views:

362

answers:

6

I have the following unmanaged C++ code:

MessageBox( NULL, strMessage, "Cool Product", MB_RETRYCANCEL | MB_ICONEXCLAMATION);

I want to disable the RETRY button for 10 seconds (for example), then enable it.

How can I do this?

A: 

With the standard MessageBox call, you can't. You'd need to implement your own MessageBox in order to do this.

Jeff Yates
A: 

I don't believe this is possible with the standard message box call.

You would probably be better off writing your own message box that includes this functionality.

(Or, you could write a separate thread that continually watches the screen waiting for that message box to appear, disable the retry button, wait 10 seconds and reenable it. Not fun. Seriously, do it the other way.)

BoltBait
+1  A: 

Like @ffpf says, you need to make your own dialog to do this, using MFC, ATL, raw Win32, etc.

Then create a timer that would enable and disable the button.

crashmstr
A: 

Since Vista you can use taskdialog -- a more sophisticated dialog than a simple message box. More info and links here.

Kasprzol
And even without Vista, a task dialog is a much better approach than a message box. There are some implementation that work on pre-Vista systems and it isn't that hard to implement either, if you don't need all features at once.
OregonGhost
It does not look like you could actually enable and disable the buttons, only (potentially) add and remove.
crashmstr
+1  A: 

You cannot directly manipulate the MessageBox controls, but you can use a hack. Install a WH_CBT hook just before displaying the dialog and handle the HCBT_ACTIVATE event. This will give you the HWND of the message box, so that you can do whatever you want with it (subclass it, manage its buttons and set a timer).

You can find a Custom MessageBox tutorial with demo code in James Brown's site.

efotinis
A: 

I agree with efotinis, it's not impossible, once you have the HWND you can do whatever you want with it. It is just a matter of "do you really need the hacks or are you better off with just creating your own message box dialog"?

Another not so nice way of finding the HWND (which would obviously give you access to eveything in the message box) would be to start a thread and ciclically poll for the message box handle by using EnumChildWindows. But I personally would prefer the WH_CBT hook also.

Dan Cristoloveanu