SlideShare a Scribd company logo
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

03 첫번째프로그램
03 첫번째프로그램03 첫번째프로그램
03 첫번째프로그램
jaypi Ko
 
Урок. Типи слайдів.
Урок. Типи слайдів.Урок. Типи слайдів.
Урок. Типи слайдів.
Andrey Podgayko
 
Cours CSS feuilles de style en cascade- mars 2015
Cours CSS feuilles de style en cascade- mars 2015Cours CSS feuilles de style en cascade- mars 2015
Cours CSS feuilles de style en cascade- mars 2015
Abdoulaye Dieng
 
Chapitre5: Classes et objets
Chapitre5: Classes et objetsChapitre5: Classes et objets
Chapitre5: Classes et objets
Aziz Darouichi
 
POO Java Chapitre 6 Exceptions
POO Java  Chapitre 6 ExceptionsPOO Java  Chapitre 6 Exceptions
POO Java Chapitre 6 Exceptions
Mouna Torjmen
 
Cycle de vie d'activité Android et les composant d'Android
Cycle de vie d'activité Android et les composant d'AndroidCycle de vie d'activité Android et les composant d'Android
Cycle de vie d'activité Android et les composant d'Android
Houssem Lahiani
 
An in Depth Journey into Odoo's ORM
An in Depth Journey into Odoo's ORMAn in Depth Journey into Odoo's ORM
An in Depth Journey into Odoo's ORM
Odoo
 
Qt Animation
Qt AnimationQt Animation
Qt Animation
William Lee
 
Le langage html
Le langage htmlLe langage html
Le langage html
Mohammed Amine Mostefai
 
Support de cours technologie et application m.youssfi
Support de cours technologie et application m.youssfiSupport de cours technologie et application m.youssfi
Support de cours technologie et application m.youssfi
ENSET, Université Hassan II Casablanca
 
Support programmation orientée objet c# .net version f8
Support programmation orientée objet c#  .net version f8Support programmation orientée objet c#  .net version f8
Support programmation orientée objet c# .net version f8
ENSET, Université Hassan II Casablanca
 
Chap1V2019: Cours en C++
Chap1V2019: Cours en C++Chap1V2019: Cours en C++
Chap1V2019: Cours en C++
Aziz Darouichi
 
Atelier Python 2eme partie par Achraf Kacimi El Hassani
Atelier Python 2eme partie par Achraf Kacimi El HassaniAtelier Python 2eme partie par Achraf Kacimi El Hassani
Atelier Python 2eme partie par Achraf Kacimi El HassaniShellmates
 
Examen principal- php - correction
Examen principal- php - correctionExamen principal- php - correction
Examen principal- php - correction
Ines Ouaz
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
Doeun KOCH
 
Chapitre 6 traitement des exceptions
Chapitre 6  traitement des exceptionsChapitre 6  traitement des exceptions
Chapitre 6 traitement des exceptions
Amir Souissi
 
Cours Visual Basic.NET
Cours Visual Basic.NETCours Visual Basic.NET
Cours Visual Basic.NET
Aziz Darouichi
 
Social Engineering the Windows Kernel by James Forshaw
Social Engineering the Windows Kernel by James ForshawSocial Engineering the Windows Kernel by James Forshaw
Social Engineering the Windows Kernel by James Forshaw
Shakacon
 
Initiation à Express js
Initiation à Express jsInitiation à Express js
Initiation à Express js
Abdoulaye Dieng
 
Урок 42. Алгоритми з повтореннями для опрацювання величин. Цикл з лічильником
 Урок 42. Алгоритми з повтореннями  для опрацювання величин.  Цикл з лічильником Урок 42. Алгоритми з повтореннями  для опрацювання величин.  Цикл з лічильником
Урок 42. Алгоритми з повтореннями для опрацювання величин. Цикл з лічильником
Василь Тереховський
 

What's hot (20)

03 첫번째프로그램
03 첫번째프로그램03 첫번째프로그램
03 첫번째프로그램
 
Урок. Типи слайдів.
Урок. Типи слайдів.Урок. Типи слайдів.
Урок. Типи слайдів.
 
Cours CSS feuilles de style en cascade- mars 2015
Cours CSS feuilles de style en cascade- mars 2015Cours CSS feuilles de style en cascade- mars 2015
Cours CSS feuilles de style en cascade- mars 2015
 
Chapitre5: Classes et objets
Chapitre5: Classes et objetsChapitre5: Classes et objets
Chapitre5: Classes et objets
 
POO Java Chapitre 6 Exceptions
POO Java  Chapitre 6 ExceptionsPOO Java  Chapitre 6 Exceptions
POO Java Chapitre 6 Exceptions
 
Cycle de vie d'activité Android et les composant d'Android
Cycle de vie d'activité Android et les composant d'AndroidCycle de vie d'activité Android et les composant d'Android
Cycle de vie d'activité Android et les composant d'Android
 
An in Depth Journey into Odoo's ORM
An in Depth Journey into Odoo's ORMAn in Depth Journey into Odoo's ORM
An in Depth Journey into Odoo's ORM
 
Qt Animation
Qt AnimationQt Animation
Qt Animation
 
Le langage html
Le langage htmlLe langage html
Le langage html
 
Support de cours technologie et application m.youssfi
Support de cours technologie et application m.youssfiSupport de cours technologie et application m.youssfi
Support de cours technologie et application m.youssfi
 
Support programmation orientée objet c# .net version f8
Support programmation orientée objet c#  .net version f8Support programmation orientée objet c#  .net version f8
Support programmation orientée objet c# .net version f8
 
Chap1V2019: Cours en C++
Chap1V2019: Cours en C++Chap1V2019: Cours en C++
Chap1V2019: Cours en C++
 
Atelier Python 2eme partie par Achraf Kacimi El Hassani
Atelier Python 2eme partie par Achraf Kacimi El HassaniAtelier Python 2eme partie par Achraf Kacimi El Hassani
Atelier Python 2eme partie par Achraf Kacimi El Hassani
 
Examen principal- php - correction
Examen principal- php - correctionExamen principal- php - correction
Examen principal- php - correction
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
Chapitre 6 traitement des exceptions
Chapitre 6  traitement des exceptionsChapitre 6  traitement des exceptions
Chapitre 6 traitement des exceptions
 
Cours Visual Basic.NET
Cours Visual Basic.NETCours Visual Basic.NET
Cours Visual Basic.NET
 
Social Engineering the Windows Kernel by James Forshaw
Social Engineering the Windows Kernel by James ForshawSocial Engineering the Windows Kernel by James Forshaw
Social Engineering the Windows Kernel by James Forshaw
 
Initiation à Express js
Initiation à Express jsInitiation à Express js
Initiation à Express js
 
Урок 42. Алгоритми з повтореннями для опрацювання величин. Цикл з лічильником
 Урок 42. Алгоритми з повтореннями  для опрацювання величин.  Цикл з лічильником Урок 42. Алгоритми з повтореннями  для опрацювання величин.  Цикл з лічильником
Урок 42. Алгоритми з повтореннями для опрацювання величин. Цикл з лічильником
 

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 Model
jaypi 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
 
10 컨트롤윈도우
10 컨트롤윈도우10 컨트롤윈도우
10 컨트롤윈도우
jaypi Ko
 
[신경망기초] 신경망학습
[신경망기초] 신경망학습[신경망기초] 신경망학습
[신경망기초] 신경망학습
jaypi Ko
 
[신경망기초] 합성곱신경망
[신경망기초] 합성곱신경망[신경망기초] 합성곱신경망
[신경망기초] 합성곱신경망
jaypi Ko
 
[신경망기초] 퍼셉트론구현
[신경망기초] 퍼셉트론구현[신경망기초] 퍼셉트론구현
[신경망기초] 퍼셉트론구현
jaypi Ko
 
interface
interfaceinterface
interface
jaypi Ko
 
com architecture
com architecturecom architecture
com architecture
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 윈도우프로그램 들어가기
 
10 컨트롤윈도우
10 컨트롤윈도우10 컨트롤윈도우
10 컨트롤윈도우
 
[신경망기초] 신경망학습
[신경망기초] 신경망학습[신경망기초] 신경망학습
[신경망기초] 신경망학습
 
[신경망기초] 합성곱신경망
[신경망기초] 합성곱신경망[신경망기초] 합성곱신경망
[신경망기초] 합성곱신경망
 
[신경망기초] 퍼셉트론구현
[신경망기초] 퍼셉트론구현[신경망기초] 퍼셉트론구현
[신경망기초] 퍼셉트론구현
 
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 부분은 별로 건드릴 일이 없네