參考資訊:
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
main.c
#include <windows.h>
#include "resource.h"
HWND hWin = 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 IDM_EXIT:
DestroyWindow(hWnd);
break;
}
break;
}
return CallWindowProc(defWndProc, hWnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HMENU hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDM_MAIN));
hWin = CreateWindow(WC_DIALOG, "main",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 300, 300, NULL, hMenu, NULL, NULL);
defWndProc = (WNDPROC)SetWindowLongPtr(hWin, GWLP_WNDPROC, (long int)WndProc);
MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0)) {
DispatchMessage(&msg);
}
ExitProcess(0);
return 0;
}
main.rc
#include <windows.h>
#include "resource.h"
IDM_MAIN MENU DISCARDABLE
BEGIN
POPUP "File"
BEGIN
MENUITEM "Exit", IDM_EXIT
END
END
resource.h
#define IDM_MAIN 101 #define IDM_EXIT 102
編譯、執行
$ x86_64-w64-mingw32-windres main.rc -o main.res $ winegcc main.c main.res -o main $ wine ./main.exe