1. 일반 WinAPI로 윈도우 생성
#include <windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
HWND hWndMain;
LPCTSTR lpClassName=TEXT("main");
LPCTSTR lpTitleName=TEXT("Tomato Soap");
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdParam,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst=hInstance;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=(WNDPROC)WndProc;
WndClass.lpszClassName=lpClassName;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd = CreateWindow(lpClassName,lpTitleName,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,500,500,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
while (GetMessage(&Message,0,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
UnregisterClass(lpClassName, hInstance);
return (int)Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
switch(iMessage) {
case WM_CREATE:
hWndMain=hWnd;
return 0;
case WM_SIZE:
return 0;
case WM_SETFOCUS:
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_LBUTTONDOWN:
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
|
2. message cracker : #include <windowsx.h> 사용
메세지 처리를 함수로 둘 수 있도록 도와준다.
#include <windows.h>
#include <windowsx.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE g_hInst;
LPCTSTR lpClassName = TEXT("main");
LPCTSTR lpWindowName = TEXT("Tomato Soap");
HWND hWndMain;
//fucntion : message cracker
BOOL OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct);
void OnChar(HWND hWnd, TCHAR ch, int cRepeat);
void OnKey(HWND hWnd, UINT vk, BOOL fDown, int cRepeat, UINT flags);
void OnPaint(HWND hWnd);
void OnSetFocus(HWND hWnd, HWND hwndOldFocus);
void OnKillFocus(HWND hWnd, HWND hwndNewFocus);
void OnDestroy(HWND hWnd);
void OnLButtonDown(HWND hWnd, BOOL fDoubleClick, int x, int y, UINT keyFlags);
void OnMouseMove(HWND hWnd, int x, int y, UINT keyFlags);
void OnLButtonUp(HWND hWnd, int x, int y, UINT keyFlags);
void OnTimer(HWND hWnd, UINT id);
void OnSize(HWND hWnd, UINT state, int cx, int cy);
void OnHScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos);
void OnVScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos);
void OnContextMenu(HWND hWnd, HWND hwndContext, UINT xPos, UINT yPos);
void OnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify);
BOOL OnSetCursor(HWND hWnd, HWND hwndCursor, UINT codeHitTest, UINT msg);
UINT OnGetDlgCode(HWND hWnd, LPMSG lpmsg);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
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;
WndClass.lpszClassName = lpClassName;
WndClass.lpszMenuName = NULL;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd = CreateWindow(
lpClassName, //Class Name
lpWindowName, //Window Name
WS_OVERLAPPEDWINDOW | WS_VSCROLL, //dwStyle
CW_USEDEFAULT, //x
CW_USEDEFAULT, //y
210, //nWidth
300, //nHeight
NULL, //hWndParent
(HMENU)NULL, //hMenu
hInstance, //hInstance
NULL //lpParam
);
ShowWindow(hWnd, nCmdShow);
while (GetMessage(&Message, NULL, 0, 0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return (int)Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
switch(iMessage) {
HANDLE_MSG(hWnd, WM_CREATE, OnCreate);
HANDLE_MSG(hWnd, WM_DESTROY, OnDestroy);
HANDLE_MSG(hWnd, WM_CHAR, OnChar);
HANDLE_MSG(hWnd, WM_KEYDOWN, OnKey);
HANDLE_MSG(hWnd, WM_KEYUP, OnKey);
HANDLE_MSG(hWnd, WM_PAINT, OnPaint);
HANDLE_MSG(hWnd, WM_SETFOCUS, OnSetFocus);
HANDLE_MSG(hWnd, WM_KILLFOCUS, OnKillFocus);
HANDLE_MSG(hWnd, WM_LBUTTONDOWN, OnLButtonDown);
HANDLE_MSG(hWnd, WM_LBUTTONDBLCLK, OnLButtonDown);
HANDLE_MSG(hWnd, WM_MOUSEMOVE, OnMouseMove);
HANDLE_MSG(hWnd, WM_LBUTTONUP, OnLButtonUp);
HANDLE_MSG(hWnd, WM_TIMER, OnTimer);
HANDLE_MSG(hWnd, WM_SIZE, OnSize);
HANDLE_MSG(hWnd, WM_HSCROLL, OnHScroll);
HANDLE_MSG(hWnd, WM_VSCROLL, OnVScroll);
HANDLE_MSG(hWnd, WM_CONTEXTMENU, OnContextMenu);
HANDLE_MSG(hWnd, WM_COMMAND, OnCommand);
HANDLE_MSG(hWnd, WM_SETCURSOR, OnSetCursor);
HANDLE_MSG(hWnd, WM_GETDLGCODE, OnGetDlgCode);
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
BOOL OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct){ return TRUE;}
void OnDestroy(HWND hWnd){PostQuitMessage(0);}
void OnSize(HWND hWnd, UINT state, int cx, int cy){}
void OnKey(HWND hWnd, UINT vk, BOOL fDown, int cRepeat, UINT flags){}
void OnPaint(HWND hWnd)
{
//OnPaint에 아래 코드가 없으면 LBUTTON 같은 곳에서 MessageBox() 출력시 메세지 박스 창이 숨어버린다.
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hWnd,&ps);
//TextOut(hdc,0,0,buf,lstrlen(buf));
EndPaint(hWnd,&ps);
}
void OnSetFocus(HWND hWnd, HWND hwndOldFocus){}
void OnKillFocus(HWND hWnd, HWND hwndNewFocus){}
void OnChar(HWND hWnd, TCHAR ch, int cRepeat){}
void OnHScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos){}
void OnVScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos){}
void OnContextMenu(HWND hWnd, HWND hwndContext, UINT xPos, UINT yPos){}
void OnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify){}
void OnLButtonDown(HWND hWnd, BOOL fDoubleClick, int x, int y, UINT keyFlags){}
void OnMouseMove(HWND hWnd, int x, int y, UINT keyFlags){}
void OnLButtonUp(HWND hWnd, int x, int y, UINT keyFlags){}
void OnTimer(HWND hWnd, UINT id){}
BOOL OnSetCursor(HWND hWnd, HWND hwndCursor, UINT codeHitTest, UINT msg){ return FORWARD_WM_SETCURSOR(hWnd,hwndCursor,codeHitTest,msg,DefWindowProc);}
UINT OnGetDlgCode(HWND hWnd, LPMSG lpmsg){ return 0; }
|
3. message craker를 Class로 작성한 모습
#include <windows.h>
#include <windowsx.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
HWND hWndMain;
LPCTSTR lpClassName=TEXT("main");
LPCTSTR lpTitleName=TEXT("Tomato Soap");
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdParam,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst=hInstance;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=(WNDPROC)WndProc;
WndClass.lpszClassName=lpClassName;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd = CreateWindow(lpClassName,lpTitleName,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,500,500,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
while (GetMessage(&Message,0,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return (int)Message.wParam;
}
class CTest
{
public:
CTest(void);
~CTest(void);
public:
LRESULT onMessage(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
private:
bool onCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct);
void onDestroy(HWND hWnd);
void onSize(HWND hWnd, UINT state, int cx, int cy);
void onKey(HWND hWnd, UINT vk, bool fDown, int cRepeat, UINT flags);
void onPaint(HWND hWnd);
void onSetFocus(HWND hWnd, HWND hwndOldFocus);
void onKillFocus(HWND hWnd, HWND hwndNewFocus);
void onChar(HWND hWnd, TCHAR ch, int cRepeat);
void onHScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos);
void onVScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos);
void onContextMenu(HWND hWnd, HWND hwndContext, UINT xPos, UINT yPos);
void onCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify);
void onLButtonDown(HWND hWnd, bool fDoubleClick, int x, int y, UINT keyFlags);
void onMouseMove(HWND hWnd, int x, int y, UINT keyFlags);
void onLButtonUp(HWND hWnd, int x, int y, UINT keyFlags);
void onTimer(HWND hWnd, UINT id);
BOOL onSetCursor(HWND hWnd, HWND hwndCursor, UINT codeHitTest, UINT msg);
UINT onGetDlgCode(HWND hWnd, LPMSG lpmsg);
};
//CTest cpp 부분
CTest::CTest(void) {}
CTest::~CTest(void) {}
LRESULT CTest::onMessage(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
switch (iMessage) {
HANDLE_MSG(hWnd, WM_CREATE, onCreate);
HANDLE_MSG(hWnd, WM_DESTROY, onDestroy);
HANDLE_MSG(hWnd, WM_CHAR, onChar);
HANDLE_MSG(hWnd, WM_KEYDOWN, onKey);
HANDLE_MSG(hWnd, WM_KEYUP, onKey);
HANDLE_MSG(hWnd, WM_PAINT, onPaint);
HANDLE_MSG(hWnd, WM_SETFOCUS, onSetFocus);
HANDLE_MSG(hWnd, WM_KILLFOCUS, onKillFocus);
HANDLE_MSG(hWnd, WM_LBUTTONDOWN, onLButtonDown);
HANDLE_MSG(hWnd, WM_LBUTTONDBLCLK, onLButtonDown);
HANDLE_MSG(hWnd, WM_MOUSEMOVE, onMouseMove);
HANDLE_MSG(hWnd, WM_LBUTTONUP, onLButtonUp);
HANDLE_MSG(hWnd, WM_TIMER, onTimer);
HANDLE_MSG(hWnd, WM_SIZE, onSize);
HANDLE_MSG(hWnd, WM_HSCROLL, onHScroll);
HANDLE_MSG(hWnd, WM_VSCROLL, onVScroll);
HANDLE_MSG(hWnd, WM_CONTEXTMENU, onContextMenu);
HANDLE_MSG(hWnd, WM_COMMAND, onCommand);
HANDLE_MSG(hWnd, WM_SETCURSOR, onSetCursor);
HANDLE_MSG(hWnd, WM_GETDLGCODE, onGetDlgCode);
case WM_MOUSEWHEEL:
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
void CTest::onPaint(HWND hWnd)
{
//OnPaint에 아래 코드가 없으면 LBUTTON 같은 곳에서 MessageBox() 출력시 메세지 박스 창이 숨어버린다.
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hWnd,&ps);
//TextOut(hdc,0,0,buf,lstrlen(buf));
EndPaint(hWnd,&ps);
}
bool CTest::onCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct){return true;}
void CTest::onDestroy(HWND hWnd){PostQuitMessage(0);}
void CTest::onSize(HWND hWnd, UINT state, int cx, int cy){}
void CTest::onKey(HWND hWnd, UINT vk, bool fDown, int cRepeat, UINT flags){}
void CTest::onSetFocus(HWND hWnd, HWND hwndOldFocus){}
void CTest::onKillFocus(HWND hWnd, HWND hwndNewFocus){}
void CTest::onHScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos){}
void CTest::onVScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos){}
void CTest::onContextMenu(HWND hWnd, HWND hwndContext, UINT xPos, UINT yPos){}
void CTest::onCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify){}
void CTest::onLButtonDown(HWND hWnd, bool fDoubleClick, int x, int y, UINT keyFlags){}
void CTest::onMouseMove(HWND hWnd, int x, int y, UINT keyFlags){}
void CTest::onLButtonUp(HWND hWnd, int x, int y, UINT keyFlags){}
void CTest::onTimer(HWND hWnd, UINT id){}
BOOL CTest::onSetCursor(HWND hWnd, HWND hwndCursor, UINT codeHitTest, UINT msg){return FORWARD_WM_SETCURSOR(hWnd,hwndCursor,codeHitTest,msg,DefWindowProc);}
UINT CTest::onGetDlgCode(HWND hWnd, LPMSG lpmsg){ return 0;}
void CTest::onChar(HWND hWnd, TCHAR ch, int cRepeat){}
//메세지 처리 WindowProc
CTest* test;
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage,WPARAM wParam,LPARAM lParam)
{
return test->onMessage(hWnd, iMessage, wParam, lParam);
}
|
4. WindowProc 하나로 여러 객체에서 사용. + message cracker
CTest 클래스로 생성된 윈도우들이 하나의 WindowProc을 통해 처리한다.
(class 안에 WindowProc을 넣으면 static 난립 및 클래스 멤버 변수 활용 문제 등으로 인해 시간낭비 하게 될 것이다.)
Main.cpp
#include <windows.h>
#include "Test.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
HWND hWndMain;
LPCTSTR lpClassName=TEXT("main");
LPCTSTR lpTitleName=TEXT("Tomato Soap");
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdParam,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst=hInstance;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=(WNDPROC)WndProc;
WndClass.lpszClassName=lpClassName;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd = CreateWindow(lpClassName,lpTitleName,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,500,500,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
while (GetMessage(&Message,0,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
UnregisterClass(lpClassName, hInstance);
return (int)Message.wParam;
}
CTest Test1, Test2;
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
switch(iMessage) {
case WM_CREATE:
hWndMain=hWnd;
Test1.create(10, 10, 200, 300, hWnd);
Test2.create(210, 10, 200, 300, hWnd);
return 0;
case WM_SIZE:
return 0;
case WM_SETFOCUS:
SetFocus(Test1.hWnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_LBUTTONDOWN:
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
} |
Test.h
#pragma once
#include <windows.h>
class CTest
{
public:
CTest(void);
~CTest(void);
public:
HWND hWnd;
HWND hWndParent;
WNDCLASS WndClass;
public:
void create(int x, int y, int nWidth, int nHeight, HWND hWndParent);
LRESULT onMessage(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
private:
bool onCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct);
void onDestroy(HWND hWnd);
void onSize(HWND hWnd, UINT state, int cx, int cy);
void onKey(HWND hWnd, UINT vk, bool fDown, int cRepeat, UINT flags);
void onPaint(HWND hWnd);
void onSetFocus(HWND hWnd, HWND hwndOldFocus);
void onKillFocus(HWND hWnd, HWND hwndNewFocus);
void onChar(HWND hWnd, TCHAR ch, int cRepeat);
void onHScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos);
void onVScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos);
void onContextMenu(HWND hWnd, HWND hwndContext, UINT xPos, UINT yPos);
void onCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify);
void onLButtonDown(HWND hWnd, bool fDoubleClick, int x, int y, UINT keyFlags);
void onMouseMove(HWND hWnd, int x, int y, UINT keyFlags);
void onLButtonUp(HWND hWnd, int x, int y, UINT keyFlags);
void onTimer(HWND hWnd, UINT id);
BOOL onSetCursor(HWND hWnd, HWND hwndCursor, UINT codeHitTest, UINT msg);
UINT onGetDlgCode(HWND hWnd, LPMSG lpmsg);
LRESULT onImeComposition(HWND hWnd, WPARAM wParam, LPARAM lParam);
LRESULT onImeChar(HWND hWnd, WPARAM wParam, LPARAM lParam);
};
|
Test.cpp
CEditorManager 클래스에서 CTest 클래스 인스턴스와 HWND를 갖고 (STL map 사용)
메세지 발생시 적절한 클래스의 메세지 처리함수를 호출.
#include "Test.h"
#include <windowsx.h>
#include <map>
typedef std::map<HWND, CTest*> eMap;
class CEditorManager
{
public:
CEditorManager(void) {}
~CEditorManager(void) {}
private:
eMap editorMap;
public:
void add(HWND hWnd, CTest* editor)
{
editorMap.insert(std::pair< HWND, CTest* >(hWnd, editor));
}
CTest* get(HWND hWnd)
{
eMap::iterator where = editorMap.find(hWnd);
if (where == editorMap.end()) return NULL;
else return where->second;
}
};
CEditorManager EditorManager;
LRESULT CALLBACK EditorWndProc(HWND hWnd, UINT iMessage,WPARAM wParam,LPARAM lParam)
{
CTest* test = EditorManager.get(hWnd);
if (NULL == test) //등록 된거 없으면 찾아 넣어~
{
//CreateWindow시 마지막 인자값을 받아옴.
test = (CTest*)((LPCREATESTRUCT)lParam)->lpCreateParams;
EditorManager.add(hWnd, test);
}
return test->onMessage(hWnd, iMessage, wParam, lParam);
}
CTest::CTest(void) {}
CTest::~CTest(void) {}
void CTest::create(int x, int y, int nWidth, int nHeight, HWND hWndParent)
{
LPCTSTR lpClassName = TEXT("Test");
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=NULL;
WndClass.hCursor=LoadCursor(NULL,IDC_IBEAM);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=GetModuleHandle(NULL);
WndClass.lpfnWndProc=(WNDPROC)EditorWndProc;
WndClass.lpszClassName=lpClassName;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
RegisterClass(&WndClass);
this->hWnd = CreateWindow(
lpClassName,
TEXT("editor"),
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_HSCROLL,
x, y,
nWidth, nHeight,
hWndParent,
(HMENU)NULL, GetModuleHandle(NULL), this);
this->hWndParent = hWndParent;
}
LRESULT CTest::onMessage(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
switch (iMessage) {
HANDLE_MSG(hWnd, WM_CREATE, onCreate);
HANDLE_MSG(hWnd, WM_DESTROY, onDestroy);
HANDLE_MSG(hWnd, WM_CHAR, onChar);
HANDLE_MSG(hWnd, WM_KEYDOWN, onKey);
HANDLE_MSG(hWnd, WM_KEYUP, onKey);
HANDLE_MSG(hWnd, WM_PAINT, onPaint);
HANDLE_MSG(hWnd, WM_SETFOCUS, onSetFocus);
HANDLE_MSG(hWnd, WM_KILLFOCUS, onKillFocus);
HANDLE_MSG(hWnd, WM_LBUTTONDOWN, onLButtonDown);
HANDLE_MSG(hWnd, WM_LBUTTONDBLCLK, onLButtonDown);
HANDLE_MSG(hWnd, WM_MOUSEMOVE, onMouseMove);
HANDLE_MSG(hWnd, WM_LBUTTONUP, onLButtonUp);
HANDLE_MSG(hWnd, WM_TIMER, onTimer);
HANDLE_MSG(hWnd, WM_SIZE, onSize);
HANDLE_MSG(hWnd, WM_HSCROLL, onHScroll);
HANDLE_MSG(hWnd, WM_VSCROLL, onVScroll);
HANDLE_MSG(hWnd, WM_CONTEXTMENU, onContextMenu);
HANDLE_MSG(hWnd, WM_COMMAND, onCommand);
HANDLE_MSG(hWnd, WM_SETCURSOR, onSetCursor);
HANDLE_MSG(hWnd, WM_GETDLGCODE, onGetDlgCode);
case WM_IME_COMPOSITION:
return onImeComposition(hWnd, wParam, lParam);
case WM_IME_CHAR:
return onImeChar(hWnd, wParam, lParam);
case WM_IME_STARTCOMPOSITION:
return 0;
case WM_MOUSEWHEEL:
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
void CTest::onPaint(HWND hWnd){
//OnPaint에 아래 코드가 없으면 LBUTTON 같은 곳에서 MessageBox() 출력시 메세지 박스 창이 숨어버린다.
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hWnd,&ps);
TCHAR tmp[100];
wsprintf(tmp, TEXT("hWnd: %d\n"), hWnd);
TextOut(hdc, 10, 10, tmp, lstrlen(tmp));
EndPaint(hWnd,&ps);
}
bool CTest::onCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct){return TRUE;}
void CTest::onDestroy(HWND hWnd){PostQuitMessage(0);}
void CTest::onSize(HWND hWnd, UINT state, int cx, int cy){}
void CTest::onKey(HWND hWnd, UINT vk, bool fDown, int cRepeat, UINT flags){}
void CTest::onSetFocus(HWND hWnd, HWND hwndOldFocus){}
void CTest::onKillFocus(HWND hWnd, HWND hwndNewFocus){}
void CTest::onHScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos){}
void CTest::onVScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos){}
void CTest::onContextMenu(HWND hWnd, HWND hwndContext, UINT xPos, UINT yPos){}
void CTest::onCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify){}
void CTest::onLButtonDown(HWND hWnd, bool fDoubleClick, int x, int y, UINT keyFlags){}
void CTest::onMouseMove(HWND hWnd, int x, int y, UINT keyFlags){}
void CTest::onLButtonUp(HWND hWnd, int x, int y, UINT keyFlags){}
void CTest::onTimer(HWND hWnd, UINT id){}
BOOL CTest::onSetCursor(HWND hWnd, HWND hwndCursor, UINT codeHitTest, UINT msg){return FORWARD_WM_SETCURSOR(hWnd,hwndCursor,codeHitTest,msg,DefWindowProc);}
UINT CTest::onGetDlgCode(HWND hWnd, LPMSG lpmsg){ return 0;}
void CTest::onChar(HWND hWnd, TCHAR ch, int cRepeat){}
LRESULT CTest::onImeComposition(HWND hWnd, WPARAM wParam, LPARAM lParam){return DefWindowProc(hWnd,WM_IME_COMPOSITION,wParam,lParam);}
LRESULT CTest::onImeChar(HWND hWnd, WPARAM wParam, LPARAM lParam){return 0;}
|
'C++' 카테고리의 다른 글
Random 난수 생성하기 (0) | 2010.10.13 |
---|---|
SOCKET (0) | 2010.10.09 |
Windows Thread 와 Synchronization(동기화) (0) | 2010.10.06 |
자료구조 (0) | 2010.09.30 |
VC++ 수행시간 체크 (1) | 2010.09.15 |
IME(Input Method Editor) (0) | 2010.09.11 |
C++ 포인터 및 레퍼런스 (0) | 2010.09.02 |
PE (portable executable) 파일 (0) | 2010.08.20 |