Article 3 Use of menus, icons, and cursors

Source: Internet
Author: User

This blog will briefly introduce how to use menus, icons, and cursors in windows.

 

1. menus, icons, and cursors are defined as resources in the resource file.

1. Menu definition method:

Menu ID menu [discardable]

Begin

Menu item Definition

End

 

Menu item definition:

Define common menu items:

Menuitem menu text, command ID [, Option List]

Define the split line:

Menuitem Separator

Define the pop-up menu:

Popup menu text [, Option List]

Begin

Menu item Definition

End

 

2. Definition of icons and cursors

Icon ID icon [discardable] icon file name

Cursor ID cursor [discardable] Name of the cursor file

 

3. Note

The so-called xxid values are user-defined values in the range of 0 ~ 0 ffffh

Discardable is the memory option, indicating that the memory can be automatically released when not in use

 

4. Example

# Include <resource. h> // menu option # defineidm_main0x1000 # define idm_icohead0x2000 # authorization # defineidm_curhand0x2003 // icon # defineicon_head0x3000 # define icon_arrow0x3001 // cursor # cursor "arrow. ICO "icon_headicondiscardable" head. ICO "cur_handcursordiscardable" Hand. cur "idm_mainmenudiscardablebeginpopup" icon and cursor option (& C )... "beginmenuitem" avatar icon ", idm_icoheadmenuitem" arrow icon ", idm_icoarrowmenuitemseparatormenuitem" Dinosaur cursor ", idm_curdin#urmenuitem" Palm cursor ", idm_curhandendend

 

2. Use menus, icons, and cursor Resources in the main window Program

1. How to Create a window: the first window Program

 

2. Usage

① Use menu

First, load the menu (specified by the menu ID-IDM_MAIN) into the application after obtaining the module handle

invokeGetModuleHandle,NULLmovhInstance,eaxinvokeLoadMenu,hInstance,IDM_MAINmovhMenu,eax

Secondly, when a window is created, the menu handle hmenu is passed as a parameter.

invokeCreateWindowEx,WS_EX_CLIENTEDGE,\offset szClassName,offset szClassName,\WS_OVERLAPPEDWINDOW,\200,200,300,200,\NULL,hMenu,hInstance,NULL

② How to use the cursor and icon

When createdomainwex is called to create a window, the system sends a wm_create message to the window program before the function returns. We can

Load the cursor and Icon resource. Then call the sendmessage function to send the default icon and cursor type to the window program.

Sequential processing.

.ifeax == WM_CREATEinvokeLoadIcon,hInstance,ICON_HEADmovhIconHead,eaxinvokeLoadIcon,hInstance,ICON_ARROWmovhIconArrow,eaxinvokeLoadCursor,hInstance,CUR_HANDmovhCurHand,eaxinvokeLoadCursorFromFile,addr szCursorFilemovhCurDinosaur,eaxinvokeSendMessage,hWnd,WM_COMMAND,IDM_ICOHEAD,NULLinvokeSendMessage,hWnd,WM_COMMAND,IDM_CURHAND,NULL

 

3. Example

. 386. model flat, stdcalloption Casemap: nonedemodewindows. incincludeuser32.incincludelibuser32. libincludekernel32.incincludelibkernel32. LIB; Do not write the following equ definition as 0x ...; the definition of menu ID, icon_headequ3000hicon_arrowequ3001h, cur_handequ4000h, and handle. data? Hinstancedd? Hmenudd? Hwinmaindd? Hcurdin1_urdd? Hcurhanddd? Hiconheaddd? Hiconarrowdd ?. Constszcursorfiledb 'dinateur. wan', 0; dynamic cursor file stored on disk szclassnamedb' icon and cursor! ', 0. code_quitprocinvokedestroywindow, hwinmaininvokepostquitmessage, nullret_quitendp_winmainprocprocuses ebx edi esi hwnd, umsg, wparam, lparammoveax, umsg. ifeax = response, hinstance, response, response, ADDR response, eaxinvokesendmessage, hwnd, wm_command, idm_icohead, nullinvokesendmessage, hwnd, wm_command, idm_curhand, null. elseifeax = wm_commandmoveax, wparammovzxeax, ax. ifeax = idm_icohead; icon_big is the predefined invokesendmessage, hwnd, callback, icon_big, hiconhead cursor, hmenu, idm_icohead, idm_icoarrow, \ idm_icohead, cursor = idm_icoarrow; callback is the predefined invokesendmessage, hwnd, wm_seticon, forward, hiconarrow forward, hmenu, idm_icohead, idm_icoarrow, \ idm_icoarrow, forward = forward, hwnd, forward, bottom, hmenu, hour, idm_curhand, \ idm_curdin1_ur, hour = hour, hwnd, hour, hour, hmenu, idm_curdin1_ur, idm_curhand, \ idm_curhand, hour = hour, hwnd, umsg, wparam, lparamret. endifmoveax, Principal @ stwndclass: wndclassexlocal @ stmsg: Principal, nullmovhinstance, Principal, hinstance, idm_mainmovhmenu, Principal, ADDR @ stwndclass, sizeof @ stWndClasspushhInstancepop@stWndClass.hInstancemov @ stwndclass. cbsize, sizeof @ stWndClassmov@stWndClass.style, cs_hredraw or CS_VREDRAWmov@stWndClass.lpfnWndProc, offset _ WinMainProcmov@stWndClass.hbrBackground, color_window + 1mov@stWndClass.lpszClassName, offset primary, ADDR @ secondary, ws_ex_clientedge, \ offset szclassname, offset szclassname, \ ws_overlappedwindow, \ 200,200,300,200, \ null, hmenu, hinstance, nullmovhwinmain, eaxinvokeshowwindow, hwinmain, sw_shownormalinvokeupdatewindow, hwinmain. whiletrueinvokegetmessage, ADDR @ stmsg, null, 0, 0. break. ifeax = 0 invoketranslatemessage, ADDR @ stmsginvokedispatchmessage, ADDR @ stmsg. endwret_winmainendpstart: invoke_winmaininvokeexitprocess, nullendstart

3. Download icons and cursor files in the code

Icon and cursor file

 

4. Examples of this blog

After the program is running, select a project in the menu to view the icon and cursor changes.

 

 

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.