Drawing In TextBox Control
:(( Got Stuck In It.
How To Draw A In TextBox Control.
vb Code:
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As VBRUN.RasterOpConstants) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Load()
MsgBox BitBlt(GetDC(Text1.hwnd), 0, 0, 200, 200, Picture1.hDC, 0, 0, vbSrcCopy)
End Sub
BiBlt Return 1 But Nothing Is Drawn In TextBox.. Please Some One Help Me With It.
Re: Drawing In TextBox Control
Re: Drawing In TextBox Control
:) Thanks LaVolpe I Just go Thru This Sample Projects Its Complicated And Not Explained.
vb Code:
' Ask text box to draw itself into the workdc:
If bUseArea Then
Else
SendMessageLong m_hWnd, WM_PRINT, m_cWorkDC.hDC, PRF_CLIENT Or PRF_CHECKVISIBLE
End If
' Draw the results into the textbox:
lHDC = GetDC(m_hWnd)
If Not m_bFixBackground Then
BitBlt lHDC, m_tR.left, m_tR.tOp, m_tR.Right - m_tR.left + 1, m_tR.Bottom - m_tR.tOp + 1, m_cWorkDC.hDC, m_tR.left, m_tR.tOp, vbSrcCopy
Else
BitBlt lHDC, 0, 0, tR.Right - tR.left + 1, tR.Bottom - tR.tOp + 1, m_cWorkDC.hDC, 0, 0, vbSrcCopy
End If
He Used The Same Method :( I Need Some Explanations :(
Re: Drawing In TextBox Control
What that code is attempting to do is
1. Have textbox draw its content to a memory DC.
:: I assume some other custom drawing is being done in that DC, then...
2. Render the DC back onto the textbox.
This can't just be used as is because any change to the textbox (i.e., text change, gain/loose focus, repainting, etc) would just erase completely/partially what was just sent there. Subclassing is the right answer and vbAccelerator's project does that.
Last but not least. It is best practice to call ReleaseDC on any call to GetDC as not doing it can prevent the DC from updating.
Re: Drawing In TextBox Control
What You Are Saying Is That In My Codes Image Is Copied To TextBox But Removed When WM_PAINT is Sended To It? Or In My Codes Image Is Not Even Copied?
Re: Drawing In TextBox Control
Yes, one can paint anything on any window, even the desktop. That's the easy part. But if you don't have control on how it refreshes/repaints, it does you very little good and is very temporary at best. That is where subclassing comes into play.
Re: Drawing In TextBox Control
Ok Im Putting The Above Function To Timer Control So I Can See Is It Really Painting The Text1 HDC May Be I See A Flicker Or SomeThing ...
Re: Drawing In TextBox Control
:) Yes Its Working. Let Me See If I Can Draw Text Box In PictureBox HDC :)
Re: Drawing In TextBox Control
If you really want to see a flicker or change, make m_cWorkDC all black or red and don't call WM_PRINT. From what I can see, unless something is being done to m_cWorkDC between the WM_PRINT and BitBlt call, and the code works, you are copying & pasting the same "stuff".
Edited: Ignore this, we posted at same time and I see you now have results.
Re: Drawing In TextBox Control
SendMessageLong Text1.hwnd, WM_PRINT, Picture1.hDC, PRF_CLIENT Or PRF_CHECKVISIBLE
Not Working... m i Missing SomeThing?
Re: Drawing In TextBox Control
Not all controls/windows will process that message. But using ByVal on the last parameter may help if you have the API declared with lParam As Any.
If that fails, you can try this, using WM_PAINT instead.
SendMessageLong Text1.hWnd, WM_PAINT, Picture1.hDC, ByVal 0&
Ensure Picture1.AutoRedraw=True
Re: Drawing In TextBox Control
Thanks Thanks You Very Much I Got It.
One More Thing Im Stuck In Is How To Enumerate Style From GetWindowLong Like The Api Spy++ Do. Means How Can I Check If Specific Style Is There Or Not?
Re: Drawing In TextBox Control
It Is Still Missing The Caret :) (Blinking Cursor) But It Copied The Text1 Contents To Picture1
Re: Drawing In TextBox Control
Get a list of all the common window styles. Then loop thru the returned style to see if those common style bits are included.
Simple example, using fake values. This is one example. Building your list will be time consuming.
Code:
Private Sub Command1_Click()
Dim lStyle As Long ' < returned from GetWindowLong
Dim Styles(0 To 4) As Long
Styles(0)=0 ' WS_OVERLAPPED
Styles(1)=1 ' WS_somethingElse1
Styles(2)=2 ' WS_somethingElse2
Styles(3)=4 ' WS_somethingElse3
Styles(4)=8 ' WS_somethingElse4
For x = 0 To Ubound(Styles)
If (lStyle And Styles(x)) Then ' has this style
Select Case X
Case 0: List1.AddItem "WS_OVERLAPPED"
Case 1: List1.AddItem "WS_somethingElse1"
Case 2: List1.AddItem "WS_somethingElse2"
Case 3: List1.AddItem "WS_somethingElse3"
Case 4: List1.AddItem "WS_somethingElse4"
End Select
End If
Next
End Sub
Re: Drawing In TextBox Control
vb Code:
If [Returned Value] And [To Check Value] Then
...
End if
Thanks Again Got It.
1 Attachment(s)
Re: Drawing In TextBox Control
See Demo.zip
Type In TextBox it is copying Text1 Contents But Not The Caret...
Re: Drawing In TextBox Control
It Is Also Receiving The Background Of Text1
For This VBAccelerator Did This
vb Code:
Private Function ISubclass_WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case iMsg
...
...
...
Case WM_CTLCOLOREDIT
If m_hWnd = lParam Then
SetBkMode wParam, TRANSPARENT
In Sub Classing CallBack Sub Exactly What Will Be wParam I Cant Debug It. It Is Crashing.
And Some Explanation About this Function SetBkMode :)
In My App It Is Returning Non Zero Value But Doest Seen To Remove The Background Color From Text1.HDC
Re: Drawing In TextBox Control
MSDN my friend. Type in the API you want to learn more about, in this case; SetBkMode and you can learn more about constants too: WM_CTLCOLOREDIT. In both cases, the code is preparing the textbox DC.
With traditional subclassing, never place messageboxes or breakpoints in the subclass routine. Use Debug.Print instead.