MessageBoxIndirect loads the icon itself; you can’t hand it a pre-loaded icon

Raymond Chen

Commenter 8 wants to know how to tell the MessageBoxIndirect function to use an existing HICON instead of pointing it to an icon resource.

You can’t.

The MessageBoxIndirect loads the icon itself. You can’t hand it a pre-loaded icon.

Of course, it’s hardly rocket science to write your own MessageBoxWithMyIcon function that lets you use whatever icon you want. There’s no law that says all Yes/No dialogs must use the MessageBox function. Feel free to write your own.

The MessageBox and MessageBoxIndirect functions are just convenience functions. They don’t create new functionality; they don’t do anything you couldn’t already do yourself. You can have a template dialog box that you use for “generic” purposes and set the icon and text yourself. Or, if you’re really adventuresome, you can generate a dialog template on the fly.

The MessageBox and MessageBoxIndirect functions never aspired to be “everything anybody could ever do with a dialog box.” They just provide some basic functionality that lots of people find useful. If you need more functionality, then you can always write it yourself. (There’s already a function for “everything anybody could ever do with a standard Win32 dialog box”: It’s called, um, DialogBox.)

Windows Vista introduces a considerably more customizable “message box”-type dialog known as a Task Dialog; you may want to give that one a try.


Discussion is closed.

Feedback usabilla icon