Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

RichTextBox highlight

Posted on 2000-03-14
4
Medium Priority
?
634 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Suggested Courses

636 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