perezm
asked on
Bold messages/words
Is there a way to make part of a message bold in a message box or of input box?
And, is there a way to make all of a message bold in a message box or of input box?
If so, can this be done?
Any assistance would be appreciated.
And, is there a way to make all of a message bold in a message box or of input box?
If so, can this be done?
Any assistance would be appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Absolutely right, you couldn't do it with standard message box because it uses system display settings (click right button on your desktop and choose Properies, then go to Appearance tab)...
The ONLY way to implement such functionality - own form.
Sincerely yours,
Crin
The ONLY way to implement such functionality - own form.
Sincerely yours,
Crin
>Absolutely right, you couldn't do it<
Again impossible!!! Nothing impossible with VB <smile>. Wait about 1 hour, I'll do it.
Cheers
Again impossible!!! Nothing impossible with VB <smile>. Wait about 1 hour, I'll do it.
Cheers
Hi
Here it is:
'I used InputBox, code for MsgBox is the same
'--Bas module code--
Option Explicit
Const LF_FACESIZE = 32
Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName(LF_FACESIZE) As Byte
End Type
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SetTimer& Lib "user32" (ByVal hwnd&, ByVal nIDEvent&, ByVal uElapse&, ByVal lpTimerFunc&)
Private Declare Function KillTimer& Lib "user32" (ByVal hwnd&, ByVal nIDEvent&)
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
Private Declare Function GetObjectApi Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Public Const NV_INPUTBOX As Long = &H5000&
Const SYSTEM_FONT = 13
Const FW_BOLD = 700
Const TRANSPARENT = 1
Public sMessage As String
Public Sub TimerProc(ByVal hwnd&, ByVal uMsg&, ByVal idEvent&, ByVal dwTime&)
Dim hMsg As Long, hdcMsg As Long
Dim LF As LOGFONT
Dim ret As Long, oldfont As Long, newfont As Long
hMsg = FindWindow("#32770", App.Title)
hdcMsg = GetDC(hMsg)
oldfont = SelectObject(hdcMsg, GetStockObject(SYSTEM_FONT ))
ret = GetObjectApi(oldfont, Len(LF), LF)
ret = SelectObject(hdcMsg, oldfont)
LF.lfWeight = FW_BOLD
newfont = CreateFontIndirect(LF)
oldfont = SelectObject(hdcMsg, newfont)
SetBkMode hdcMsg, TRANSPARENT
TextOut hdcMsg, 20, 20, ByVal sMessage, Len(sMessage)
newfont = SelectObject(hdcMsg, oldfont)
ret = DeleteObject(newfont)
UpdateWindow hMsg
KillTimer hwnd, idEvent
End Sub
'--using - form code--
Private Sub Command1_Click()
sMessage = "Message text is BOLD"
SetTimer hwnd, NV_INPUTBOX, 10, AddressOf TimerProc
InputBox ""
End Sub
'You can fill LF structure manually and use ANY font name, size, charset, weight etc. More, you can draw picture or icon on Input(Msg) box using BitBlt or DraIcon functions.
Cheers
Here it is:
'I used InputBox, code for MsgBox is the same
'--Bas module code--
Option Explicit
Const LF_FACESIZE = 32
Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName(LF_FACESIZE) As Byte
End Type
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SetTimer& Lib "user32" (ByVal hwnd&, ByVal nIDEvent&, ByVal uElapse&, ByVal lpTimerFunc&)
Private Declare Function KillTimer& Lib "user32" (ByVal hwnd&, ByVal nIDEvent&)
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
Private Declare Function GetObjectApi Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Public Const NV_INPUTBOX As Long = &H5000&
Const SYSTEM_FONT = 13
Const FW_BOLD = 700
Const TRANSPARENT = 1
Public sMessage As String
Public Sub TimerProc(ByVal hwnd&, ByVal uMsg&, ByVal idEvent&, ByVal dwTime&)
Dim hMsg As Long, hdcMsg As Long
Dim LF As LOGFONT
Dim ret As Long, oldfont As Long, newfont As Long
hMsg = FindWindow("#32770", App.Title)
hdcMsg = GetDC(hMsg)
oldfont = SelectObject(hdcMsg, GetStockObject(SYSTEM_FONT
ret = GetObjectApi(oldfont, Len(LF), LF)
ret = SelectObject(hdcMsg, oldfont)
LF.lfWeight = FW_BOLD
newfont = CreateFontIndirect(LF)
oldfont = SelectObject(hdcMsg, newfont)
SetBkMode hdcMsg, TRANSPARENT
TextOut hdcMsg, 20, 20, ByVal sMessage, Len(sMessage)
newfont = SelectObject(hdcMsg, oldfont)
ret = DeleteObject(newfont)
UpdateWindow hMsg
KillTimer hwnd, idEvent
End Sub
'--using - form code--
Private Sub Command1_Click()
sMessage = "Message text is BOLD"
SetTimer hwnd, NV_INPUTBOX, 10, AddressOf TimerProc
InputBox ""
End Sub
'You can fill LF structure manually and use ANY font name, size, charset, weight etc. More, you can draw picture or icon on Input(Msg) box using BitBlt or DraIcon functions.
Cheers
One Hour has passed ......
Oops....
That's what they call coïncidence
That's what they call coïncidence
Hi
Sorry for 20 minutes late <smile>.
Some more comments:
1. It seems it's better to initialize hdc first time before printing (when compilled, it's works fine, but in IDE variables don't print, but text in quotes prints OK),so:
Place
TextOut hdcMsg, 20, 20, ByVal "", 0& before
TextOut hdcMsg, 20, 20, ByVal sMessage, Len(sMessage)
2. For MsgBox you need MoveWindow Api to ajust Box size
Cheers
Sorry for 20 minutes late <smile>.
Some more comments:
1. It seems it's better to initialize hdc first time before printing (when compilled, it's works fine, but in IDE variables don't print, but text in quotes prints OK),so:
Place
TextOut hdcMsg, 20, 20, ByVal "", 0& before
TextOut hdcMsg, 20, 20, ByVal sMessage, Len(sMessage)
2. For MsgBox you need MoveWindow Api to ajust Box size
Cheers
This works both in IDE and compilled (remove ByVal)
TextOut hdcMsg, 20, 20, "", 0&
TextOut hdcMsg, 60, 20, sMessage, Len(sMessage)
Cheers
TextOut hdcMsg, 20, 20, "", 0&
TextOut hdcMsg, 60, 20, sMessage, Len(sMessage)
Cheers
Ark, I absolutely agree with you that we can do EVERYTHING with VB, but look to your code and just think - what way is easier: create simple form or hard usage of API?
I think to be good programmer better to do algoriths right instead playng with different system abilities :)) Don't feel hurt, I didn't say you're bad programmer :)))
Sincerely yours,
Crin
I think to be good programmer better to do algoriths right instead playng with different system abilities :)) Don't feel hurt, I didn't say you're bad programmer :)))
Sincerely yours,
Crin
ASKER
I guess that I will follow the KISS principle.
Thanks.
Have a great weekend & Easter.
Marco
Thanks.
Have a great weekend & Easter.
Marco
Hi
Question was:
>Is there a way to make part of a message bold in a MESSAGE BOX or of INPUT BOX?<
Not about "how to make form like MsgBox or InputBox"
I answered DIRECTLY on question.
BTW, Crin, there is not hard API usage. As you see, 90% of code is for font creating and it's only huge, not difficult. But now I can play with font as I want, including some tricks which you can not do with form. And I'm not sure that "substitute" method will take less resources.
Cheers
Question was:
>Is there a way to make part of a message bold in a MESSAGE BOX or of INPUT BOX?<
Not about "how to make form like MsgBox or InputBox"
I answered DIRECTLY on question.
BTW, Crin, there is not hard API usage. As you see, 90% of code is for font creating and it's only huge, not difficult. But now I can play with font as I want, including some tricks which you can not do with form. And I'm not sure that "substitute" method will take less resources.
Cheers
perezm, Thanks for the points! Glad I could help... That K.I.S.S. principle is quite handy ;-)
Ark,
Just because you are you, I have opened question https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10332343
Go over and collect your points and smile... ;-)
Cheers!®©
Ark,
Just because you are you, I have opened question https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10332343
Go over and collect your points and smile... ;-)
Cheers!®©
mypopup(message,whichwordb
or some such ugly creature ;P