Solved

RichTextBox highlight

Posted on 2000-03-14
4
625 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

770 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