July 21st, 2008

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

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.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.