这工作正常:
// msg.c:
#include <windows.h>
#include <stdio.h>
int CALLBACK WinMain (_In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
MSG msg;
DWORD curThreadId;
curThreadId = GetCurrentThreadId();
// Send messages to self:
PostThreadMessage(curThreadId, WM_USER, 1, 2);
PostThreadMessage(curThreadId, WM_USER+1, 3, 4);
PostThreadMessage(curThreadId, WM_USER+2, 5, 6);
PostThreadMessage(curThreadId, WM_USER+3, 7, 8);
PostThreadMessage(curThreadId, WM_QUIT, 9, 10);
while (GetMessage(&msg, NULL, 0, 0)) {
printf("message: %d; wParam: %d; lParam: %d\n", msg.message, msg.wParam, msg.lParam);
}
return (int) msg.wParam;
}
制作:
> g++ -m64 -mwindows -c -o msg.o msg.c
> g++ -s -o msg.exe msg.o
> msg.exe
message: 1024; wParam: 1; lParam: 2
message: 1025; wParam: 3; lParam: 4
message: 1026; wParam: 5; lParam: 6
message: 1027; wParam: 7; lParam: 8
> echo %ERRORLEVEL%
9