SlideShare a Scribd company logo
1 of 14
Download to read offline
CHAP. 6
일반적 유형의 프로그램
1
2
먼저 윈도우 클래스 두 개
하나는 흰색 배경
또 다른 하나는 검은색 배경
윈도우 배경 색 설정은 윈도우 클래스 정의 부분에 있었다
윈도우 클래스를 두 개 등록하면 돼
3
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND _hWnd2;
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;
흰색배경 갖는
hello로 하나 정의
등록
4
WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
WndClass.lpszClassName = "WND2";
if(!RegisterClass(&WndClass)) return NULL;
나머지 속성은 다 같으니까 달라지는 부분만 다시 설정
검은색 배경을 갖는 WND2 윈도우 클래스 정의 및 등록
이름은 붙이기 나름
5
hWnd = CreateWindow(
"Hello",
"Hello",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL, NULL, hInstance,
NULL
);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
윈도우 클래스 이름이
hello인 클래스를 이용
하여 윈도우 생성
hello 윈도우 클래스 이용해서 윈도우 생성
hello 윈도우 클래스에서 배경색을 흰색으로 설정했으니까
만들어 지는 윈도우의 배경은 흰색
6
_hWnd2 = CreateWindow(
"WND2",
"World",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL, NULL, hInstance,
NULL
);
ShowWindow(_hWnd2, nCmdShow);
UpdateWindow(_hWnd2);
윈도우 클래스 이름이
WND2인 클래스를 이용
하여 윈도우 생성
WND2 윈도우 클래스 이용해서 윈도우 생성
WND2 윈도우 클래스에서 배경색을 검은색으로 설정했으니까
만들어 지는 윈도우의 배경은 검은색
7
윈도우 프로시저도 두 개
마우스 왼쪽 버튼 눌림에 대해
두 윈도우에서 각기 다른 메시지 박스 출력
메시지 박스 함수의 첫 번째 인자를 생각해 보면
다음과 같이 간단히 해결될 수 있다
MessageBox(hWnd, "안녕하세요", "인사", MB_OK);
8
LRESULT CALLBACK WndProc(HWND hWnd, UINT mesg, WPARAM wParam, LPARAM lParam)
{
switch(mesg)
{
case WM_LBUTTONDOWN:
if (hWnd == _hWnd2)
MessageBox(hWnd, "저리가세요", "인사", MB_OK);
else
MessageBox(hWnd, "안녕하세요", "인사", MB_OK);
break;
case WM_DESTROY :
PostQuitMessage(0);
return FALSE;
}
return DefWindowProc(hWnd, mesg, wParam, lParam);
}
이벤트를 발생시킨 윈도우의
핸들이 넘어온다
파라미터로 넘어온 윈도우 핸들이 누구인지를 비교
검은색 윈도우의 핸들이 전역변수 _hWnd2 이기에 가능
전역변수가 아닐 땐 어떻게 하지 ?
9
검은색 윈도우도 별도의 윈도우 프로시저를 갖도록
WndClass.lpfnWndProc = WndProc2;
WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
WndClass.lpszClassName = "WND2";
if(!RegisterClass(&WndClass)) return NULL;
사용할 윈도우 프로시저 함수의 이름을 WndProc2로 정함
이름은 붙이기 나름
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc2(HWND, UINT, WPARAM, LPARAM);
도입부에 함수의 프로토타입 추가
10
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);
}
LRESULT CALLBACK WndProc2(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);
}
11
이와 관련하여 메시지 루프 부분을 다시 살펴보면
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
CTRL-C CTRL-V 같은 단축키 처리 (번역)
이벤트가 발생한 윈도우의 윈도우 프로시저 호출
메시지 전달 = 메시지 분배
dispatch
이벤트 발생한 윈도우 구분해서 호출 필요
윈도우 프로시저 호출 담당 함수에 대한 궁금증 해결 됐지 ?
12
윈도우 간의 통신
흰색 윈도우에서 마우스 왼쪽 버튼 누르면
검은색 윈도우의 타이틀을 Black으로 변경
13
SetWindowText(HWND hWnd, LPCSTR lpString)
윈도우 타이틀 관련 함수
변경할 윈도우 타이틀
윈도우 타이틀 변경
GetWindowText(HWND hWnd, LPSTR lpString, int nMaxCount)
윈도우 타이틀 얻기
얻어올 윈도우 타이틀
문자열의 최대 길이
char szTitle[1024];
14
LRESULT CALLBACK WndProc(HWND hWnd, UINT mesg, WPARAM wParam, LPARAM lParam)
{
switch(mesg)
{
case WM_LBUTTONDOWN:
SetWindowText(_hWnd2, "Black");
break;
case WM_DESTROY :
PostQuitMessage(0);
return FALSE;
}
return DefWindowProc(hWnd, mesg, wParam, lParam);
}
검은색 윈도우의 윈도우 핸들만 알면 가능
검은색 윈도우의 핸들이 전역변수 _hWnd2 이기에 가능
윈도우 간의 통신이라고 거창하게 얘기했지만
윈도우 핸들만 알면 Ok~ 전역변수가 계속 신경 쓰여

More Related Content

What's hot

03 첫번째프로그램
03 첫번째프로그램03 첫번째프로그램
03 첫번째프로그램jaypi Ko
 
10 컨트롤윈도우
10 컨트롤윈도우10 컨트롤윈도우
10 컨트롤윈도우jaypi Ko
 
Impact of the New ORM on Your Modules
Impact of the New ORM on Your ModulesImpact of the New ORM on Your Modules
Impact of the New ORM on Your ModulesOdoo
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017名辰 洪
 
Thirteen ways of looking at a turtle
Thirteen ways of looking at a turtleThirteen ways of looking at a turtle
Thirteen ways of looking at a turtleScott Wlaschin
 
Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Scott Wlaschin
 
Chapitre 2: String en Java
Chapitre 2:  String en JavaChapitre 2:  String en Java
Chapitre 2: String en JavaAziz Darouichi
 
Tp1 compte rendu en langage c
Tp1 compte rendu en langage cTp1 compte rendu en langage c
Tp1 compte rendu en langage cEbrima NJIE
 
Poo en c++ les relations entre classes
Poo en c++ les relations entre classesPoo en c++ les relations entre classes
Poo en c++ les relations entre classesAmina HAMEURLAINE
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
Serie recurrents & arithmetiques
Serie recurrents & arithmetiquesSerie recurrents & arithmetiques
Serie recurrents & arithmetiquesmohamed_SAYARI
 
Improving WordPress Performance with Xdebug and PHP Profiling
Improving WordPress Performance with Xdebug and PHP ProfilingImproving WordPress Performance with Xdebug and PHP Profiling
Improving WordPress Performance with Xdebug and PHP ProfilingOtto Kekäläinen
 
New Framework - ORM
New Framework - ORMNew Framework - ORM
New Framework - ORMOdoo
 
OpenNTF Domino API (ODA): Super-Charging Domino Development
OpenNTF Domino API (ODA): Super-Charging Domino DevelopmentOpenNTF Domino API (ODA): Super-Charging Domino Development
OpenNTF Domino API (ODA): Super-Charging Domino DevelopmentPaul Withers
 

What's hot (20)

03 첫번째프로그램
03 첫번째프로그램03 첫번째프로그램
03 첫번째프로그램
 
10 컨트롤윈도우
10 컨트롤윈도우10 컨트롤윈도우
10 컨트롤윈도우
 
Impact of the New ORM on Your Modules
Impact of the New ORM on Your ModulesImpact of the New ORM on Your Modules
Impact of the New ORM on Your Modules
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 
Thirteen ways of looking at a turtle
Thirteen ways of looking at a turtleThirteen ways of looking at a turtle
Thirteen ways of looking at a turtle
 
Cours JavaScript
Cours JavaScriptCours JavaScript
Cours JavaScript
 
Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)
 
Borland C++Builder 進階課程
Borland C++Builder 進階課程Borland C++Builder 進階課程
Borland C++Builder 進階課程
 
Chapitre 2: String en Java
Chapitre 2:  String en JavaChapitre 2:  String en Java
Chapitre 2: String en Java
 
bac info : série récursivité
bac info : série récursivitébac info : série récursivité
bac info : série récursivité
 
Tp1 compte rendu en langage c
Tp1 compte rendu en langage cTp1 compte rendu en langage c
Tp1 compte rendu en langage c
 
Poo en c++ les relations entre classes
Poo en c++ les relations entre classesPoo en c++ les relations entre classes
Poo en c++ les relations entre classes
 
Algorithmes de tri
Algorithmes de triAlgorithmes de tri
Algorithmes de tri
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
Cours javascript v1
Cours javascript v1Cours javascript v1
Cours javascript v1
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Serie recurrents & arithmetiques
Serie recurrents & arithmetiquesSerie recurrents & arithmetiques
Serie recurrents & arithmetiques
 
Improving WordPress Performance with Xdebug and PHP Profiling
Improving WordPress Performance with Xdebug and PHP ProfilingImproving WordPress Performance with Xdebug and PHP Profiling
Improving WordPress Performance with Xdebug and PHP Profiling
 
New Framework - ORM
New Framework - ORMNew Framework - ORM
New Framework - ORM
 
OpenNTF Domino API (ODA): Super-Charging Domino Development
OpenNTF Domino API (ODA): Super-Charging Domino DevelopmentOpenNTF Domino API (ODA): Super-Charging Domino Development
OpenNTF Domino API (ODA): Super-Charging Domino Development
 

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
 
[신경망기초] 소프트맥스회귀분석
[신경망기초] 소프트맥스회귀분석[신경망기초] 소프트맥스회귀분석
[신경망기초] 소프트맥스회귀분석
 
[신경망기초] 심층신경망개요
[신경망기초] 심층신경망개요[신경망기초] 심층신경망개요
[신경망기초] 심층신경망개요
 
[신경망기초] 선형회귀분석
[신경망기초] 선형회귀분석[신경망기초] 선형회귀분석
[신경망기초] 선형회귀분석
 
[신경망기초] 오류역전파알고리즘
[신경망기초] 오류역전파알고리즘[신경망기초] 오류역전파알고리즘
[신경망기초] 오류역전파알고리즘
 
[신경망기초] 멀티레이어퍼셉트론
[신경망기초] 멀티레이어퍼셉트론[신경망기초] 멀티레이어퍼셉트론
[신경망기초] 멀티레이어퍼셉트론
 

06 일반적 유형의 프로그램

  • 2. 2 먼저 윈도우 클래스 두 개 하나는 흰색 배경 또 다른 하나는 검은색 배경 윈도우 배경 색 설정은 윈도우 클래스 정의 부분에 있었다 윈도우 클래스를 두 개 등록하면 돼
  • 3. 3 #include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); HWND _hWnd2; 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; 흰색배경 갖는 hello로 하나 정의 등록
  • 4. 4 WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); WndClass.lpszClassName = "WND2"; if(!RegisterClass(&WndClass)) return NULL; 나머지 속성은 다 같으니까 달라지는 부분만 다시 설정 검은색 배경을 갖는 WND2 윈도우 클래스 정의 및 등록 이름은 붙이기 나름
  • 5. 5 hWnd = CreateWindow( "Hello", "Hello", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); 윈도우 클래스 이름이 hello인 클래스를 이용 하여 윈도우 생성 hello 윈도우 클래스 이용해서 윈도우 생성 hello 윈도우 클래스에서 배경색을 흰색으로 설정했으니까 만들어 지는 윈도우의 배경은 흰색
  • 6. 6 _hWnd2 = CreateWindow( "WND2", "World", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); ShowWindow(_hWnd2, nCmdShow); UpdateWindow(_hWnd2); 윈도우 클래스 이름이 WND2인 클래스를 이용 하여 윈도우 생성 WND2 윈도우 클래스 이용해서 윈도우 생성 WND2 윈도우 클래스에서 배경색을 검은색으로 설정했으니까 만들어 지는 윈도우의 배경은 검은색
  • 7. 7 윈도우 프로시저도 두 개 마우스 왼쪽 버튼 눌림에 대해 두 윈도우에서 각기 다른 메시지 박스 출력 메시지 박스 함수의 첫 번째 인자를 생각해 보면 다음과 같이 간단히 해결될 수 있다 MessageBox(hWnd, "안녕하세요", "인사", MB_OK);
  • 8. 8 LRESULT CALLBACK WndProc(HWND hWnd, UINT mesg, WPARAM wParam, LPARAM lParam) { switch(mesg) { case WM_LBUTTONDOWN: if (hWnd == _hWnd2) MessageBox(hWnd, "저리가세요", "인사", MB_OK); else MessageBox(hWnd, "안녕하세요", "인사", MB_OK); break; case WM_DESTROY : PostQuitMessage(0); return FALSE; } return DefWindowProc(hWnd, mesg, wParam, lParam); } 이벤트를 발생시킨 윈도우의 핸들이 넘어온다 파라미터로 넘어온 윈도우 핸들이 누구인지를 비교 검은색 윈도우의 핸들이 전역변수 _hWnd2 이기에 가능 전역변수가 아닐 땐 어떻게 하지 ?
  • 9. 9 검은색 윈도우도 별도의 윈도우 프로시저를 갖도록 WndClass.lpfnWndProc = WndProc2; WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); WndClass.lpszClassName = "WND2"; if(!RegisterClass(&WndClass)) return NULL; 사용할 윈도우 프로시저 함수의 이름을 WndProc2로 정함 이름은 붙이기 나름 #include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK WndProc2(HWND, UINT, WPARAM, LPARAM); 도입부에 함수의 프로토타입 추가
  • 10. 10 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); } LRESULT CALLBACK WndProc2(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); }
  • 11. 11 이와 관련하여 메시지 루프 부분을 다시 살펴보면 while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; CTRL-C CTRL-V 같은 단축키 처리 (번역) 이벤트가 발생한 윈도우의 윈도우 프로시저 호출 메시지 전달 = 메시지 분배 dispatch 이벤트 발생한 윈도우 구분해서 호출 필요 윈도우 프로시저 호출 담당 함수에 대한 궁금증 해결 됐지 ?
  • 12. 12 윈도우 간의 통신 흰색 윈도우에서 마우스 왼쪽 버튼 누르면 검은색 윈도우의 타이틀을 Black으로 변경
  • 13. 13 SetWindowText(HWND hWnd, LPCSTR lpString) 윈도우 타이틀 관련 함수 변경할 윈도우 타이틀 윈도우 타이틀 변경 GetWindowText(HWND hWnd, LPSTR lpString, int nMaxCount) 윈도우 타이틀 얻기 얻어올 윈도우 타이틀 문자열의 최대 길이 char szTitle[1024];
  • 14. 14 LRESULT CALLBACK WndProc(HWND hWnd, UINT mesg, WPARAM wParam, LPARAM lParam) { switch(mesg) { case WM_LBUTTONDOWN: SetWindowText(_hWnd2, "Black"); break; case WM_DESTROY : PostQuitMessage(0); return FALSE; } return DefWindowProc(hWnd, mesg, wParam, lParam); } 검은색 윈도우의 윈도우 핸들만 알면 가능 검은색 윈도우의 핸들이 전역변수 _hWnd2 이기에 가능 윈도우 간의 통신이라고 거창하게 얘기했지만 윈도우 핸들만 알면 Ok~ 전역변수가 계속 신경 쓰여