달력

52025  이전 다음

  • 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
  • 31

'API'에 해당되는 글 5건

  1. 2008.11.02 키보드 이벤트
  2. 2008.11.02 시스템 키보드 처리
  3. 2008.11.02 MOUSE 위치 이벤트
  4. 2008.11.02 mouse wheel 이벤트
  5. 2008.11.02 mouse 이벤트

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

#include <windows.h>

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 switch( msg )
 { 
 // 아래 메세지가 DefWindowProc 에 가면 ALT + F4 등의 기능을 수행 되게 된다.
 case WM_SYSKEYDOWN:
  return 0;


 case WM_KEYDOWN:
  {
   int vCode = (int)wParam;

   // Scan Code 는 lParam 의 16~23 비트에 있다.
   int sCode = ( lParam & 0x00FF0000) >> 16;

   char s[256];
   wsprintf( s, "Scan Code : %d \nvirtual Key Code : %d", sCode, vCode);

   MessageBox( hwnd, s, "", MB_OK);
  }
  return 0;

     // 대 소문자 변경해서 Test 해 보세요
     // "A", "a" 가 같은 가상 키코드임을 확인 하세요..

 

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

// -> 화살표 키 : WM_KEYDOWN 만 발생.

// 기능키 : WM_KEYDOWN 에서 처리
// 문자키 : WM_CHAR 에서 처리

Posted by CokeBell
|


#include <windows.h>

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 switch( msg )
 {
// case WM_SYSKEYDOWN:
  // system keyboard는 반드시 defWindowProc에 보내야 한다.
  // 그래야 Alt + F4 같은 기본 기능이 지원 된다...
//  return 0;
//  return DefWindowProc(hwnd, msg, wParam, lParam);

  // Alt + X로 종료..
 case WM_SYSCHAR:
  {
   //
   if( wParam == 'X' || wParam == 'x')
   {
    // 자기자신 종료..
//    SendMessage(hwnd, WM_CLOSE, 0, 0); //WM_CLOSE 이벤트로 이동하여 종료함
    SendMessage(hwnd, WM_QUIT, 0, 0); //종료 이벤트 호출
    DestroyWindow(hwnd);    //윈도우를 죽인다.
    return 0;
   }
  }
  return DefWindowProc(hwnd, msg, wParam, lParam);


  return 0;
 case WM_CLOSE:
  {
   UINT ret = MessageBox(hwnd, "정말로 끝내시렵니까?", "확인", MB_YESNO);
   if (ret == IDYES)
   {
    // 윈도우 파괴 -> WM_DESTROY 발생 => PostQuitMessage() => WM_QUIT
    DestroyWindow(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)
{
 // 1. 윈도우 클래스 만들기
 WNDCLASS wc;
 wc.cbWndExtra   = 0;
 wc.cbClsExtra   = 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;   // DefWindowProc;
 wc.lpszClassName  = "First";
 wc.lpszMenuName   = 0;
 wc.style    = 0;

 // 2. 등록(레지스트리에)
 RegisterClass(&wc);

 // 3. 윈도우 창 만들기
 HWND hwnd = CreateWindowEx( 0,     // WS_EX_TOPMOST
     "first",    // 클래스 명
     "Hello",    // 캡션바 내용
     WS_OVERLAPPEDWINDOW,
     CW_USEDEFAULT , 0, CW_USEDEFAULT, 0, // 초기 위치
     0, 0,   // 부모 윈도우 핸들, 메뉴 핸들
     hInstance,  // WinMain의 1번째 파라미터 (exe 주소)
     0);   // 생성 인자

 

 // 4. 윈도우 보여주기
 ShowWindow(hwnd, SW_SHOW);
 UpdateWindow(hwnd);
 

 // 5. Message
 MSG msg;
 while( GetMessage( &msg, 0, 0, 0 ) )
 {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 }
 return 0;
}

Posted by CokeBell
|

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