The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: G`HOST on September 28, 2005, 06:45:01 PM

Title: About Message Box
Post by: G`HOST on September 28, 2005, 06:45:01 PM
Is this the correct way to do it .I am just a noob ::) and have just started win32 ASM

.DATA?
ErrorMessage DWORD ?


invoke MessageBox,hWnd,ADDR PexitBoxTxt,ADDR PexitBoxCap,MB_YESNO
mov errorMessage,eax
.IF errorMessage==IDYES
invoke DestroyWindow,hWnd
.ENDIF
Title: Re: About Message Box
Post by: diablo2oo2 on September 28, 2005, 07:23:37 PM
did you try to compile it? dont understand why you ask...

only one or two things i would mention is that you can skip the var "errormessage"

just:

.if eax==IDYES
...
.endif


also i like to use chr$ macro

invoke MessageBox,hWnd,chr$("some text"),chr$("more text here"),MB_YESNO

Title: Re: About Message Box
Post by: hutch-- on September 28, 2005, 10:41:46 PM
Ghost,

What you are doing looks OK and its good sense to learn the manual code before you try out the higher level stuff that MASM32 supports. If you are happy with the results and it works as expected, you can try out some of the higher level stuff.


    cmp rv(MessageBox,hWnd,"Message Text","Caption",MB_YESNO), IDYES
    jne @F
    invoke DestroyWindow,hWnd
  @@:


This code does exactly the same thing but its a bit more compact. If you fully expanded it, it would look someting like this,


    push MB_YESNO
    push OFFSET caption
    push OFFSET Text
    push hWnd
    call MessageBox
    cmp eax, IDYES
    jne @F

    push hWnd
    call DestroyWindow

  @@:




The important thing is to understand what you are doing with the code and once you feel comfortable with it you can start using more compact and more easily readable forms.
Title: Re:MessageBox
Post by: G`HOST on September 29, 2005, 06:57:02 PM
THANX diablo2oo2 and Hutch  i wil improve. :dance:
Title: Re: About Message Box
Post by: diablo2oo2 on September 30, 2005, 06:13:13 PM
Quotecmp rv(MessageBox,hWnd,"Message Text","Caption",MB_YESNO), IDYES
    jne @F
    invoke DestroyWindow,hWnd
  @@:

thanks hutch, i didnt know the rv macro before. its also nice that it can be used with the .if macro...
i like it more than the jumps (the code look has a better structure and is easy to read)

.if rv(MessageBox,hWnd,"Message Text","Caption",MB_YESNO) == IDYES
invoke DestroyWindow,hWnd
.endif