SlideShare a Scribd company logo
1 of 20
Download to read offline
CHAP. 4
이벤트 처리
1
2
3장에서 해봤던 이벤트 처리
무슨 이벤트에 대해 어떤 처리를 해봤더라?
아직 아무것도 안 해본 것 같은데…
3
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE
hPrevInstance, LPSTR lpszArg, int nCmdShow)
{
HWND hWnd;
MSG msg;
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”;
if(!RegisterClass(&WndClass)) return NULL;
4
hWnd = CreateWindow(
“Hello”,
“Hello” ,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL, NULL, hInstance,
NULL
);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
5
LRESULT CALLBACK WndProc(HWND hWnd, UINT mesg, WPARAM wParam, LPARAM lParam)
{
switch(mesg)
{
case WM_DESTROY :
PostQuitMessage(0);
return FALSE;
}
return DefWindowProc(hWnd, mesg, wParam, lParam);
}
윈도우 파괴 이벤트에 대한
프로그램 종료 처리
윈도우 배경을 검은색으로
6
이벤트 처리에 앞서 윈도우 클래스 살짝 복습
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
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
무슨 메시지인지만 구분
메시지 처리 유형 Ⅰ
메시지 처리 유형 번호는 중요하지 않음
유형 5가지를 제시하고 그게 전부라는 것을 전달하고자 유형 번호 부여
사실 5가지도 그냥 정한 거야
10
WM_LBUTTONDOWN
MessageBox(HWND hWnd, LPCSTR szMsg, LPCSTR szTitle,
UINT type)
MB_OK, MB_OKCANCEL, MB_YESNO
마우스 왼쪽 버튼 눌림 이벤트
메시지박스(대화상자) 윈도우 생성 및 출력
출력할 메시지
대화상자 윈도우 타이틀
Message Box
11
LRESULT CALLBACK WndProc(HWND hWnd, UINT mesg, WPARAM wParam, LPARAM lParam)
{
switch(mesg)
{
case WM_LBUTTONDOWN:
MessageBox(hWnd,"마우스왼쪽버튼클릭 ",
"알림 ", MB_OK);
break;
case WM_DESTROY :
PostQuitMessage(0);
return FALSE;
}
return DefWindowProc(hWnd, mesg, wParam, lParam);
}
파라미터로 넘어온 인자가 무엇 인지만 구분하면 된다
WM_RBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONUP
이 정도는 쉽게 유추할 수 있다
12
메시지 부가정보 처리
무슨 메시지인지는 당연히 구분하고
더 나아가 메시지에 담긴 정보도 활용
13
WM_MOUSEMOVE
마우스 움직임 이벤트 구분
마우스 좌표는 어디서 가져와야 하지 ?
14
WM_MOUSEMOVE
마우스 움직임 이벤트
마우스 좌표는 어디서 가져와야 하지 ?
부가정보 wParam 또는 lParam
int x = HIWORD(lParam)
int y = LOWORD(lParam)
high-order word, low-order word
부가 정보 어느 파라미터에 있고 어떻게 끄집어 내야 할지 외워야 하나 ?
그럴 필요 없다
15
■ MSDN 사용
MSDN은 대개 Visual C++ 을 설치할 때 함께 설치된다. 이 경우 비주얼
스튜디오에서 F1키를 누르면 현재 커서위치의 문자를 키워드로 하여
MSDN을 실행시킨다. 그렇지 않은 사람은 http://msdn.micorsoft.com/ 을
통해 온라인으로 정보를 찾을 수 있다.
■ MSDN의 메인 화면
본 화 면 의 검 색 창 (Search) 에 WM_MOUSEMOVE 를 입 력 하 고
검색(Search)버튼을 누르면 된다.
MSDN
윈도우 프로그램 처음 배울 때는 MSDN 6.0이 제일 보기 편하다
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
윈도우 화면에 글자 출력하기
HDC hdc;
hdc = GetDC(hWnd);
TextOut(hdc, x, y, "hello", 5);
ReleaseDC(hWnd, hdc);
x, y 위치에 “hello” 출력, “hello” 문자열의 길이는 5
근데 hdc 는 뭐야 ?
하여튼 출력되는 문자열은 “hello”라 이거지
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
#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
정리하면
• WM_XXXX
• WndProc 함수의 case 문에 추가
• 부가정보는 MSDN에서 검색
• 앞으로 어떤 이벤트(메시지)가
있는지 알아보면 되겠죠
MSDN 6.0 화면
WinMain 부분은 별로 건드릴 일이 없네

More Related Content

What's hot (20)

07 윈도우 핸들
07 윈도우 핸들07 윈도우 핸들
07 윈도우 핸들
 
03 첫번째프로그램
03 첫번째프로그램03 첫번째프로그램
03 첫번째프로그램
 
Introduction à React
Introduction à ReactIntroduction à React
Introduction à React
 
Plsql
PlsqlPlsql
Plsql
 
Fiche3 ex-sous-programme
Fiche3 ex-sous-programmeFiche3 ex-sous-programme
Fiche3 ex-sous-programme
 
wxFormBuilder - Tutorial on “A GUI for making GUIs” for Python
wxFormBuilder - Tutorial on “A GUI for making GUIs” for PythonwxFormBuilder - Tutorial on “A GUI for making GUIs” for Python
wxFormBuilder - Tutorial on “A GUI for making GUIs” for Python
 
Nodejs Session01
Nodejs Session01Nodejs Session01
Nodejs Session01
 
Support POO Java Deuxième Partie
Support POO Java Deuxième PartieSupport POO Java Deuxième Partie
Support POO Java Deuxième Partie
 
VueJS Introduction
VueJS IntroductionVueJS Introduction
VueJS Introduction
 
Demarrer ionic en 5 etape
Demarrer ionic en 5 etapeDemarrer ionic en 5 etape
Demarrer ionic en 5 etape
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
 
Plsql
PlsqlPlsql
Plsql
 
Svelte JS introduction
Svelte JS introductionSvelte JS introduction
Svelte JS introduction
 
Svelte
SvelteSvelte
Svelte
 
Borland C++Builder 進階課程
Borland C++Builder 進階課程Borland C++Builder 進階課程
Borland C++Builder 進階課程
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
 
Introduction to NodeJS
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJS
 
Introduction à React
Introduction à ReactIntroduction à React
Introduction à React
 
Polymorphisme (cours, résumé)
Polymorphisme (cours, résumé)Polymorphisme (cours, résumé)
Polymorphisme (cours, résumé)
 
Gestion comptes bancaires Spring boot
Gestion comptes bancaires Spring bootGestion comptes bancaires Spring boot
Gestion comptes bancaires Spring boot
 

More from jaypi Ko

CVPR 2022 Tutorial에 대한 쉽고 상세한 Diffusion Probabilistic Model
CVPR 2022 Tutorial에 대한 쉽고 상세한 Diffusion Probabilistic ModelCVPR 2022 Tutorial에 대한 쉽고 상세한 Diffusion Probabilistic Model
CVPR 2022 Tutorial에 대한 쉽고 상세한 Diffusion Probabilistic Modeljaypi Ko
 
개념 이해가 쉬운 Variational Autoencoder (VAE)
개념 이해가 쉬운 Variational Autoencoder (VAE)개념 이해가 쉬운 Variational Autoencoder (VAE)
개념 이해가 쉬운 Variational Autoencoder (VAE)jaypi Ko
 
[신경망기초]오류역전파알고리즘구현
[신경망기초]오류역전파알고리즘구현[신경망기초]오류역전파알고리즘구현
[신경망기초]오류역전파알고리즘구현jaypi Ko
 
파이썬설치
파이썬설치파이썬설치
파이썬설치jaypi Ko
 
객체지향 단어가 의미하는 것
객체지향 단어가 의미하는 것객체지향 단어가 의미하는 것
객체지향 단어가 의미하는 것jaypi Ko
 
C언어 들어가기
C언어 들어가기C언어 들어가기
C언어 들어가기jaypi Ko
 
C언어 연산자에 대해 간과한 것
C언어 연산자에 대해 간과한 것C언어 연산자에 대해 간과한 것
C언어 연산자에 대해 간과한 것jaypi Ko
 
[확률통계]04모수추정
[확률통계]04모수추정[확률통계]04모수추정
[확률통계]04모수추정jaypi Ko
 
MFC 프로젝트 시작하기
MFC 프로젝트 시작하기MFC 프로젝트 시작하기
MFC 프로젝트 시작하기jaypi Ko
 
01 윈도우프로그램 들어가기
01 윈도우프로그램 들어가기01 윈도우프로그램 들어가기
01 윈도우프로그램 들어가기jaypi Ko
 
[신경망기초] 신경망학습
[신경망기초] 신경망학습[신경망기초] 신경망학습
[신경망기초] 신경망학습jaypi Ko
 
[신경망기초] 합성곱신경망
[신경망기초] 합성곱신경망[신경망기초] 합성곱신경망
[신경망기초] 합성곱신경망jaypi Ko
 
[신경망기초] 퍼셉트론구현
[신경망기초] 퍼셉트론구현[신경망기초] 퍼셉트론구현
[신경망기초] 퍼셉트론구현jaypi Ko
 
com architecture
com architecturecom architecture
com architecturejaypi Ko
 
[신경망기초] 소프트맥스회귀분석
[신경망기초] 소프트맥스회귀분석[신경망기초] 소프트맥스회귀분석
[신경망기초] 소프트맥스회귀분석jaypi Ko
 
[신경망기초] 심층신경망개요
[신경망기초] 심층신경망개요[신경망기초] 심층신경망개요
[신경망기초] 심층신경망개요jaypi Ko
 
[신경망기초] 선형회귀분석
[신경망기초] 선형회귀분석[신경망기초] 선형회귀분석
[신경망기초] 선형회귀분석jaypi Ko
 
[신경망기초] 오류역전파알고리즘
[신경망기초] 오류역전파알고리즘[신경망기초] 오류역전파알고리즘
[신경망기초] 오류역전파알고리즘jaypi Ko
 
[신경망기초] 멀티레이어퍼셉트론
[신경망기초] 멀티레이어퍼셉트론[신경망기초] 멀티레이어퍼셉트론
[신경망기초] 멀티레이어퍼셉트론jaypi Ko
 

More from jaypi Ko (20)

CVPR 2022 Tutorial에 대한 쉽고 상세한 Diffusion Probabilistic Model
CVPR 2022 Tutorial에 대한 쉽고 상세한 Diffusion Probabilistic ModelCVPR 2022 Tutorial에 대한 쉽고 상세한 Diffusion Probabilistic Model
CVPR 2022 Tutorial에 대한 쉽고 상세한 Diffusion Probabilistic Model
 
개념 이해가 쉬운 Variational Autoencoder (VAE)
개념 이해가 쉬운 Variational Autoencoder (VAE)개념 이해가 쉬운 Variational Autoencoder (VAE)
개념 이해가 쉬운 Variational Autoencoder (VAE)
 
[신경망기초]오류역전파알고리즘구현
[신경망기초]오류역전파알고리즘구현[신경망기초]오류역전파알고리즘구현
[신경망기초]오류역전파알고리즘구현
 
파이썬설치
파이썬설치파이썬설치
파이썬설치
 
객체지향 단어가 의미하는 것
객체지향 단어가 의미하는 것객체지향 단어가 의미하는 것
객체지향 단어가 의미하는 것
 
C언어 들어가기
C언어 들어가기C언어 들어가기
C언어 들어가기
 
C언어 연산자에 대해 간과한 것
C언어 연산자에 대해 간과한 것C언어 연산자에 대해 간과한 것
C언어 연산자에 대해 간과한 것
 
[확률통계]04모수추정
[확률통계]04모수추정[확률통계]04모수추정
[확률통계]04모수추정
 
MFC 프로젝트 시작하기
MFC 프로젝트 시작하기MFC 프로젝트 시작하기
MFC 프로젝트 시작하기
 
01 윈도우프로그램 들어가기
01 윈도우프로그램 들어가기01 윈도우프로그램 들어가기
01 윈도우프로그램 들어가기
 
[신경망기초] 신경망학습
[신경망기초] 신경망학습[신경망기초] 신경망학습
[신경망기초] 신경망학습
 
[신경망기초] 합성곱신경망
[신경망기초] 합성곱신경망[신경망기초] 합성곱신경망
[신경망기초] 합성곱신경망
 
[신경망기초] 퍼셉트론구현
[신경망기초] 퍼셉트론구현[신경망기초] 퍼셉트론구현
[신경망기초] 퍼셉트론구현
 
interface
interfaceinterface
interface
 
com architecture
com architecturecom architecture
com architecture
 
[신경망기초] 소프트맥스회귀분석
[신경망기초] 소프트맥스회귀분석[신경망기초] 소프트맥스회귀분석
[신경망기초] 소프트맥스회귀분석
 
[신경망기초] 심층신경망개요
[신경망기초] 심층신경망개요[신경망기초] 심층신경망개요
[신경망기초] 심층신경망개요
 
[신경망기초] 선형회귀분석
[신경망기초] 선형회귀분석[신경망기초] 선형회귀분석
[신경망기초] 선형회귀분석
 
[신경망기초] 오류역전파알고리즘
[신경망기초] 오류역전파알고리즘[신경망기초] 오류역전파알고리즘
[신경망기초] 오류역전파알고리즘
 
[신경망기초] 멀티레이어퍼셉트론
[신경망기초] 멀티레이어퍼셉트론[신경망기초] 멀티레이어퍼셉트론
[신경망기초] 멀티레이어퍼셉트론
 

04 이벤트처리

  • 2. 2 3장에서 해봤던 이벤트 처리 무슨 이벤트에 대해 어떤 처리를 해봤더라? 아직 아무것도 안 해본 것 같은데…
  • 3. 3 #include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArg, int nCmdShow) { HWND hWnd; MSG msg; 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”; if(!RegisterClass(&WndClass)) return NULL;
  • 4. 4 hWnd = CreateWindow( “Hello”, “Hello” , WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
  • 5. 5 LRESULT CALLBACK WndProc(HWND hWnd, UINT mesg, WPARAM wParam, LPARAM lParam) { switch(mesg) { case WM_DESTROY : PostQuitMessage(0); return FALSE; } return DefWindowProc(hWnd, mesg, wParam, lParam); } 윈도우 파괴 이벤트에 대한 프로그램 종료 처리
  • 6. 윈도우 배경을 검은색으로 6 이벤트 처리에 앞서 윈도우 클래스 살짝 복습
  • 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가지도 그냥 정한 거야
  • 10. 10 WM_LBUTTONDOWN MessageBox(HWND hWnd, LPCSTR szMsg, LPCSTR szTitle, UINT type) MB_OK, MB_OKCANCEL, MB_YESNO 마우스 왼쪽 버튼 눌림 이벤트 메시지박스(대화상자) 윈도우 생성 및 출력 출력할 메시지 대화상자 윈도우 타이틀 Message Box
  • 11. 11 LRESULT CALLBACK WndProc(HWND hWnd, UINT mesg, WPARAM wParam, LPARAM lParam) { switch(mesg) { case WM_LBUTTONDOWN: MessageBox(hWnd,"마우스왼쪽버튼클릭 ", "알림 ", MB_OK); break; case WM_DESTROY : PostQuitMessage(0); return FALSE; } return DefWindowProc(hWnd, mesg, wParam, lParam); } 파라미터로 넘어온 인자가 무엇 인지만 구분하면 된다 WM_RBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONUP 이 정도는 쉽게 유추할 수 있다
  • 12. 12 메시지 부가정보 처리 무슨 메시지인지는 당연히 구분하고 더 나아가 메시지에 담긴 정보도 활용
  • 13. 13 WM_MOUSEMOVE 마우스 움직임 이벤트 구분 마우스 좌표는 어디서 가져와야 하지 ?
  • 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 부분은 별로 건드릴 일이 없네