달력

62025  이전 다음

  • 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

'Mouse'에 해당되는 글 3건

  1. 2008.11.02 MOUSE 위치 이벤트
  2. 2008.11.02 mouse wheel 이벤트
  3. 2008.11.02 mouse 이벤트

//------------------------------------------------------------
// 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;
}


 

Posted by CokeBell
|

//--------------------------------------------------------------
// 마우스 휠
//--------------------------------------------------------------
#pragma comment(linker, "/subsystem:windows")
#define _WIN32_WINNT 0x0501
#define WINVER   0x0501
#include <windows.h>

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 switch( msg )
 { 
 case WM_MOUSEWHEEL:
  {
   short delta = HIWORD( wParam );

   delta = ( delta / WHEEL_DELTA ); // WHEEL_DELTA : 120

   RECT rc;
   GetWindowRect( hwnd, &rc); // 현재 윈도우의 위치, 크기

   OffsetRect( &rc, 0, delta * 10 ); // rc를 이동.

   // 윈도우를 이동.
   SetWindowPos( hwnd, 0, rc.left, rc.top, 0, 0,
        SWP_NOZORDER | SWP_NOSIZE );
  }
  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;
}


 

Posted by CokeBell
|

//--------------------------------------------------------------
// GetKeyState
//---------------------------------------------------------------

#pragma comment(linker, "/subsystem:windows")

#include <windows.h>

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 switch( msg )
 { 

 case WM_LBUTTONDBLCLK:
  MessageBox( 0, "DBLCLK", "", MB_OK);
  return 0;
 
 case WM_RBUTTONDOWN:
  {
   // GetKeyState() 함수를 사용하면 메세지 발생 당시의
   // 모든 키보드 상태를 얻을수 있다.
   if ( GetKeyState( VK_CAPITAL ) & 0x00FF ) // 상태키 정보(하위8비트조사)
   {
    MessageBox( 0, "대문자 상태", "", MB_OK);
   }
   else
    MessageBox( 0, "소문자 상태", "", MB_OK);

   
   // 일반 키보드 정보
   if ( GetKeyState( VK_F2 ) & 0xFF00 ) // 상위 8비트 조사
    MessageBox( 0, "F2 + RBUTTON", "", MB_OK);


   // wParam 조사하는 방법 - & 연산 사용
   if ( wParam & MK_SHIFT )
   {
    MessageBox( 0, "SHIFT + RBUTTON", "", MB_OK);
   }
  }
  return 0;
      // SHIFT를 누른 상태에서 RBUTTON 을 눌러 보세요.

 case WM_LBUTTONDOWN:
  {
   // 모든 마우스 메세지의 lParam에는 마우스 좌표가 있다.-클라이 언트좌표
   int x = lParam & 0x0000FFFF; // 하위 16비트 에 x좌표
   int y = lParam >> 16;        // 상위 16비트 에 y좌표

   // 결국 위 작업을 대신 해주는 매크로가 있다.
   x = LOWORD(lParam);
   y = HIWORD(lParam);

   // 또는
   POINTS pt = MAKEPOINTS(lParam);
  }
  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  = CS_DBLCLKS; //더블 클릭 메세지를 만들어 달라는 클래스 스타일


 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;
}

 

Posted by CokeBell
|