Lesson #4 we are going to take advantage of
hutch`s masm32 library (Thats the guy you downloaded the
Microsoft Macro MASM32 package from).
From the &File menu click &New Project and choose DialogAsMain.tpl as our new template.
Name the project "Program"
Create 2 editboxes and a button like on the screenshot. We will retrieve the programs
application path as well
as writing a line of text into a file using API WritePrivateProfileString and run an application (Notepad) by pressing
a button. We will also learn a new MACRO for SingleInstance only.
Now something very important: Click the Dialog and look at the property window. There is a line called CLASS.
At its property you read: DLGCLASS change this into MYCLASS. This is the first time we change our programs class.You should always do so to prevent collisions with other programs.
Set the 2 editboxes properties LOCKED to TRUE and AUTOSCROLL to HORIZONTAL. Set the Dialogs border to TOOL and the SIZEBORDER property to FALSE.
This will create a TOOLWINDOW for us. Dont forget to implement a nice icon again. If you would set SYSMENU to FALSE
you will see the closing button "x" will disappear on your TOOLWINDOW. So be sure you set SYSMENU to TRUE.
You can still shut the program down either pressing ALT+F4 or in the Taskmanager.
When your finished you have something like this:
Now first open your Program.inc file. We have to insert some lines there.
I wont explain anything again, that was already explained in the tutorials be4. OK ?
To take advantage of hutch`s masm32 library we have to implement it first to our project so the linker knows where
to get those 'functions' from.
Then we add our MACRO copy & paste following to you .inc file
SingleInstanceOnly MACRO lpClassName
cmp eax, 0
mov eax, 0
in the .data section please first change the line
ClassName db 'DLGCLASS',0
ClassName db'MYCLASS',0 ;(like we did in the dialog editor)
process db 'c:\Windows\notepad.exe',0
NOTE: Please edit the path of my process so it fits to your Notepad path. Or else it
In the .data? section add following lines
db 256 dup (?)
;the buffer to store our
;this is what we need to run other programs
processinfo PROCESS_INFORMATION <?>
startinfo STARTUPINFO <?>
We are done with the Program.inc file. You can close it. DONT FORGET TO ADD ALL CODE
FOR YOUR ICON,
EDITBOX AND BUTTON.AS I SAID I DID NOT EXPLAIN IT AGAIN - YOU SHOULD HAVE LEARNED THIS BY NOW.
Double click the Program.asm file now.
First we add our Previous Instance MACRO to our WinMain proc.
The line looks like this:
SingleInstanceOnly offset ClassName
Place this as the first line in the WinMainproc under the LOCAL variables. This MACRO
will look for an already existing window with the same ClassName and if it finds one it
closes the application and sets focus to the existing one.
We are done with the WinMain proc.
First we add a local variable for a textbuffer again.
Then we move to the WM_INITDIALOG
ADD YOUR CODE FOR RETRIEVING THE HANDLES OF YOUR EDITBOXES AND YOUR ICON.
invoke GetAppPath, offset AppPath
;Function from the
masm32 library to retrieve app.path
invoke SendMessage,hEdit1,WM_SETTEXT,0,offset AppPath
invoke lstrcat,offset AppPath,offset Settings ;we combine 2 strings with LSTRCAT API
invoke SendMessage,hEdit2,WM_SETTEXT,0,offset AppPath
invoke WritePrivateProfileString,offset AppName,offset ClassName,offset process,offset AppPath
;WIN API to write a line of text to an *.ini file
The button code to fire up the notepad is following:
invoke CreateProcess,offset process,0,0,0,0,CREATE_NEW_CONSOLE,0,0,offset startinfo, offset processinfo
The files for this example can be found here.