Results 1 to 18 of 18

Thread: Drawing In TextBox Control

  1. #1

    Thread Starter
    Lively Member SamCasper's Avatar
    Join Date
    Dec 2009
    Posts
    89

    Drawing In TextBox Control

    ( Got Stuck In It.

    How To Draw A In TextBox Control.

    vb Code:
    1. 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
    2. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    3.  
    4. Private Sub Form_Load()
    5.  MsgBox BitBlt(GetDC(Text1.hwnd), 0, 0, 200, 200, Picture1.hDC, 0, 0, vbSrcCopy)
    6. End Sub

    BiBlt Return 1 But Nothing Is Drawn In TextBox.. Please Some One Help Me With It.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Drawing In TextBox Control

    Oh, only if it was that easy. Look at this vbAccelerator project
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Lively Member SamCasper's Avatar
    Join Date
    Dec 2009
    Posts
    89

    Re: Drawing In TextBox Control

    Thanks LaVolpe I Just go Thru This Sample Projects Its Complicated And Not Explained.

    vb Code:
    1. ' Ask text box to draw itself into the workdc:
    2.    If bUseArea Then
    3.    Else
    4.       SendMessageLong m_hWnd, WM_PRINT, m_cWorkDC.hDC, PRF_CLIENT Or PRF_CHECKVISIBLE
    5.    End If
    6.    
    7.    ' Draw the results into the textbox:
    8.    lHDC = GetDC(m_hWnd)
    9.    If Not m_bFixBackground Then
    10.       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
    11.    Else
    12.       BitBlt lHDC, 0, 0, tR.Right - tR.left + 1, tR.Bottom - tR.tOp + 1, m_cWorkDC.hDC, 0, 0, vbSrcCopy
    13.    End If

    He Used The Same Method I Need Some Explanations

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Lively Member SamCasper's Avatar
    Join Date
    Dec 2009
    Posts
    89

    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?

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Lively Member SamCasper's Avatar
    Join Date
    Dec 2009
    Posts
    89

    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 ...

  8. #8

    Thread Starter
    Lively Member SamCasper's Avatar
    Join Date
    Dec 2009
    Posts
    89

    Re: Drawing In TextBox Control

    Yes Its Working. Let Me See If I Can Draw Text Box In PictureBox HDC

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    Lively Member SamCasper's Avatar
    Join Date
    Dec 2009
    Posts
    89

    Re: Drawing In TextBox Control

    SendMessageLong Text1.hwnd, WM_PRINT, Picture1.hDC, PRF_CLIENT Or PRF_CHECKVISIBLE

    Not Working... m i Missing SomeThing?

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12

    Thread Starter
    Lively Member SamCasper's Avatar
    Join Date
    Dec 2009
    Posts
    89

    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?

  13. #13

    Thread Starter
    Lively Member SamCasper's Avatar
    Join Date
    Dec 2009
    Posts
    89

    Re: Drawing In TextBox Control

    It Is Still Missing The Caret (Blinking Cursor) But It Copied The Text1 Contents To Picture1

  14. #14
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  15. #15

    Thread Starter
    Lively Member SamCasper's Avatar
    Join Date
    Dec 2009
    Posts
    89

    Re: Drawing In TextBox Control

    vb Code:
    1. If [Returned Value] And [To Check Value] Then
    2.   ...
    3. End if

    Thanks Again Got It.

  16. #16

    Thread Starter
    Lively Member SamCasper's Avatar
    Join Date
    Dec 2009
    Posts
    89

    Re: Drawing In TextBox Control

    See Demo.zip

    Type In TextBox it is copying Text1 Contents But Not The Caret...
    Attached Files Attached Files

  17. #17

    Thread Starter
    Lively Member SamCasper's Avatar
    Join Date
    Dec 2009
    Posts
    89

    Re: Drawing In TextBox Control

    It Is Also Receiving The Background Of Text1
    For This VBAccelerator Did This

    vb Code:
    1. Private Function ISubclass_WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    2.    Select Case iMsg
    3. ...
    4. ...
    5. ...
    6.    Case WM_CTLCOLOREDIT
    7.       If m_hWnd = lParam Then
    8.          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
    Last edited by SamCasper; Feb 19th, 2010 at 06:07 PM.

  18. #18
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Last edited by LaVolpe; Feb 19th, 2010 at 09:12 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width