News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

First GUI Attempt

Started by tbohon, May 04, 2010, 02:04:53 AM

Previous topic - Next topic

tbohon

Although I've written programs in assembler (MASM and TASM) in the past, I've never done a GUI-based program so today I watched a couple of YouTube videos, read some information on Windows programming and came up with the code below.  The GUI - built with EasyCode MASM - has an edit box and two buttons.  Button1 is supposed to simply place a predefined message in the edit box and, once I figure out how to do it, button2 will terminate the application.

Nothing happens when I click on button1 and none of the messagebox commands appear to be executed either as none of them appear on the screen.

I'm sure that I'm going to be mortified  :red when I find out what I'm doing wrong but can anyone point me in the right direction?  I"ve spent a lot of time on this today and am simply going around in circles.

Thanks in advance.

Tom


.Const

.Data?
Edit1 HANDLE ?

.Data
msg1 DB "This is the first message", 0
msg2 DB "And this is the second message", 0
TitleMsg DB "MB Title", 0

.Code

Window1Procedure Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM

.If uMsg == WM_CREATE
Invoke GetWindowItem, hWnd, IDC_WINDOW1EDIT1
Move Edit1, Eax
Invoke MessageBox, hWnd, Addr Edit1, Addr TitleMsg, MB_OK

.ElseIf uMsg == WM_COMMAND
LoWord wParam
.If Ax == IDC_WINDOW1BUTTON1
HiWord wParam
.If Ax == BN_CLICKED
Invoke MessageBox, NULL, Addr msg1, Addr TitleMsg, MB_OK
Invoke SetText, Edit1, Addr msg1
Invoke DoEvents
.EndIf
.EndIf

.ElseIf uMsg == WM_CLOSE
Invoke IsModal, hWnd
.If Eax
Invoke EndModal, hWnd, IDCANCEL
Return TRUE
.EndIf
.EndIf
Return FALSE
Window1Procedure EndP


joemc

Looks like a good first attempt. There are a few simple to fix issues. GUI programing is a little different than console programing because it uses callback procedures, which you have written one. But your program needs to dispatch messages to it and also needs an entry point that creates your first window.  A lot of things are referred to as a "windows". if it is an edit or a button it is based on a predefined window.

and i am going to stop here because i was rereading through your post.  You are having a window show up? you must have a entry point or more code somewhere, or maybe EasyCode is generating it for you. I have never used it before...  i will leave you some links though, and if there is more to your code go ahead and post it.

although not in MASM, http://winprog.org/  shows the basics, most if it is function calls anyway, so if you are already experienced with asm you should be ok converting it.
and the most refer to site i have probably seen http://win32assembly.online.fr/ is in masm.

and one quick note on your proc

try changing the end to :

.Else
Return FALSE
   .endif
   return TRUE
Window1Procedure EndP


and WM_CREATE to WM_INITDIALOG and RETURN TRUE
from it.

I personally prefer window procedures over dialog procedures, especially as a beginner, i would try following some of the tutorials i linked to above.

tbohon

Once I put out a fire or two (or three or ...) at work this morning I'll give these changes a shot.

And thanks for the links ... great sites!!!

Tom