Wine >> C/C++ >> Dialog >> Controls
Button
參考資訊:
1. win32
2. petzold
3. tutorial
4. examples_win32
main.c
#include <windows.h> #define ID_BTN 1000 HWND hWin = NULL; HWND hBtn = NULL; WNDPROC defWndProc = NULL; LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CLOSE: DestroyWindow(hWnd); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; case WM_COMMAND: switch (LOWORD(wParam)) { case ID_BTN: MessageBox(hWnd, "I am button", "main", MB_OK); return 0; } break; } return CallWindowProc(defWndProc, hWnd, uMsg, wParam, lParam); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { hWin = CreateWindow(WC_DIALOG, "main", WS_OVERLAPPEDWINDOW, 0, 0, 300, 300, NULL, NULL, NULL, NULL); hBtn = CreateWindow("BUTTON", "Test", WS_CHILD | BS_PUSHBUTTON, 50, 50, 100, 100, hWin, (HMENU)ID_BTN, NULL, NULL); defWndProc = (WNDPROC)SetWindowLongPtr(hWin, GWLP_WNDPROC, (long int)WndProc); ShowWindow(hBtn, SW_SHOW); ShowWindow(hWin, SW_SHOW); MSG msg = {0}; while (GetMessage(&msg, NULL, 0, 0)) { DispatchMessage(&msg); } ExitProcess(0); return 0; }
編譯、執行
$ winegcc main.c -o main $ wine ./main.exe