Solved

Bold messages/words

Posted on 2000-04-20
13
206 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
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
 
LVL 27

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 27

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 17

Expert Comment

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

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 27

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 27

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

895 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

18 Experts available now in Live!

Get 1:1 Help Now