자, 이번엔 Paint에 대해서 알아보도록 하겠다.
dc의 경우엔 사실 Invalidate()가 자동적으로 이루어지지 않았다.(2010, windows7에서는 자동으로 되는듯 싶지만) WM_Paint를 사용하면 Uncover가 자동적으로 이루어진다. 음... 정확하진 않다.
일단 사용방법은.

 PAINTSTRUCT 구조체를 사용하는 방법이다.

자, 자세한 예제를 보면,
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;

switch(iMessage)
{
case WM_DESTROY:PostQuitMessage(0);return 0;
case WM_PAINT :
hdc = BeginPaint(hWnd, &ps);
TextOut(hdc, 100,100,TEXT("Beautiful Korea"),15);
EndPaint(hWnd,&ps);
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam);
}

자, 여기서 새로나온걸 보자면 PAINTSTRUCT 구조체와 BeginPaint, EndPaint다.
PAINTSTRUCT의 안을 들여다보면
typedef struct tagPAINTSTRUCT
{
HDC hdc;
BOOL fErase;
RECT rcPaint;
BOOL fRestore;
BOOL flncUpdate;
BYTE rgbReserved[16];
} PAINTSTRUCT;

MSDN에서의 설명을 그냥 번역해보자면
hdc

A handle to the display DC to be used for painting.
그리기를 위해 사용될 DC를 표시할 핸들.

fErase

Indicates whether the background must be erased. This value is nonzero if the application should erase the background. The application is responsible for erasing the background if a window class is created without a background brush. For more information, see the description of the hbrBackground member of the WNDCLASS structure.
지시한다 배경이 지워져야만 할것인지 아닌지. 만약 이 어플이 배경을 지운다면 이 값은 0이 아니다. 만약 윈도우 클래스가 배경색 프러쉬없이 만들어진다면, 이 어플은 배경을 지울 책임이 있다. 뭔가 더 궁금하면 WNDCLASS구조체의 hbrBackground멤버 설명을 좀더 보면 이해가 될수도 있을껄?

rcPaint

A RECT structure that specifies the upper left and lower right corners of the rectangle in which the painting is requested, in device units relative to the upper-left corner of the client area.
그리기가 요청된 위 왼쪽, 아래, 오른쪽 코너들을 특정짓는 사각형(RECT) 구조. 디바이스 유닛에서는 클라이언트영역의 왼쪽위로 연결된다.

fRestore

Reserved; used internally by the system.
시스템 내부적으로 예약되어 있음. 건들지 마셈.

fIncUpdate

Reserved; used internally by the system.
시스템 내부적으로 예약되어 있음. 건들지 마셈.

rgbReserved

Reserved; used internally by the system.
시스템 내부적으로 예약되어 있음. 건들지 마셈.

 
자, 한마디로 말하자면, 알필요 없는 구조체네. 그저 BeginPaint를 사용하기 위한 전초전이라 생각해도 편할듯 싶다.
 
BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint);
자, 그럼 이 코드를 보자면, BeginPaint다. 음.. GetDC, ReleaseDC와 마찬가지로
BeginPaint를 해주면, 반드시 EndPaint를 해줘야 한다.
자, 그리고 넘겨주는것에는 HWND와 LPPAINTSTRUCT. LP는 포인터를 의미한다. 따라서 저기 선언해 놓은 PAINTSTRUCT ps;의 주소값을 넘겨주면 된다.
 





















'Programming > Visual C++' 카테고리의 다른 글

출력4. 기타  (0) 2011.06.28
출력3. DrawText  (0) 2011.06.28
출력1. TextOut  (0) 2011.06.28
How to Programming by Unicode in windows programming - 3  (1) 2011.06.25
윈도우즈 프로그래밍에서 유니코드로 코딩법 2  (1) 2011.06.25

+ Recent posts