#include <windows.h>
#include <tchar.h>
#include <stdio.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
HDC hDc;
// *
// 지정된 문자열을 출력하기위해 static변수가 필요하다
// WndProc은 이벤트 관리 콜백 함수로서 윈도우에 의해 호출이 되어진다.
// static으로 선언을 안할경우 새로운 가비지 값이 들어가기 때문이다.
static TCHAR tcaStr[256];
PAINTSTRUCT ps;
switch(Msg) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_LBUTTONUP:
_tcscpy(tcaStr, _T("마누라 사랑해~ 알지~?"));
InvalidateRect(hWnd, NULL, TRUE);
return 0;
case WM_PAINT:
hDc = BeginPaint(hWnd, &ps);
TextOut(hDc, 10, 10, tcaStr, lstrlen(tcaStr));
EndPaint(hWnd, &ps);
return 0;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstacne, LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd;
WNDCLASS wc;
MSG msg;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL , IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL , IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = _T("MyWindow");
if (!RegisterClass(&wc)) return 0;
hWnd = CreateWindow(
_T("MyWindow"), _T("This is Test") ,
WS_OVERLAPPEDWINDOW | WS_VISIBLE ,
100, 100,
200, 200,
NULL , NULL ,
hInstance , NULL
);
if (hWnd == NULL) return 0;
while (GetMessage(&msg , NULL , 0 , 0)) DispatchMessage(&msg);
return msg.wParam;
} |