Solved

RichTextBox highlight

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

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

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 …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now