7. 7
WinMain(HINSTANCE hInstance,…)
{
WNDCLASS WndClass;
WndClass.style = NULL;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = "Hello";
}
윈도우 클래스 부분을 천천히 다시 살펴 봅니다
뒤로 넘어가지 말고 직접 해결 해 보세요 제발!
답을 알았으면 뒤로
8. 8
WinMain(HINSTANCE hInstance,…)
{
WNDCLASS WndClass;
WndClass.style = NULL;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = "Hello";
}
신기하게도 고칠 수가 있다
사람은 안 가르쳐 줘도 스스로 할 수 있는 능력이 있어
앞으로도 이런 식으로 합니다
9. 메시지 단순 처리
9
무슨 메시지인지만 구분
메시지 처리 유형 Ⅰ
메시지 처리 유형 번호는 중요하지 않음
유형 5가지를 제시하고 그게 전부라는 것을 전달하고자 유형 번호 부여
사실 5가지도 그냥 정한 거야
14. 14
WM_MOUSEMOVE
마우스 움직임 이벤트
마우스 좌표는 어디서 가져와야 하지 ?
부가정보 wParam 또는 lParam
int x = HIWORD(lParam)
int y = LOWORD(lParam)
high-order word, low-order word
부가 정보 어느 파라미터에 있고 어떻게 끄집어 내야 할지 외워야 하나 ?
그럴 필요 없다
15. 15
■ MSDN 사용
MSDN은 대개 Visual C++ 을 설치할 때 함께 설치된다. 이 경우 비주얼
스튜디오에서 F1키를 누르면 현재 커서위치의 문자를 키워드로 하여
MSDN을 실행시킨다. 그렇지 않은 사람은 http://msdn.micorsoft.com/ 을
통해 온라인으로 정보를 찾을 수 있다.
■ MSDN의 메인 화면
본 화 면 의 검 색 창 (Search) 에 WM_MOUSEMOVE 를 입 력 하 고
검색(Search)버튼을 누르면 된다.
MSDN
윈도우 프로그램 처음 배울 때는 MSDN 6.0이 제일 보기 편하다
16. 16
■ WM_MOUSEMOVE 검색결과 화면
This message is posted to a window when user moves the mouse while pressing
the left mouse button or moves the stylus while the tip is down. If another
window does not capture the mouse stylus input, the OS posts the message to
the window that contains the cursor or the stylus tip. If another window
captures the mouse or stylus input, the OS posts the message to the window
that has the capture.
WM_MOUSEMOVE
fwKeys = wParam;
xPos = LOWORD(lParam);
yPos = HIWORD(lParam);
Parameters
fwKeys
Indicates the mouse buttons and keys that the user pressed. The following
table shows the possible values, which can be combined.
Value Description
MK_CONTROL The user pressed the CTRL key.
MK_LBUTTON The user pressed the left mouse button.
MK_SHIFT The user pressed the SHIFT key.
(중략…)
17. 17
윈도우 화면에 글자 출력하기
HDC hdc;
hdc = GetDC(hWnd);
TextOut(hdc, x, y, "hello", 5);
ReleaseDC(hWnd, hdc);
x, y 위치에 “hello” 출력, “hello” 문자열의 길이는 5
근데 hdc 는 뭐야 ?
하여튼 출력되는 문자열은 “hello”라 이거지
18. 18
윈도우 화면에 글자 출력하기는 그냥 이렇게 해
HDC hdc;
hdc = GetDC(hWnd);
TextOut(hdc, x, y, "hello", 5);
ReleaseDC(hWnd, hdc);
hdc는 GetDC 함수를 통해
hWnd가 가리키는 윈도우에서 얻어 오는 것
Device Context 라고 함
HDC GetDC(HWND hWnd)
ReleaseDC(HWND hWnd, HDC hdc) 얻어왔으니 반환해야지
이 둘은 항상 쌍으로
19. 19
#include <stdio.h>
#include <string.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT mesg, WPARAM wParam, LPARAM lParam)
{…
case WM_MOUSEMOVE:
int x, y;
char szPos[80];
HDC hdc;
x = LOWORD(lParam);
y = HIWORD(lParam);
sprintf(szPos, "%03d %03d", x, y);
hdc = GetDC(hWnd);
TextOut(0, 0, szPos, strlen(szPos));
ReleaseDC(hWnd, hdc);
break;
…
}
sprintf 함수를 몰랐을 수도 있지만 예제 보니까 별 것 없다
이제 알면 되지
20. 20
정리하면
• WM_XXXX
• WndProc 함수의 case 문에 추가
• 부가정보는 MSDN에서 검색
• 앞으로 어떤 이벤트(메시지)가
있는지 알아보면 되겠죠
MSDN 6.0 화면
WinMain 부분은 별로 건드릴 일이 없네