?
Solved

RichTextBox highlight

Posted on 2000-03-14
4
Medium Priority
?
631 Views
Last Modified: 2012-05-04
I am working on a simple text editing program, like Windows Notepad, that will alow the user to place pictures in there work (a compramise between notepad and Word97).

However, i find that when the users goes to change the font, they select what they want to change and click on the combo box containing the list of fonts. This then removes the blue highlight from the selected text. It still changes the font fine but the user can't see what text they are changing the font for.


Does anybody know how i can keep the blue highlight on the text?
0
Comment
Question by:dmessenger
[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
  • 3
4 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 300 total points
ID: 2617276
Here you go...


Put this in a module:

'-------------------------------------------------------------------------------
    Global lpPrevWndProc As Long
    Global gHW As Long
    Public Const GWL_WNDPROC = -4
    Public Const WM_SETFOCUS = &H7
    Public Const WM_KILLFOCUS = &H8
    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
           (ByVal lpPrevWndFunc As Long, _
            ByVal hWnd As Long, _
            ByVal Msg As Long, _
            ByVal wParam As Long, _
            ByVal lParam As Long) As Long
    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
           (ByVal hWnd As Long, _
            ByVal nIndex As Long, _
            ByVal dwNewLong As Long) As Long
    Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
    Public Sub Hook()
        lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
    End Sub
    Public Sub UnHook()
        Dim lngReturnValue As Long
        lngReturnValue = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
    End Sub
    Function WindowProc(ByVal hw As Long, _
                        ByVal uMsg As Long, _
                        ByVal wParam As Long, _
                        ByVal lParam As Long) As Long
        Select Case uMsg
            Case WM_SETFOCUS
                LockWindowUpdate 0&
               
            Case WM_KILLFOCUS
                LockWindowUpdate gHW
        End Select
        WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
    End Function
'-------------------------------------------------------------------------------




Then put this in the Form Load event of the form that has the RTBox (change RichTextBox1 to whatever you called your RTBox):

   gHW = RichTextBox1.hWnd
   Hook


Put this in the Form Unload event:

   UnHook

Put this in the ComboBox Change event:

   LockWindowUpdate 0&


WARNING:  This code calls window hooks. If you are running this in IDE mode (debug runtime mode) you MUST execute "UnHook" before you stop the program in VB... Otherwise VB will Crash!


Cheers!®©
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2631251
Thanks for the points, glad I could help...

Just out of curiosity, why grade this a "B"??


Cheers!®©
0
 

Author Comment

by:dmessenger
ID: 2631253
Well, the code is a bit long and complex, but it works and that is the main point.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2631307
Well unfortunately, you question doesn't have a short concise 1 line answer... :-(
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

800 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