#pragma comment(linker, "/subsystem:windows")
#include <windows.h>
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch( msg )
{
// 아래 메세지가 DefWindowProc 에 가면 ALT + F4 등의 기능을 수행 되게 된다.
case WM_SYSKEYDOWN:
return 0;
case WM_KEYDOWN:
{
int vCode = (int)wParam;
// Scan Code 는 lParam 의 16~23 비트에 있다.
int sCode = ( lParam & 0x00FF0000) >> 16;
char s[256];
wsprintf( s, "Scan Code : %d \nvirtual Key Code : %d", sCode, vCode);
MessageBox( hwnd, s, "", MB_OK);
}
return 0;
// 대 소문자 변경해서 Test 해 보세요
// "A", "a" 가 같은 가상 키코드임을 확인 하세요..
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc( hwnd, msg, wParam, lParam);
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd )
{
ATOM atom;
WNDCLASS wc;
HWND hwnd;
MSG msg;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground= (HBRUSH)GetStockObject( WHITE_BRUSH );
wc.hCursor = LoadCursor( 0, IDC_ARROW );
wc.hIcon = LoadIcon( 0, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName= "First";
wc.lpszMenuName = 0;
wc.style = 0;
atom = RegisterClass( &wc);
if ( atom == 0 )
{
MessageBox( 0, "Fail To RegisterClass", "Error", MB_OK);
return 0;
}
hwnd = CreateWindowEx( 0, "first", "Hello", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT,0, 0, 0,
hInstance, 0);
ShowWindow( hwnd, nShowCmd);
UpdateWindow( hwnd );
while ( GetMessage( &msg, 0, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage( &msg);
}
return 0;
}
// -> 화살표 키 : WM_KEYDOWN 만 발생.
// 기능키 : WM_KEYDOWN 에서 처리
// 문자키 : WM_CHAR 에서 처리