32-bit assembler in Windows C code-Chapter 5 (1)

Source: Internet
Author: User

(1) menu and acceleration key

 

# Include <windows. h> <br/> # include "Resource. h "</p> <p> TCHARszBuffer [128]; <br/> TCHARszClassName [] = TEXT (" Menu Example "); <br/> TCHARszCaptionMain [] = TEXT ("Menu"); <br/> TCHAR szCaption [] = TEXT ("Menu selection "); <br/> TCHARszMenuHelp [] = TEXT ("help topic (& H )"); <br/> TCHARszMenuAbout [] = TEXT ("about this program (& )... "); <br/> TCHARszFormat [] = TEXT (" you have selected the menu command: % 08x "); <br/> HWNDhMainWnd; <br/> HMENUhMenu; <br/> HMENUhSubMenu; <br/> HACCELhAccelerator; </p> <p> VOID DisplayMenuItem (DWORD dwCommandID) <br/>{< br/> wsprintf (szBuffer, szFormat, dwCommandID); <br/> MessageBox (hMainWnd, szBuffer, szCaption, MB_ OK); <br/>}</p> <p> VOID Quit () <br/>{< br/> DestroyWindow (hMainWnd); <br/> PostQuitMessage (0 ); <br/>}</p> <p> lresult callback ProcWinMain (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) <br/>{< br/> POINTstPt; <br/> HMENUhSysMenu; </p> <p> switch (uMsg) <br/> {<br/> case WM_CREATE: <br/> hSubMenu = GetSubMenu (hMenu, 1); <br/> hSysMenu = GetSystemMenu (hWnd, FALSE); <br/> AppendMenu (hSysMenu, MF_SEPARATOR, 0, NULL); <br/> AppendMenu (hSysMenu, 0, IDM_HELP, szMenuHelp); <br/> AppendMenu (hSysMenu, 0, IDM_ABOUT, szMenuAbout); <br/> return 0; </p> <p> case WM_COMMAND: <br/> DisplayMenuItem (wParam); <br/> switch (LOWORD (wParam) <br/>{< br/> case IDM_EXIT: <br/> Quit (); <br/> return 0; <br/> case IDM_TOOLBAR: <br/> case IDM_TOOLBARTEXT: <br/> case IDM_INPUTBAR: <br/> case IDM_STATUSBAR: <br/> if (MF_CHECKED = GetMenuState (hMenu, (UINT) wParam, MF_BYCOMMAND) <br/>{< br/> CheckMenuItem (hMenu, (UINT) wParam, MF_UNCHECKED); <br/>}< br/> else <br/>{< br/> CheckMenuItem (hMenu, (UINT) wParam, MF_CHECKED ); <br/>}< br/> return 0; <br/> case IDM_BIG: <br/> case IDM_SMALL: <br/> case IDM_LIST: <br/> case IDM_DETAIL: <br/> CheckMenuRadioItem (hMenu, IDM_BIG, IDM_DETAIL, LOWORD (wParam), MF_BYCOMMAND); <br/> return 0; <br/>}< br/> break; <br/> caseWM_SYSCOMMAND: <br/> switch (LOWORD (wParam) <br/>{< br/> caseIDM_HELP: <br/> caseIDM_ABOUT: <br/> DisplayMenuItem (wParam); <br/> return 0; <br/> default: <br/> return DefWindowProc (hWnd, uMsg, wParam, lParam ); <br/>}< br/> break; <br/> case WM_RBUTTONDOWN: <br/> GetCursorPos (& stPt); <br/> TrackPopupMenu (hSubMenu, TPM_LEFTALIGN, stPt. x, stPt. y, 0, hMainWnd, NULL); <br/> return 0; <br/> case WM_CLOSE: <br/> Quit (); <br/> return 0; <br/>}< br/> return DefWindowProc (hWnd, uMsg, wParam, lParam); <br/>}</p> <p> int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) <br/>{< br/> WNDCLASSEXstWndCls; <br/> msstmsg; </p> <p> RtlZeroMemory (& stWndCls, sizeof (stWndCls); <br/> stWndCls. hCursor = LoadCursor (NULL, IDC_ARROW); <br/> stWndCls. hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_MAIN); <br/> stWndCls. hIconSm = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_MAIN); <br/> stWndCls. cbWndExtra = 0; <br/> stWndCls. cbClsExtra = 0; <br/> stWndCls. hInstance = hInstance; <br/> stWndCls. cbSize = sizeof (WNDCLASSEX); <br/> stWndCls. style = CS_HREDRAW | CS_VREDRAW; <br/> stWndCls. lpfnWndProc = ProcWinMain; <br/> stWndCls. hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); <br/> stWndCls. lpszClassName = szClassName; <br/> stWndCls. lpszMenuName = NULL; </p> <p> RegisterClassEx (& stWndCls); </p> <p> hMenu = LoadMenu (hInstance, MAKEINTRESOURCE (IDM_MAIN )); <br/> hAccelerator = LoadAccelerators (hInstance, MAKEINTRESOURCE (IDA_ACCELERATOR); <br/> hMainWnd = createdomainwex (Region, szClassName, szCaptionMain, <br/> temperature, 100,100,600,400, NULL, hMenu, hInstance, NULL); </p> <p> ShowWindow (hMainWnd, SW_SHOWNORMAL); <br/> UpdateWindow (hMainWnd ); </p> <p> while (GetMessage (& stMsg, NULL, 0, 0) <br/> {<br/> if (0 = TranslateAccelerator (hMainWnd, hAccelerator, & stMsg) <br/>{< br/> TranslateMessage (& stMsg); <br/> DispatchMessage (& stMsg ); <br/>}< br/> return stMsg. wParam; <br/>}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.