Solved

Bold messages/words

Posted on 2000-04-20
13
203 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:perezm
  • 5
  • 2
  • 2
  • +3
13 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 100 total points
Comment Utility
The easiest way around this is to build your own form and design it with whatever attributes you want, then show it like this:

     MyMessageBox.Show 1


Cheers!®©
0
 
LVL 3

Expert Comment

by:myqlG
Comment Utility
I agree with mcrider..I know I have seen controls that allow what you want..but thats all they really do anyway...you could make the form that excepts input too
mypopup(message,whichwordboldarray(),whichwordsitalicizedarray)
or some such ugly creature ;P
0
 
LVL 2

Expert Comment

by:Crin
Comment Utility
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
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
>Absolutely right, you couldn't do it<
Again impossible!!! Nothing impossible with VB <smile>. Wait about 1 hour, I'll do it.
Cheers
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
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
0
 
LVL 17

Expert Comment

by:calacuccia
Comment Utility
One Hour has passed ......
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 17

Expert Comment

by:calacuccia
Comment Utility
Oops....
That's what they call coïncidence
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
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
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
This works both in IDE and compilled (remove ByVal)
TextOut hdcMsg, 20, 20, "", 0&
TextOut hdcMsg, 60, 20, sMessage, Len(sMessage)
Cheers
0
 
LVL 2

Expert Comment

by:Crin
Comment Utility
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



0
 
LVL 1

Author Comment

by:perezm
Comment Utility
I guess that I will follow the KISS principle.

Thanks.

Have a great weekend & Easter.

Marco
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
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
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
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 http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10332343  

Go over and collect your points and smile... ;-)


Cheers!®©
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now