Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Bold messages/words

Posted on 2000-04-20
13
Medium Priority
?
221 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
[X]
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
  • 5
  • 2
  • 2
  • +3
13 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 400 total points
ID: 2736302
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
ID: 2736344
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
ID: 2736358
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 28

Expert Comment

by:Ark
ID: 2736469
>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 28

Expert Comment

by:Ark
ID: 2736633
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
ID: 2736639
One Hour has passed ......
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 2736640
Oops....
That's what they call coïncidence
0
 
LVL 28

Expert Comment

by:Ark
ID: 2736652
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 28

Expert Comment

by:Ark
ID: 2736677
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
ID: 2737404
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
ID: 2737685
I guess that I will follow the KISS principle.

Thanks.

Have a great weekend & Easter.

Marco
0
 
LVL 28

Expert Comment

by:Ark
ID: 2738804
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
ID: 2739579
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

722 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