一样可以用 tk/tcl 和 qt。
gui 库有很多
#include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { TCHAR szAppName[] = "HelloWnd"; WNDCLASS wc; HWND hWnd; MSG msg; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = szAppName; if(!RegisterClass(&wc)) { MessageBox(NULL, TEXT("Register class failed, program will to exit!"), szAppName, MB_OK | MB_ICONERROR); return 0; } hWnd = CreateWindow(szAppName, TEXT("The Hello world program."), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { static int cxClient, cyClient, cxChar, cxCaps, cyChar; static TCHAR hello[] = "Hello, world!"; TEXTMETRIC tm; PAINTSTRUCT ps; HDC hDC; switch(msg) { case WM_CREATE: hDC = GetDC(hWnd); GetTextMetrics(hDC, &tm); cxChar = tm.tmAveCharWidth; cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2; cyChar = tm.tmHeight + tm.tmExternalLeading; ReleaseDC(hWnd, hDC); return 0; case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); return 0; case WM_PAINT: hDC = BeginPaint(hWnd, &ps); TextOut(hDC, (cxClient - cxCaps * lstrlen(hello)) / 2, (cyClient - cyChar) / 2, hello, lstrlen(hello)); EndPaint(hWnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); }
#include <gtk/gtk.h> GdkPixbuf *creat_pixbuf(const gchar *file) { GdkPixbuf *pixbuf; GError *error = NULL; pixbuf = gdk_pixbuf_new_from_file(file, &error); if (!pixbuf) { fprintf(stderr, "%s\n", error->message); g_error_free(error); } return pixbuf; } int main(int argc, char **argv) { /*定义一个窗口指针*/ GtkWidget *main_window; /*初始化*/ gtk_init(&argc, &argv); /*创建一个窗口*/ main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); /*设置窗口标题*/ gtk_window_set_title(GTK_WINDOW(main_window), "Yucoat!"); /*设置窗口默认大小*/ gtk_window_set_default_size(GTK_WINDOW(main_window), 280, 200); /*设置窗口所在位置*/ gtk_window_set_position(GTK_WINDOW(main_window), GTK_WIN_POS_CENTER); /*设置窗口图标*/ gtk_window_set_icon(GTK_WINDOW(main_window), creat_pixbuf("music.png")); g_signal_connect(main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL); /*显示窗口*/ gtk_widget_show(main_window); gtk_main(); return 0; }