블로그 이미지
대갈장군

calendar

1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

Notice

2009. 11. 17. 03:34 프로그래밍/Windows API
CreateWindow() 함수를 사용하여 응용 프로그램 로컬 윈도우 클래스를 생성하고자 한다면 WNDCLASS 구조체를 채워넣어야 한다.

typedef struct {
    UINT style;
    WNDPROC lpfnWndProc;
    int cbClsExtra;
    int cbWndExtra;
    HINSTANCE hInstance;
    HICON hIcon;
    HCURSOR hCursor;
    HBRUSH hbrBackground;
    LPCTSTR lpszMenuName;
    LPCTSTR lpszClassName;
} WNDCLASS, *PWNDCLASS;

이 구조체 중에서 중요한 3가지는 lpszClassName, lpfnWndProc, 그리고 hInstance 요소로서 이 세놈은 기본값이 없으므로 생략할 수 없다. 

lpszClassName이 바로 CreatWindow() 함수의 첫번째 인자가 될 것이므로 되도록이면 만들고자 하는 윈도우를 잘 나타내는 이름을 지어주자. 

hInstance는 이 윈도우 클래스를 등록한 응용 프로그램의 인스턴스 핸들이다. 여기서 지정된 응용프로그램이 종료되면 윈도우 클래스도 같이 파괴된다. 주로 WinMain 으로 전달된 hInstance 인수를 그대로 사용하면 된다.

마지막으로 lpfnWndProc는 메시지 처리 함수다. 뭐, 이놈이 사실 내가 만드는 윈도우의 모든 동작을 정의한다. 

이 외에 style 인자가 재미 있는 녀석인데 윈도우의 스타일을 지정하는 인수다. 지정할 수 있는 것들로는 
StyleAction
CS_BYTEALIGNCLIENT Aligns the window's client area on a byte boundary (in the x direction). This style affects the width of the window and its horizontal placement on the display.
CS_BYTEALIGNWINDOW Aligns the window on a byte boundary (in the x direction). This style affects the width of the window and its horizontal placement on the display.
CS_CLASSDC Allocates one device context to be shared by all windows in the class. Because window classes are process specific, it is possible for multiple threads of an application to create a window of the same class. It is also possible for the threads to attempt to use the device context simultaneously. When this happens, the system allows only one thread to successfully finish its drawing operation.
CS_DBLCLKS Sends a double-click message to the window procedure when the user double-clicks the mouse while the cursor is within a window belonging to the class.
CS_DROPSHADOW Windows XP: Enables the drop shadow effect on a window. The effect is turned on and off through SPI_SETDROPSHADOW. Typically, this is enabled for small, short-lived windows such as menus to emphasize their Z order relationship to other windows.
CS_GLOBALCLASS Specifies that the window class is an application global class. For more information, see Application Global Classes.
CS_HREDRAW Redraws the entire window if a movement or size adjustment changes the width of the client area.
CS_NOCLOSE Disables Close on the window menu.
CS_OWNDC Allocates a unique device context for each window in the class.
CS_PARENTDC Sets the clipping rectangle of the child window to that of the parent window so that the child can draw on the parent. A window with the CS_PARENTDC style bit receives a regular device context from the system's cache of device contexts. It does not give the child the parent's device context or device context settings. Specifying CS_PARENTDC enhances an application's performance.
CS_SAVEBITS Saves, as a bitmap, the portion of the screen image obscured by a window of this class. When the window is removed, the system uses the saved bitmap to restore the screen image, including other windows that were obscured. Therefore, the system does not send WM_PAINT messages to windows that were obscured if the memory used by the bitmap has not been discarded and if other screen actions have not invalidated the stored image.

This style is useful for small windows (for example, menus or dialog boxes) that are displayed briefly and then removed before other screen activity takes place. This style increases the time required to display the window, because the system must first allocate memory to store the bitmap.

CS_VREDRAW Redraws the entire window if a movement or size adjustment changes the height of the client area.

여기서 주의해서 볼 필요가 있는 속성 두가지는 CS_DBLCLKS와 CS_NOCLOSE인데 첫번째 놈을 설정하지 않으면 마우스 더블클릭은 무시된다. (WndProc 함수로 전달되지 않는다는 말) 그리고 두번째 놈은 종료 버튼이 없도록 만든다. 심지어 Alt+F4도 안된다. 이 플래그가 설정된 경우 윈도우를 닫기 위해서는 반드시 다른 형태의 종료 방법이 제공되야 한다.


posted by 대갈장군