Changing the font size of Message Box

Posted on 1998-09-23
Last Modified: 2013-12-03
I'm working on a large VB app. Is there an API call that will allow me to change the font size (as I can in Control Panel) of the message box used by MsgBox()?

I cannot implement a form in place of MsgBox() for the following reasons:

- This is an MDI application.
- I sometimes need to show 2 msgboxes in sequence.
- I need them both to be system modal

If I need to create a custom dialog box resource, can someone provide sample code for the necessary window procedure?

Thanks very much.
Question by:cdickerson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1

Expert Comment

ID: 1414706
Windows does the formatting. (MsgBox corresponds to the MessageBox API call)

If you change the font, you change it for all messages boxes not just the ones in your app.  This is a very unfriendly way for you app to behave, so I wouldn't recommend it (basically you can change the system settings to do this).

A good work round is to create a form and use that instead of the built-in Message box.
1. Pass the form the title & text you want.
2. Put these in text fields
3. Pass the icon you want to the form, but this in a picture box.
4. Pass the buttons you want (you can also add the capability to use other text than windows allows, which is a good reason for doing this in itself)

Some MS apps do this too.

Finally you may also want to do this, as you can do thinks like add your own scroll bar for really long messages with a form (which you can't do with the standard message box).

Author Comment

ID: 1414707
In my message I explained why I *can't* use a form.

I cannot make more than one form in a MDI app modal. If 2 error messages pop up in sequence, only 1 will be modal, while the other goes into the background, waiting for input.

I understand changing the setting affects everything, which is why I'd intended to undo the change immediately after the call to MsgBox.

Expert Comment

ID: 1414708
Sorry I don't understand why you can't simply display the second form after the first one has finished - could you explain why this doesn't work for you ?
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.


Author Comment

ID: 1414709
Perhaps I can and just know how. One form is fired off by an error routine, another is fired off by an event. That sort of thing happens all over the app, and there's really no way of getting around it in the timeframe we have.

Expert Comment

ID: 1414710
if that is happening, how is the MessageBox dealing with that?
LVL 11

Expert Comment

ID: 1414711
Like most VB programmers, you're facing a limitation of the development environment and you need to find a workaround.

You can create a DLL in C or C++ that will hook creation of message boxes your app posts. You can have that hook change the font used by the controls and text in the message box.

Or, you can investigate more carefully managing modality in your application. If you need to pop up a second error message, then your first window isn't truly modal anyway--you're still doing processing!  You can avoid the focus and input problems you describe by disabling the windows that are going into the background. Just set their "enabled" properties to FALSE.

B ekiM


Author Comment

ID: 1414712
I realize I can write a DLL, which is why I asked for sample code for the window procedure.

I also know this is a bad design to begin with, but we really don't have the timeframe to change it. This is a conversion project (from an OS/2 language), and the delivery date did not take into account that a line-for-line conversion might not be acceptable (typical!).

We're pretty close to a workaround.
LVL 11

Accepted Solution

mikeblas earned 50 total points
ID: 1414713
Uh, I guess you didn't read my answer all the way, or at least didn't understand it.

I'm suggesting that you write a DLL with a hook--which won't require a window procedure. You suggesting that you'd create a custom dialog box, which would need a window procedure.

Your window procedure would do next to nothing:

BOOL CALLBACK MyDialogProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
   BOOL bRet = FALSE;
   switch (uMessage)
      case WM_INITDIALOG:
         bRet = TRUE;

   return bRet;

and that's that.  If you need something more specific, you have to indicate which controls you'll have on the box and what you'll want those controls to do for you at runtime.

B ekiM


Author Comment

ID: 1414714
I think the latter of your first statement is true.

What would the hook look like? (Remember I mentioned I have no experience with MFC).

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (, we saw how to put the Delete button back there where it belongs.  "Delete" is …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question