//=============================================================== // first.h 文件
// 避免头文件的重复包含 #ifndef _CHUYUNFENG_FIRST_H_ #define _CHUYUNFENG_FIRST_H_
// 计算需要处理的消息数目 #define MSG_NUM(x) (sizeof(x) / sizeof(x[0]))
// 整个程序的消息映射结构 typedef struct tagMSG_MAP_MAIN { UINT nMsg; LRESULT (*pMsgProcess)(HWND, UINT, WPARAM, LPARAM);
}MSG_MAP_MAIN_S;
// 命令消息(WM_COMMAND)的消息映射结构,因为两者处理函数 // 的参数不同,调用场合也不同,因此这里需要单独建立,类似的有 // WM_NOTOFY消息,本程序中不涉及 typedef struct tagMSG_MAP_CMD { UINT nMsg; LRESULT (*pMsgProcess)(HWND, WORD, HWND, WORD);
}MSG_MAP_CMD_S;
// 声明程序中用到的全局变量 extern const TCHAR g_szAppName[]; extern HINSTANCE g_hInstance; extern HWND g_hMainWnd; extern const MSG_MAP_MAIN_S g_mainMsg[]; extern const MSG_MAP_CMD_S g_cmdMsg[];
// 窗口处理函数原型 LRESULT CALLBACK mainWndProc(HWND, UINT, WPARAM, LPARAM);
// 需要处理的主框架消息定义函数 LRESULT onCreate(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam); LRESULT onPaint(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam); LRESULT onCommand(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam); LRESULT onDestroy(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
// 需要处理的菜单命令消息定义函数 LRESULT onAbout(HWND hWnd, WORD idItem, HWND hwndCtl,WORD wNotifyCode); LRESULT onExit(HWND hWnd, WORD idItem, HWND hwndCtl,WORD wNotifyCode);
#endif //_CHUYUNFENG_FIRST_H_
//================================================================= // First.cpp 文件
#include <windows.h> #include <windowsx.h> #include <aygshell.h> #include "resource.h"
#include "First.h"
// 定义程序中用到的全局变量 const TCHAR g_szAppName[] = _T("First"); HINSTANCE g_hInstance; HWND g_hMainWnd;
// 程序中需要处理的消息映射,如果要增加,在此处增加一 // 对{msgID,onMsgProcFun},然后写对应的消息处理函数即可。 const MSG_MAP_MAIN_S g_mainMsg[] = { {WM_PAINT, onPaint}, {WM_COMMAND, onCommand}, {WM_CREATE, onCreate}, {WM_DESTROY, onDestroy} };
//此处放置需要处理的命令消息 const MSG_MAP_CMD_S g_cmdMsg[] = { {IDM_ABOUT, onAbout}, {IDM_EXIT,onExit} };
//================================================================= // WinMain,入口函数,由操作系统调用 //================================================================= int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { WNDCLASS wc; MSG msg;
// 注册窗口类 wc.style = 0; // 窗口样式
上一篇:OO in C(4): C语言中的面向对象思想(1)
下一篇:三大编程语言性能PK:Java, C/C++和Ruby
|