ssihc0@163.com 窗体资源 菜单 源代码 //----头文件------------------------------------------------------------------ // Generic defines and data types // #define dim(x) (sizeof(x) / sizeof(x[0])) struct decodeUINT { // Structure associates UINT Code; // messages LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM); // with a function. }; struct decodeCMD { // Structure associates UINT Code; // menu IDs with a LRESULT (*Fxn)(HWND, WORD, HWND, WORD); // function. }; //Window menu function // Window procedures LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM); LRESULT DoCreateMain (HWND, UINT, WPARAM, LPARAM); LRESULT DoDestroyMain (HWND, UINT, WPARAM, LPARAM); LRESULT DoCommandMain(HWND, UINT, WPARAM, LPARAM); LRESULT DoInitdialogMain(HWND, UINT, WPARAM, LPARAM); LRESULT ONIDOKMain (HWND, WORD, HWND, WORD); #include <WINDOWS.H> #include "emessage.h" #include <aygshell.h> #include "resource.h" #include <commctrl.h> //---------------------------------------------------------------------- //全局变量 // const TCHAR szAppName[] = TEXT ("EMessage"); HINSTANCE hInst; // Program instance handle SHINITDLGINFO shidi = {0}; SHMENUBARINFO shmbi = {0}; // Message dispatch table for MainWindowProc const struct decodeUINT MainMessages[] = { WM_CREATE,DoCreateMain, WM_DESTROY,DoDestroyMain, WM_COMMAND,DoCommandMain, WM_INITDIALOG,DoInitdialogMain, }; const struct decodeCMD MainCommandItems[]={ ID_DSDLDF,ONIDOKMain, IDOK,ONIDOKMain, }; int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow) { hInst = hInstance; SHInitExtraControls(); // just call a dialog box, system will handle messaging, painting, etc... DialogBox(hInstance,(LPCTSTR)IDD_NOTIFYMAIN, NULL,(DLGPROC)MainWndProc); return 0; } //---------------------------------------------------------------------- // MainWndProc - Callback function for application window // LRESULT CALLBACK MainWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,LPARAM lParam) { INT i; for (i = 0; i < dim(MainMessages); i++) { if (wMsg == MainMessages[i].Code) return (*MainMessages[i].Fxn)(hWnd, wMsg, wParam, lParam); } return DefWindowProc (hWnd, wMsg, wParam, lParam); } LRESULT DoInitdialogMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { //生成工具栏 shidi.dwMask = SHIDIM_FLAGS; shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIZEDLGFULLSCREEN; shidi.hDlg = hWnd; SHInitDialog(&shidi); //生成菜单 SHMENUBARINFO mbi; memset(&mbi, 0, sizeof(SHMENUBARINFO)); mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = hWnd; mbi.nToolBarId =IDR_MENU1; mbi.dwFlags = SHCMBF_HMENU | SHCMBF_HIDESIPBUTTON; mbi.hInstRes = hInst; mbi.nBmpId = 0; mbi.cBmpImages = 0; SHCreateMenuBar(&mbi); return 0; } LRESULT DoCreateMain (HWND hWnd, UINT wMsg, WPARAM wParam,LPARAM lParam) { return 0; } LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { PostQuitMessage (0); return 0; } LRESULT DoCommandMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { WORD idItem, wNotifyCode; HWND hwndCtl; INT i; // Parse the parameters. idItem = (WORD) LOWORD (wParam); wNotifyCode = (WORD) HIWORD (wParam); hwndCtl = (HWND) lParam; // Call routine to handle control message. for (i = 0; i < dim(MainCommandItems); i++) { if (idItem == MainCommandItems[i].Code) return (*MainCommandItems[i].Fxn)(hWnd, idItem, hwndCtl, wNotifyCode); } return 0; } LRESULT ONIDOKMain (HWND hWnd, WORD wMsg, HWND wParam, WORD lParam) { EndDialog(hWnd, LOWORD(wParam)); return 0; }