|
-
Apr 21st, 2007, 12:49 AM
#1
Problem while dragging a transparent RichTextBox
I've created a transparent RTB and dragging it using Rhino's WM_NCLBUTTONDOWN code. The form has a picture.
But the problem is, when I try to drag the transparent RTB (Ctrl+LeftClick on the RTB and drag), the background doesn't get updated.
I tried to subclass the RTB for WM_MOVING / WM_WINDOWPOSCHANGING and SendMessage-ed WM_NCPAINT,WM_ERASEBKGND, WM_PAINT. But that didn't work.
I tried RedrawWindow, but that didn't work either.
Only, if I hide the RTB and show it again - that works (Command1_Click).
Any idea how to update the background while moving ?
Thanks in advance ! 
PS. I don't want to use DrawFocusRect or similar method to show a blank rectangle while dragging. I would like to show full contents of the rtb while dragging.
Code:
' Add a CommandButton and a RichTextBox in your form
Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_TRANSPARENT = &H20&
'
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Sub Command1_Click()
' Backgrund updates only if you click this button
RichTextBox1.Visible = False
RichTextBox1.Visible = True
End Sub
Private Sub Form_Load()
With RichTextBox1
.Text = ""
.SelColor = vbWhite
.SelBold = True
.SelText = "press Ctrl+LeftClick to drag"
End With
' Make RichTextBox transparent -->
' If you run this code after the RTB becomes visible, you'll need to call Command1_Click
SetWindowLong RichTextBox1.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT
'
Me.Picture = LoadPicture("C:\WINDOWS\Web\Wallpaper\Wind.jpg")
End Sub
Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift And vbCtrlMask Then
RichTextBox1.MousePointer = rtfSizeAll
End If
End Sub
Private Sub RichTextBox1_KeyUp(KeyCode As Integer, Shift As Integer)
If Not (Shift And vbCtrlMask) Then
RichTextBox1.MousePointer = rtfDefault
End If
End Sub
Private Sub RichTextBox1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Press Ctrl and LeftClick to drag
If (Button = vbLeftButton) And (Shift And vbCtrlMask) Then
ReleaseCapture
SendMessageLong RichTextBox1.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
RichTextBox1.MousePointer = rtfDefault
End If
End Sub
Last edited by iPrank; Apr 22nd, 2007 at 03:42 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|