내가 게시 한 링크를 따라 가면서, 나는 e Visual Studio Express 2013을 다운로드하고 컴파일하여 다음을 실행하고 작동 여부를 테스트합니다.
여기에는 창 및 클래스 만들기, 메시지 루프 및 메시지 처리를위한 Windows 절차가 포함되어 있습니다.
// Trim fat from windows
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
// Windows Procedure Message Handler
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// Switch message, condition that is met will execute*/
switch (message)
{
case WM_CLOSE:
MessageBox(NULL, "QUIT", NULL, MB_OK);
PostQuitMessage(0);
break;
case WM_KEYDOWN:
MessageBox(NULL, "PRESS", NULL, MB_OK);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
// Main function
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX windowClass; //window class
HWND hwnd; //window handle
MSG msg; //message
/* Fill out the window class structure*/
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = "MyClass";
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
/* Register window class*/
if (!RegisterClassEx(&windowClass))
{
return 0;
}
/* Class registerd, so now create window*/
hwnd = CreateWindowEx(NULL, //extended style
"MyClass", //class name
"A Real Win App", //app name
WS_OVERLAPPEDWINDOW | //window style
WS_VISIBLE |
WS_SYSMENU,
100, 100, //x/y coords
400, 400, //width,height
NULL, //handle to parent
NULL, //handle to menu
hInstance, //application instance
NULL); //no extra parameter's
/* Check if window creation failed*/
if (!hwnd)
return 0;
bool done = false; //initialize loop condition variable
/* main message loop*/
while (!done)
{
PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE);
if (msg.message == WM_QUIT) //check for a quit message
{
done = true;
}
else
{
// Translate and dispatch to event queue
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
이것은 내게 합당하지 않습니다. 일어날 것으로 예상되는 것과 실제로 일어나는 일에 대해 명확한 설명을 제공하여 완벽한 SSCCE를 제공 할 수 있습니까? –
메시지 루프 (peek-translate-dispatch)는 본문에'MessageBox'가 없어야합니다. 'MessageBox'는 자체 메시지 루프를 만들고 엉망으로 만듭니다. – Dialecticus
@DavidHeffernan SSCCE? 다음은이 파일의 전체 코드입니다. [링크] (http://pastebin.com/9ACgphSB) 사용자가 키를 눌렀을 때 나는 단지 붙잡고 싶습니다. 그럼 내가 그걸로 일할 수있어. 하지만 왼쪽 상단의 작은 "x"를 클릭하면 "누르기"메시지 상자가 활성화됩니다. –