참조 : https://msdn.microsoft.com/ko-kr/library/windows/desktop/ms645533(v=vs.85).aspx


 기본적으로 마우스는 GUI 기반의 운영체제인 윈도우스, X Windows, Mac등에 있는 입력 장치이다.


 마우스의 이벤트 메세지를 받아서 이용한다.


 WM에서 마우스 버튼을 클릭하거나 움직이는 용도로 사용한다.


 마우스 메세지는 좌표 정도는 lParam에 처리해준다.

 lParam에서 HIWORD(상위 16bit)는 y값을 LOWRD(하위 16bit)는 x좌표를 저장시켜 놓고 있다.


 이렇게 해서 마우스의 클릭 상태와 키보드 조합 상태의 데이터는 마우스 메세지에서 wParam에서 존재한다.


 여기서 키값은 MK을 가진다.


 예제소스


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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <stdlib.h>
 
#include <tchar.h>
#include <windows.h>
 
#include <string.h>
 
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
 
WNDCLASS WndClass;
 
int numbers = 0;
 
int WINAPI WinMain(HINSTANCE hInstance,
            HINSTANCE hPrevInstance,
            LPSTR lpszCmdParam,
            int nCmdShow)
{
    HWND hWnd;
    MSG Message;
    g_hInst = hInstance;
 
    WndClass.cbClsExtra=0;
    WndClass.cbWndExtra=0;
    WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
    WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    WndClass.hInstance=hInstance;
    WndClass.lpfnWndProc=(WNDPROC)WndProc;
    WndClass.lpszClassName="ApiBase";
    WndClass.lpszMenuName=NULL;
    WndClass.style=CS_HREDRAW|CS_VREDRAW;
 
    RegisterClass(&WndClass);
    
    hWnd = CreateWindow("ApiBase",
                        "Test",
                        WS_OVERLAPPEDWINDOW,
                        10,// X
                        100,// Y
                        400,// Width
                        400,// Height
                        NULL,
                        (HMENU)NULL,
                        hInstance,
                        NULL);
 
                        
    ShowWindow(hWnd,nCmdShow);
    
    while(GetMessage(&Message,0,0,0))
    {
        TranslateMessage(&Message);
        DispatchMessage(&Message);
    }
    
    return Message.wParam;
}
 
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    RECT rt;
    static int nX = 0, nY = 0;
    static char strTemp[MAX_PATH];
    long dwStyle;
    
    POINT polyline[5= {60,50,40,30,20};
    POINT polygon[5= {10,20,30,40,50};
    
    switch(iMessage)
    {
        case WM_CREATE:
            strcpy(strTemp, "");
            break;
        case WM_LBUTTONDOWN:
            nX = LOWORD(lParam);
            nY = HIWORD(lParam);
            sprintf(strTemp, "point (%d, %d), keyboard state %d\0", nX, nY, wParam);
            printf("%s", strTemp);
            InvalidateRect(hWnd, NULL, TRUE);
            break;
        case WM_PAINT:
            hdc=BeginPaint(hWnd,&ps);
            TextOut(hdc, nX, nY, strTemp, strlen(strTemp));
            EndPaint(hWnd,&ps);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
    }
    return DefWindowProc(hWnd,iMessage,wParam, lParam);
}
 
cs


Posted by JunkMam
,