Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to enlarge font in MessageBox()? 3

Status
Not open for further replies.

jhall251

Programmer
Dec 7, 2000
84
US
Is there a way to control font size in the MessageBox() function? I know there is an FAQ that substitutes your own form and I assume font is controllable there. Is the font in the native function changeable?

Thanks....

Joe Halloran
 
jhall251

This is part of your Windows settings.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Pardon my ignorance...So to change that font I would need to change the desktop settings, probably affecting other things in other programs? This would be a good reason to use your message form class?

Thanks.

Joe Halloran
 
jhall251

Pardon my ignorance...So to change that font I would need to change the desktop settings, probably affecting other things in other programs? This would be a good reason to use your message form class?

That is correct. Even the API MessageBox() uses the Windows Default font.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks Mike -

yes I think I will as soon as I get a minute <s> - the font is just too small in MessageBox(). It looks like Mike Gagnon has some code in the FAQ for this purpose and Steven Black has a MsgSvc program that also looks promising - so there are models to build on.

Joe Halloran
 
Joe,

Also, there was an article in Foxpro Advisor, Feb 2004, on this subject (including some relevant APIs). You might want to take a look (see if you don't have the mag).

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
It's too small because that's how you've set it. This is one of those things that should be left to users to control and set the font how they want it. If they want it small, it should be.

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports&quot;
 
Mike - thanks I will check that issue - I have it here.

Craig - thanks - I hadnt connected the dots - on the users machines the font probably looks just fine - do you know which setting messagebox takes its font from? I keep my icon fonts very small so that would explain....

Joe Halloran
 
jJoe,

- do you know which setting messagebox takes its font from?

Go to Display Properties and select the Appearance tab. In the Item drop-down, choose MessageBox. You can then choose the font, font size, colour, etc.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Craig,

craigber said:
This is one of those things that should be left to users to control and set the font how they want it. If they want it small, it should be.

What if this is a touchscreen kiosk app or similar where the last thing you want is the users controlling the look and feel of the system?

Andy
 
Andy,
I think that it's different when a system is used exclusively for a single purpose, rather than the general purpose PC that most users have on their desks. I know I like the way my system is set up - it allows me to be productive. The second an application "changes" my settings or I have to use someone elses system, I "slow down".

Rick
 
Rick,

rgbean said:
I know I like the way my system is set up - it allows me to be productive.

I agree if it's a desktop app we're talking about.

Personally, I'd love to know if there is a way to change the Messagebox font size programmatically. I'd put it in our touchscreen POS code immediately.

Andy
 
jhall251 and agoeddeke

Personally, I'd love to know if there is a way to change the Messagebox font size programmatically. I'd put it in our touchscreen POS code immediately.


Courtesy of

Code:
IF VARTYPE(_screen.msgboxtimer) <> "U" 
    _SCREEN.RemoveObject("msgboxtimer") 
ENDIF 
_SCREEN.AddObject("msgboxtimer", "Tmsgbox") 

WITH _SCREEN.msgboxtimer 
    .FontName = "Times New Roman" 
    .FontSize = 24 

    * note carriage returns added to the end of the message 
    * to increase its height 
    .MsgBox("The MessageBox dialog with adjustable font.   " +; 
        Repli(Chr(13),5), 64, "MessageBox") 
ENDWITH 
* end of main 

DEFINE CLASS Tmsgbox As Timer 
#DEFINE GW_HWNDFIRST    0 
#DEFINE GW_HWNDLAST     1 
#DEFINE GW_HWNDNEXT     2 
#DEFINE GW_CHILD        5 
#DEFINE GWL_ID         -12 
    Interval=0 
    hDialog=0      && dialog window handle 
    DlgMessage="" 
    DlgTitle="" 
    DlgType=0 
    DlgResult=0 
    FontName="Arial" 
    FontSize=16 
    FontItalic=0 
    FontWeight=400 

PROCEDURE Init 
    DECLARE INTEGER GetActiveWindow IN user32 
    DECLARE INTEGER GetWindow IN user32 INTEGER hwnd, INTEGER wFlag 
    DECLARE INTEGER GetWindowLong IN user32 INTEGER hWnd, INTEGER nIndex 
    DECLARE INTEGER ReleaseDC IN user32 INTEGER hwnd, INTEGER hdc 
    DECLARE INTEGER DeleteObject IN gdi32 INTEGER hObject 
    DECLARE INTEGER SelectObject IN gdi32 INTEGER hdc, INTEGER hObject 
    DECLARE INTEGER GetWindowDC IN user32 INTEGER hWnd 

    DECLARE INTEGER CreateFont IN gdi32; 
        INTEGER nHeight, INTEGER nWidth, INTEGER nEscapement,; 
        INTEGER nOrientation, INTEGER fnWeight, INTEGER fdwItalic,; 
        INTEGER fdwUnderline, INTEGER fdwStrikeOut, INTEGER fdwCharSet,; 
        INTEGER fdwOutPrecis, INTEGER fdwClipPrecis, INTEGER fdwQuality,; 
        INTEGER fdwPitchAndFamily, STRING lpszFace 

    DECLARE INTEGER GetWindowText IN user32; 
        INTEGER hwnd, STRING @lpString, INTEGER cch 

    DECLARE INTEGER SendMessage IN user32; 
        INTEGER hWnd, INTEGER Msg, INTEGER wParam, INTEGER lParam 

PROCEDURE MsgBox(cMsg, nType, cTitle) 
    WITH THIS 
        .DlgMessage = cMsg 
        .DlgType = m.nType 
        .DlgTitle = Iif(VARTYPE(cTitle)="C", m.cTitle, VERSION()) 
        .Interval = 100 
        .DlgResult = MessageB(THIS.DlgMessage, .DlgType, .DlgTitle) 
        .hDialog = 0 
    ENDWITH 
RETURN THIS.DlgResult 

PROCEDURE Timer 
    IF THIS.hDialog = 0 
        IF THIS.DialogFound() 
            THIS.SetMessageFont 
        ENDIF 
        THIS.Interval = 0 
    ENDIF 

PROTECTED FUNCTION DialogFound 
    LOCAL hWindow, cTitle 
    hWindow = GetActiveWindow() 
    cTitle = THIS.GetWinText(hWindow) 
    THIS.hDialog = IIF(cTitle=THIS.DlgTitle, hWindow, 0) 
RETURN (THIS.hDialog <> 0) 

PROTECTED FUNCTION GetWinText(hWindow) 
    LOCAL nBufsize, cBuffer 
    nBufsize = 128 
    cBuffer = Repli(Chr(0), nBufsize) 
    nBufsize = GetWindowText(hWindow, @cBuffer, nBufsize) 
RETURN Iif(nBufsize=0, "", Left(cBuffer, nBufsize)) 

PROTECTED PROCEDURE SetMessageFont 
#DEFINE OUT_OUTLINE_PRECIS  8 
#DEFINE CLIP_STROKE_PRECIS  2 
#DEFINE PROOF_QUALITY       2 
#DEFINE WM_SETFONT          48 

    LOCAL hFirst, hWindow, hLast, hTarget, nId, hDC, hFont 
    hFirst = GetWindow(THIS.hDialog, GW_CHILD) 
    hWindow = GetWindow(hFirst, GW_HWNDFIRST) 
    hLast = GetWindow(hFirst, GW_HWNDLAST) 
    hTarget = 0 

    DO WHILE .T. 
        nId = GetWindowLong(m.hWindow, GWL_ID) 
        cText = THIS.GetWinText(m.hWindow) 

        DO CASE 
        CASE m.cText = THIS.DlgMessage 
            hTarget = m.hWindow 
            EXIT 
        CASE hWindow = m.hLast 
            EXIT 
        ENDCASE 
        hWindow = GetWindow(m.hWindow, GW_HWNDNEXT) 
    ENDDO 

    IF hTarget <> 0 
        hDC = GetWindowDC(m.hTarget) 
        hFont = CreateFont(THIS.FontSize,; 
            0, 0,0, THIS.FontWeight,THIS.FontItalic,0,0,; 
            0, OUT_OUTLINE_PRECIS, CLIP_STROKE_PRECIS,; 
            PROOF_QUALITY, 0, THIS.FontName) 

        = SendMessage (m.hTarget, WM_SETFONT, m.hFont, 1) 
        = ReleaseDC(m.hTarget, m.hDC) 
        = DeleteObject(hFont) 
    ENDIF 
ENDDEFINE

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Courtesy of www.news2news.com

Thanks Mike!

That solution is a little quirky though. For starters you can notice the font change before your eyes. The second problem is that if I drag the messagebox somewhere else on the screen it reverts back to the original font.

I ran the code "as is" so there may be some adjustments that will fix these problems. I'll try and play with it a little when I get more time.

Andy
 

I can think of two other approaches. One would be using an HTA file (with some Java scripts for the buttons), another might be to use the internet explorer as a vehicle for your messagebox. Here is a sample:
Code:
objShell = Createobject("WScript.Shell")
Declare Sleep In kernel32 Integer dwMilliseconds
objIE = Createobject("InternetExplorer.Application")
strIETitle ="Message box"
strMsg ="This is my new style message box"
With objIE
	.Toolbar = .F.
	.StatusBar = .F.
	.Resizable = .F.
	.Navigate("about:blank")
	With .Document
		With .ParentWindow
			intWidth = .Screen.AvailWidth
			intHeight = .Screen.AvailHeight
			intWidthW = .Screen.AvailWidth * .40
			intHeightW = .Screen.AvailHeight * .05
			.resizeto(300,200)
			.moveto( (.Screen.AvailWidth)/6, (.Screen.AvailHeight)/6)
		Endwith
		.Write( "<body> " + strMsg + " </body></html>")
		With .ParentWindow.Document.body
			.Style.backgroundcolor = "LightBlue"
			.Scroll="no"
			.Style.Font = "20pt 'Arial'"
			.Style.BorderStyle = "outset"
			.Style.BorderWidth = "4px"
		Endwith
		.Title = strIETitle
		=Sleep(100)
		objShell.AppActivate(strIETitle)
	Endwith
Endwith
objIE.Visible = .T.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Mike,

I appreciate you thinking about this (even though I didn't start this thread). Ultimately I'd like to find a way to programmatically change the messagebox font just as if I went into the Display Properties and did it there. It's dangerous I know, but I can see that being useful in a variety of ways.

One thing I like about the news2news example you posted is that it changes the font for that single instance of the messagebox and doesn't mess with the settings.

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top