Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Fun starts Tomorrow :How to make a Dialogbox with Icon ,Menu in Winasm.


  • Please log in to reply
No replies to this topic

#1 gokuajmes

gokuajmes

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 02 April 2010 - 02:34 AM

New Concepts:
Adding an icon and menus to a dialog box
Using windows styles
Using a manifest to apply XP Visual Style to controls


New API functions:
LoadIcon
GetDlgItem
SetFocus
GetDlgItemText



We will build on the last example by adding an icon, a menu and some code to display text typed into the edit box in a message box. We will also start with the cursor in the editbox.



First create a new WinAsm project and add a new rc file. Turn off visual mode (F12) then paste in dialogbox1.rc from the last project. Now turn visual mode back on and click the resources tab in the explorer bar. First highlight the dialog box and doubleclick caption to change it to "Dialog Box with Icon & Menu".


Now we want to add a menu called "Menu" with 4 items; "Get Text", "Clear Text", a separator, and "Exit":


1. Click the second toolbar button in the explorer bar (New Menu) and enter "MyMenu" in the menu name and for the first menu item enter "Menu" in the Caption box, clear the Name box and click insert.


2. For the next menu item enter the Caption "Get Text", the Name "IDM_GETTEXT", click the yellow arrow pointing right and then Insert:


pic2..png



Now add 3 more menu items for Clear Text, a separator (type a "-" in the Caption box and clear the Name box) and Exit and indent them with the yellow arrows. Finally click OK:


pic3..png

Next we will tell the dialog box to use our menu and change the dialog style:


1. Click OK then click Dialogs in the explorer bar and highlight IDD_DLG1001. Click in the menu field and select "MyMenu".


2. Click in the Style field and doubleclick DS_CENTER followed by OK. This will make our dialog box appear in the centre of the screen rather than top left. Many of these settings are useful, eg turning off WS_SIZEBOX prevents our dialog box being resized which would make it look a little odd.

pic5..png

Next we will add an ico.Click on the penultimate button in the explorer bar, click add and navigate to your icon. Fill in a Name and ID by doubleclicking the fields then click OK:

pic6..png

Finally turn off visual mode to see the script. New parts are boxed in red. If any of the new control IDs are duplicates change them now - they must all be unique (boxed in green):

pic7..png

Save your new resource script as dialogbox2.rc and now we will see what code has been added to use these resources. Click on the project explorer, select Untitled1.asm and paste in the code from dialogbox2.asm. As you can see not much has changed apart from some new variables:

pic8..png

and the dialog procedure is processing messages from the menu:

pic9..png

Go All should give you this:

pic10..png

Now we will analyse the code.

Variables
New variables include the Caption string for our messagebox, buffer - an uninitialized array of 512 bytes to receive text from the editbox into, and the control IDs of the menu items and icon.

The Dialog Procedure
The first message our dialog procedure receives from Windows is WM_INITDIALOG. If we process it with our dialog procedure we can put any initialization code here.

LoadIcon - loads the specified icon resource from the executable and returns its handle in eax. The WM_SETICON message instructs the dialog procedure to associate the icon with the specified handle to the dialog box.

GetDlgItem - finds the handle of the specified control (the editbox here) and returns it in eax.

SetFocus - forces input focus to the control with the specified handle (again the editbox here so the user can type text into it immediately).

The following lines of code process WM_COMMAND messages as before. Besides coming from child window controls these are now generated if the user has chosen a menu item. If you happen to use the same ID codes for menus and child window controls, you can differentiate between them by examining the value of lParam, which will be 0 for a menu item:

pic11..png

If lParam is zero, the current WM_COMMAND message is from a menu. You cannot use wParam to differentiate between a menu and a control since the menu ID and control ID may be identical and the notification code may be zero.

In our case we have different IDs so we can process all the messages in the same loop without having to screen out all those with a zero lParam in a second IF loop. We will revisit the concept of spliting the high and low order words of messages to get the notification code in the custom key generation tutorial

The only new function we have used is GetDlgItemText:

pic12..png

Using XP Visual Style

You may notice that although the button outlines in WinAsm Resource editor have rounded corners in the XP style, the compiled executable displays the old style square cornered buttons. In order to use the new XP Visual Style with the common controls you must use a manifest file. This is a standard xml (extensible markup language) file which needs to be edited only to include the name of your app. The name of the xml file itself can be anything. It should be placed in the same folder as the source files and is specified by a single line in the resource script.

The manifest can be added to the project by clicking the Resources tab in the project explorer bar, clicking Resources then Add, and adding the manifest file. A resource name is not necessary but the ID for the manifest must always be 1 or it will not work:

pic13..png

This adds the following line to the resource script just below the icon line (which could be done manually):


1 24 DISCARDABLE "dialogbox2.xml"
Finally save dialogbox2.rc again and it should match the version in the sourcecode section. Now on recompiling you should see this:

pic14..png

Note the rounded buttons with the bluish outline. The manifest file is also included in the sourcecodes section. Just for reference the contents are as follows:

pic15..png

SourceCode Section :

dialogbox2.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<assembly     xmlns="urn:schemas-microsoft-com:asm.v1"     manifestVersion="1.0"> 
<assemblyIdentity      processorArchitecture="x86"      version="5.1.0.0"     type="win32" name="dialogbox2.exe"/> 
    <description>Mx XP Program</description>     
<dependency>     <dependentAssembly>     
<assemblyIdentity          type="win32"          name="Microsoft.Windows.Common-Controls"          version="6.0.0.0"          publicKeyToken="6595b64144ccf1df"          language="*"          processorArchitecture="x86"/>     </dependentAssembly>     </dependency> </assembly>



In the FUN section ,
Disclaimer :


lets see How to make a custom " Keygen " .What ? yes a keygen. I ain't a stupid to give
you all the hints and knowledge to make one of your own.It's against the law and forum rules.

This keygen which i will make , DOES NOT mod any commercial protection scheme ! so the
forum and moderator and members don't get jailed ,their systems will not be confiscated
.
This is after all just a program that behaves like a keygeneration application.Just a name reverser application
in Assembly Language.The template is going to be of type " Keygen ",
great then lets wait till i finish the tutorial.


Attached Thumbnails

  • pic4..png
  • pic1..png

  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download