Solved

RichTextBox highlight

Posted on 2000-03-14
4
623 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
  • 3
4 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 100 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…

746 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

13 Experts available now in Live!

Get 1:1 Help Now