The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: herge on October 01, 2008, 07:05:19 AM

Title: Cancel Button (X)
Post by: herge on October 01, 2008, 07:05:19 AM

Hi There:

I am trying to get the X button to work.
So I don't have to press ok a hundred
times.



      invoke MessageBox, NULL, addr dtbuf, addr AppName, MB_OK
      cmp  dword ptr [esp+2*4],  MB_OK
      jz    Exit
Skip:     
      pop   esi
      add   esi, 4
      pop   ecx
      jmp   Next

Exit:



Any suggestions please.

Regards herge
Title: Re: Cancel Button (X)
Post by: donkey on October 01, 2008, 07:55:37 AM
You can use MB_OKCANCEL and create a messagebox with a cancel button on it, then test the return value for either IDOK or IDCANCEL(1 and 2 respectively). The close button [X] returns 1 so it is the same as IDOK when only an OK button is used, when a Cancel button is added the return value from the close button is 2 (Cancel)
Title: Re: Cancel Button (X)
Post by: herge on October 01, 2008, 08:11:05 AM

Hi donkey:

Thanks.

Houston We Have Lift Off!


      invoke MessageBox, NULL, addr dtbuf, addr AppName, MB_OKCANCEL
      cmp  eax, 2
      jz    Exit



I was getting tired of hitting ok a hundred times or
rearranging the data. This will save my fingers.
I will have to make a proper window but I think
we will leave that for another day.

Regards herge
Title: Re: Cancel Button (X)
Post by: kero on October 01, 2008, 11:09:47 AM
donkey:
>The close button [X] returns 1 so it is the same as IDOK when only an OK button is used, when a Cancel button is added the return value from the close button is 2 (Cancel)

Info from WinXP-pro-sp2:
1) close button [X] returns 2 (IDCANCEL) always,
2) "when only an OK button is used" => id(OK button)=IDCANCEL
Title: Re: Cancel Button (X)
Post by: donkey on October 01, 2008, 12:29:40 PM
Quote from: kero on October 01, 2008, 11:09:47 AM
donkey:
>The close button [X] returns 1 so it is the same as IDOK when only an OK button is used, when a Cancel button is added the return value from the close button is 2 (Cancel)

Info from WinXP-pro-sp2:
1) close button [X] returns 2 (IDCANCEL) always,
2) "when only an OK button is used" => id(OK button)=IDCANCEL

Could possibly be, I wasn't aware that it would change from version to version but in XPSP3 it is definitely as I stated above, I just tested it.
Title: Re: Cancel Button (X)
Post by: kero on October 01, 2008, 01:59:11 PM
>I wasn't aware that it would change from version to version but in XPSP3 it is definitely as I stated above, I just tested it.

Yes, strange MessageBox feature... Then - please, 2 questions more about Message Boxes on XPSP3:

1) GetWindowLong(hWndMsgBox,GWL_USERDATA) == 0 or not ? (sp2 => !=0)

2) PostMessage(hWndMsgBox,WM_TIMER,0,0) == PostMessage(hWndMsgBox,WM_CLOSE,0,0) or not ?  (sp2 => ==)
  (see http://www.masm32.com/board/index.php?topic=9864.0)
Title: Re: Cancel Button (X)
Post by: donkey on October 01, 2008, 02:12:28 PM
Hi Kero,

Since Messageboxes are modal by nature I would have to set up a threaded test application in order to send it messages, something I don't have the time for this morning but may take a look at after work, or I might just create one and send the messages from a seperate process or WinSpy, should work as well.