API - 해당되는 글 1건

윈도우 최소화 시키는 부분에 대한 내용은 대부분 SetWindowLong를 이용하면 된다고 생각하는 분들이 많다.

맞는 애기 일수도 있다. SetWindowLong의 GWL_MINIMIZE를 OR시키면 WM_SIZE의 메시지가 호출되는데

이때 WM_SIZE에서 WM_MINIMIZE였을때를 코딩해주어야 한다. 만약 코딩해주지 않았을 경우 프로그램은 최소화 되었지만 실상 모니터에서는 창이 그대로 있게되는 어이없는 일이 벌어진다.

그럼 이를 어찌 처리하면 좋을까? 뭐 WM_SIZE메시지에 스위치문으로 최소화되는 일련의 사건들을 코딩해주면 될것이다.

이런 과정은 의외로 번거롭다. 그럼 쉬운 방법은 없을까?

당연히 있다. 네이버에서 이에 관련되어 자료가 있나 이리저리 검색해 보았지만 찾을수가 없었다.

방법은 간단하다

최소화 시킬려고 하는 버튼을 만든다..예를 들어 아래와 같이 버튼을 생성했다면


CreateWindow("button", NULL, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW,
   957,10, 27, 14,
   hWnd, (HMENU)IDBU_MINIMIZE, g_hInst, NULL);


당연히  WM_COMMAND메시지에 IDBU_MINIMIZE를 코딩해줘야 할것이다. 이부분이야 당연히 알꺼라 보고

다음과 같이 코딩을 해주면된다.


PostMessage(hWnd, WM_SYSCOMMAND, (WPARAM)SC_MINIMIZE, 0);


자 그럼 이게 무슨뜻인지 알아보기로 하자. PostMessage()함수는 WM_~메시지를 wParam, lParam과 함께 호출해준다.

첫번째야 당연히 메인윈도우 핸들이다.

두번재는 WM_SYSCOMMAND<-- 이게 무엇일까 API를 약간이라도 만져본 사람이라면 추축할수 있을것이다. 시스템메뉴에 대한 COMMAND라는 것을

세번째는 SC_MINIMIZE... 이건 WM_SYSCOMAND메시지에 최소화 시키는 부분을 wParam에 저장해준다. 왜 wParam에 저장해주느냐!

그건 아래에 붙여 넣을 MSDN WM_SYSCONNAMD를 보면 알수 있다. 참고 바란다.


어? 난 윈도우를 WM_BORDER형으로 만들어서 타이틀바를 사용하지 않는데 어쩌지?<-- 이런 분들도 있을것이다. WM_BORDER은 윈도우 형태를 표시하는 방법에 대한 셋팅일뿐 어떤 윈도우든 WM_SYSCOMMAND를 가지고 있다. 다시말해 전혀 상관없이 적용된다는 말이다.


WM_SYSCOMMAND
Notification


A window receives this message when the user chooses a command from the Window menu (formerly known as the system or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button.

Syntax

WM_SYSCOMMAND

    WPARAM wParam
    LPARAM lParam;
    

Parameters

wParam
Specifies the type of system command requested. This parameter can be one of the following values.
SC_CLOSE
Closes the window.
SC_CONTEXTHELP
Changes the cursor to a question mark with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message.
SC_DEFAULT
Selects the default item; the user double-clicked the window menu.
SC_HOTKEY
Activates the window associated with the application-specified hot key. The lParam parameter identifies the window to activate.
SC_HSCROLL
Scrolls horizontally.
SC_KEYMENU
Retrieves the window menu as a result of a keystroke. For more information, see the Remarks section.
SC_MAXIMIZE
Maximizes the window.
SC_MINIMIZE
Minimizes the window.
SC_MONITORPOWER
Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.

The lParam parameter can have the following values:

1 - the display is going to low power

2 - the display is being shut off

SC_MOUSEMENU
Retrieves the window menu as a result of a mouse click.
SC_MOVE
Moves the window.
SC_NEXTWINDOW
Moves to the next window.
SC_PREVWINDOW
Moves to the previous window.
SC_RESTORE
Restores the window to its normal position and size.
SC_SCREENSAVE
Executes the screen saver application specified in the [boot] section of the System.ini file.
SC_SIZE
Sizes the window.
SC_TASKLIST
Activates the Start menu.
SC_VSCROLL
Scrolls vertically.
lParam
The low-order word specifies the horizontal position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. Otherwise, this parameter is not used.

The high-order word specifies the vertical position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. This parameter is –1 if the command is chosen using a system accelerator, or zero if using a mnemonic.

Return Value

An application should return zero if it processes this message.

* 오랜만에 올려보내요.. 자주 실습예제를 올려놨어야 하는데 요즘 일이 조금 많아서 블로그에 신경을 못쓰네요. 이웃분들 오랜만에 업글했으니 유용하게 사용하세요. 이 부분은 네이버 어디를 찾아봐도 있지 않는 내용이니 땡잡았다 생각하셔도 될듯 ^^

      S T U D Y/Win32 API & System  |  2008. 7. 4. 00:42



jekalmin's Blog is powered by Daum