//------------------------------------------------------------
// WM_MOUSELEAVE
//------------------------------------------------------------
#pragma comment(linker, "/subsystem:windows")
// 현재 시스템의 버전 지정
#define _WIN32_WINNT 0x0501 //
#define WINVER 0x0501 //
#include <windows.h>
// windows.h 안의 내용.
/*
#ifdef _WIN32_WINNT >= 0x0400 // 현재 시스템의 버전 확인
#define WM_MOUSELEAVE xxx
#endif
*/
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static BOOL bOver = FALSE;
switch( msg )
{
case WM_MOUSEMOVE:
if ( bOver == FALSE ) // 밖에 있다 처음 들어 온 경우.
{
bOver = TRUE;
SetWindowText( hwnd, "마우스가 윈도우 위에 있습니다."); // 캡션문자열 변경
// WM_MOUSELEAVE 메세지를 요청한다.
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof( tme );
tme.dwFlags = TME_LEAVE | TME_HOVER; // WM_MOUSEHOVER 도 요청
tme.dwHoverTime = 1000; // HOVER 시간
tme.hwndTrack = hwnd;
TrackMouseEvent( &tme );
}
return 0;
case WM_MOUSEHOVER:
bOver = FALSE;
SetWindowText( hwnd, "마우스가 정지 했습니다.");
return 0;
case WM_MOUSELEAVE:
bOver = FALSE; //<<--
SetWindowText( hwnd, "마우스가 윈도우를 벗어났습니다.");
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc( hwnd, msg, wParam, lParam);
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd )
{
ATOM atom;
WNDCLASS wc;
HWND hwnd;
MSG msg;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground= (HBRUSH)GetStockObject( WHITE_BRUSH );
wc.hCursor = LoadCursor( 0, IDC_ARROW );
wc.hIcon = LoadIcon( 0, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName= "First";
wc.lpszMenuName = 0;
wc.style = 0;
atom = RegisterClass( &wc);
if ( atom == 0 )
{
MessageBox( 0, "Fail To RegisterClass", "Error", MB_OK);
return 0;
}
hwnd = CreateWindowEx( 0, "first", "Hello", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT,0, 0, 0,
hInstance, 0);
ShowWindow( hwnd, nShowCmd);
UpdateWindow( hwnd );
while ( GetMessage( &msg, 0, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage( &msg);
}
return 0;
}