參考資訊:
http://www.winprog.org/tutorial/
http://winapi.freetechsecrets.com/win32/
https://github.com/gammasoft71/Examples_Win32
http://masm32.com/board/index.php?topic=3584.0
https://learn.microsoft.com/en-us/windows/win32/winmsg/window-styles
DialogBox()是另一種用來建立Dialog的方式,有別於CreateDialog(),DialogBox()是屬於Block方式呼叫,直到Dialog結束後,才會從DialogBox()繼續往下執行,而使用DialogBox()建立的Dialog,必須使用EndDialog()關閉Dialog視窗
main.c
#include <windows.h> #include "resource.h" INT_PTR CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { DWORD dwID = wParam; switch (uMsg) { case WM_COMMAND: if (dwID == IDOK) { EndDialog(hWnd, 0); return TRUE; } break; } return FALSE; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc); ExitProcess(0); return 0; }
main.rc
#include <windows.h> #include "resource.h" IDR_MAINFRAME ICON "main.ico" IDD_MAIN DIALOGEX 0, 0, 100, 42 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "main" FONT 10, "MS Shell Dlg", 0, 0, 0x1 BEGIN LTEXT "MyDialog", IDC_STATIC, 32, 0, 32, 16, SS_NOPREFIX | SS_CENTER ICON IDR_MAINFRAME, IDC_STATIC, 42, 10, 16, 16 DEFPUSHBUTTON "OK", IDOK, 0, 25, 100, 16, WS_GROUP END
resource.h
#define IDD_MAIN 101 #define IDR_MAINFRAME 102 #define IDC_STATIC -1
main.ico
編譯、執行
$ x86_64-w64-mingw32-windres main.rc -o main.res $ winegcc main.c main.res -o main $ wine ./main.exe