(Translation) Win32ASM instance -5

zhaozj2021-02-16  46

5.0 - Adding a menu Add menu

Our Program SHOULD HAVE A MENU TO SET SOME OPTIONS. FIRSTLY WE NEED TO CREATE OUR MENU IN The Resource File:

Our program should have a menu to set some options. First, we need to create our menu in the resource file.

5.1 - CREANG A MENU Creating a menu

A menu is fairly easy to make in your resource file. If you take a look at the resource text below you will see it's self explaining. Popup menus are menus that have submenus, a menuitem is just a menuitem with an associated ID. These IDs .

In your resource file, you can easily create a menu. If you look at the resource text below, you will see it is what it is clear. Popup (popup) menu is a menu with a submenu, and a menu item is only a menu item with associated ID. These IDs will be defined and can be used for your program to find which menu items of the user clicks. Finally, the current will undertake the first letter, indicating that it can use shortcuts.

Add this Below the icon definitions:

Add the following icon definition:

MAINMENU MENU DISCARDABLEBEGIN POPUP "& File" BEGIN MENUITEM "& New Game", MI_NEWGAME MENUITEM "& Open Bitmap", MI_OPENBITMAP POPUP "& Difficulty" BEGIN MENUITEM "& Easy", MI_EASY MENUITEM "& Medium", MI_MEDIUM MENUITEM "& Hard", MI_HARD END END POPUP "& Picture "BEGIN MENUITEM" Use & standard picture ", MI_USESTANDARD MENUITEM" Use & numbers ", MI_USENUMBERS MENUITEM" Use & bitmap file ", MI_USEFILE END POPUP" & Colors "BEGIN MENUITEM" & Blue color scheme ", MI_COLORBLUE MENUITEM" & Red color scheme ", MI_COLORRED MENUITEM" & Green Color Scheme, MI_COLORGREEN MENUITEM "& UGLY Color Scheme", MI_COLORUGLY End Popup "& Help" Begin MenuItem "& About", MI_ABOUT EndEnddd this Below The icon defines (Before The Code Above!):

Add the following menu item definition (before the previous code!)

#define MAINMENU 301 # define MI_NEWGAME 101 # define MI_OPENBITMAP 102 # define MI_EASY 103 # define MI_MEDIUM 104 # define MI_HARD 105 # define MI_USESTANDARD 106 # define MI_USENUMBERS 107 # define MI_USEFILE 108 # define MI_COLORBLUE 109 # define MI_COLORRED 110 # define MI_COLORGREEN 111 # define MI_COLORUGLY 112 # Define MI_ABOUT 113

5.2 - Defining The IDS Definition ID

Now You'll Have To Convert The C Definitions To ASM Equates: Now we must translate C definition to ASM:

MAINMENU equ 301MI_NEWGAME equ 101MI_OPENBITMAP equ 102MI_EASY equ 103MI_MEDIUM equ 104MI_HARD equ 105MI_USESTANDARD equ 106MI_USENUMBERS equ 107MI_USEFILE equ 108MI_COLORBLUE equ 109MI_COLORRED equ 110MI_COLORGREEN equ 111MI_COLORUGLY equ 112MI_ABOUT equ 113

When You've Converted Them, Place Them in Mosaic.inc.

After you translate them, put them in Mosaic.inc.

The Resource File and Mosaic Inc Should Now Look Like this: Res1.zip

Resources and Mosaic.inc files should be like this: res1.zip

5.3 - Adding the menu to your window Add your window to your window

[in Your .Data? Section]

[In your.data? Part] HMENU DD? [In Your .code section]

[.Code in your part] ...... invoke RegisterClassEx, addr wc; AFTER THIS LINE invoke LoadMenu, hInstance, MAINMENU;! Load menu mov hMenu, eax; store handle INVOKE CreateWindowEx, NULL, ADDR ClassName, ADDR AppName , / WS_OVERLAPPEDWINDOW-WS_MAXIMIZEBOX-WS_SIZEBOX, / CW_USEDEFAULT, CW_USEDEFAULT, 258,350, NULL, hMenu, /; !!!! hInst, NULL; NOTE: notice addition of the hMenu parameter; in the CreateWindowEx call .......

The hMenu is added to the uninitialized data section to hold the menu handle when it's loaded. LoadMenu will load a menu resource from the instance hInstance (mosaic.exe) with a certain ID (MAINMENU). The handle is stored with 'mov hMenu, EAX ', THE HANDLE IS Passed to CreateWindowEx to create a window with a menu. after You Have Run Make.bat You Should Have A Main WINDOW WITH A MENU (That Does Nothing):

HMENU is added to save the menu handle after the menu is loaded. LoadMenu will use an ID (MAIC.exe) to load the menu in a MAINMENU. The handle is saved with 'MOV HMENU, EAX', and then the handle is passed to CREATEWINDOWEX to create a window with a menu. After you run make.bat, you should have a main window with men (it's nothing): Your Source File Should Look Like this now: Mosaic.asm

Now your resource file should be like this: Mosaic.asm

转载请注明原文地址:https://www.9cbs.com/read-26617.html

New Post(0)