본문 바로가기
프로그래밍/API

API-작업 영역

by 리뷰하는 (게임)프로그래머_리프TV 2010. 4. 21.




작업 영역에 대해서 따로 보관하는 방법,

#include <windows.h>

LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
HINSTANCE g_hInst;
LPCTSTR lpszClass = TEXT("Client");

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
					 LPSTR lpszCmdParam, int nCmdShow )
{
	HWND hWnd;
	MSG Message;
	WNDCLASS WndClass;
	g_hInst = hInstance;

	WndClass.cbClsExtra = 0;
	WndClass.cbWndExtra = 0;
	WndClass.hbrBackground = (HBRUSH)GetStockObject( COLOR_WINDOW+1 );
	WndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
	WndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
	WndClass.hInstance = hInstance;
	WndClass.lpfnWndProc = WndProc;
	WndClass.lpszClassName = lpszClass;
	WndClass.lpszMenuName = NULL;
	WndClass.style = CS_HREDRAW | CS_VREDRAW;
	RegisterClass( &WndClass );

	hWnd = CreateWindow(lpszClass, lpszClass, WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
		NULL, (HMENU)NULL, hInstance, NULL );
	ShowWindow( hWnd, nCmdShow );

	while( GetMessage( &Message, NULL, 0, 0 ) )
	{
		TranslateMessage( &Message );
		DispatchMessage( &Message );
	}
	return (int)Message.wParam;
}

LRESULT CALLBACK WndProc( HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam )
{
	HDC hdc;
	PAINTSTRUCT ps;
	static RECT rt;

	switch( iMessage )
	{
	case WM_SIZE:	// 작업 영역의 SIZE가 변하면 그것도 채크해 주어야 한다.
		//GetClientRect( hWnd, &rt );
		//InvalidateRect( hWnd, NULL, TRUE );
		rt.right = LOWORD( lParam );
		rt.bottom = HIWORD( lParam );
		InvalidateRect( hWnd, NULL, TRUE );
		return 0;
	case WM_CREATE:
		GetClientRect( hWnd, &rt );	// 작업 영역을 rt에 삽입
		return 0;
	case WM_PAINT:
		hdc = BeginPaint( hWnd, &ps );
//		GetClientRect( hWnd, &rt );
		SetTextAlign( hdc, TA_CENTER );
		TextOut( hdc, rt.right/2, rt.bottom/2, TEXT("Center String"), 13 );
		EndPaint( hWnd, &ps );
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}
	return( DefWindowProc( hWnd, iMessage, wParam, lParam));
}​

 

설명 : 화면 중앙에 문자열을 출력한다.( 화면의 크기가 변경되면 마찬가지로 중앙의 위치도 바뀌게 된다.)

'프로그래밍 > API' 카테고리의 다른 글

API-resource(2)  (0) 2010.04.21
API-resource(1)  (0) 2010.04.21
API-일회용 타이머  (0) 2010.04.21
API-무한의 작업을 위한 타이머(2)  (0) 2010.04.21
API-무한의 작업을 위한 타이머(1)  (0) 2010.04.21