dcsimg
Results 1 to 15 of 15

Thread: VB6 Virtual (ownerdrawn) TileView-Ctl

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,429

    VB6 Virtual (ownerdrawn) TileView-Ctl

    A demonstration, how to implement a virtual TileView-Control without ListView-dependencies to comctl32.dll (no SubClassing, no Timers or anything).

    ucTileView contains about 70 lines of code, which is sufficient to:
    - throw OwnerDraw-Events at the User
    - determine the "current Tile under the Mouse" (for a proper Click-Event and setting the Ctls ListIndex)
    - handle the VScroller-Visibility and .Values accordingly

    The OwnerDraw-Events (one for the Ctl-BackGround and one for each Tile) come in with a hDC-Param, which allows to implement your own UserDrawings for a Tile with any lib that can render "stuff against an hDC".

    The Demo currently makes use of the cGDIPlusCache-Class as the Drawing-Helper (which is in the CodeBank as well):
    http://www.vbforums.com/showthread.p...-cls-revisited

    If you want "Extras" (as e.g. MouseWheel-Support or Hovering), please put them in yourselves.

    Here a ScreenShot:


    And here the Demo-Zip:
    ucTileView.zip

    Have fun,

    Olaf

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,429

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    Small fix for the Refresh-Routine in the original ucTileView.zip above:

    Code:
    Public Sub Refresh()
      Dim i As Long, Row As Long, Col As Long
      
      If TileHeight <= 0 Then TileHeight = 32
      If TileWidth <= 0 Then TileWidth = 32
      picCanvas.Move 0, 0, TileWidth * DPIScaleFac, TileHeight * DPIScaleFac
      VScr.Move ScaleWidth - VScr.Width, 0, VScr.Width, ScaleHeight
      
      VisRows = ScaleHeight \ picCanvas.Height + IIf(ScaleHeight Mod picCanvas.Height, 1, 0)
      VScr.LargeChange = VisRows
      For i = 1 To 2 'we need to do this two times, due to "circular-dependecies" in some intermediate values
        VScr.Visible = VScr.Max > 0
        dxAvail = ScaleWidth - IIf(VScr.Visible, VScr.Width, 0)
        ItemsPerRow = dxAvail \ picCanvas.Width: If ItemsPerRow <= 0 Then ItemsPerRow = 1
        RowCount = ListCount \ ItemsPerRow + IIf(ListCount Mod ItemsPerRow, 1, 0)
        dxSpacing = (dxAvail - ItemsPerRow * picCanvas.Width) \ ItemsPerRow
        VScr.Max = RowCount - VisRows + 1
      Next
      
      Cls
      RaiseEvent OwnerDrawBackGround(hDC, dxAvail, ScaleHeight)
      For i = 0 To ListCount - 1
          Row = i \ ItemsPerRow
          Col = i Mod ItemsPerRow
          If Row >= VScr.Value And (Row - VScr.Value) * picCanvas.Height < ScaleHeight Then
             BitBlt picCanvas.hDC, 0, 0, picCanvas.Width, picCanvas.Height, hDC, Col * (picCanvas.Width + dxSpacing), (Row - VScr.Value) * picCanvas.Height, vbSrcCopy
             RaiseEvent OwnerDrawTile(picCanvas.hDC, i, Row, Col, picCanvas.Width, picCanvas.Height)
             BitBlt hDC, Col * (picCanvas.Width + dxSpacing), (Row - VScr.Value) * picCanvas.Height, picCanvas.Width, picCanvas.Height, picCanvas.hDC, 0, 0, vbSrcCopy
          End If
      Next
      UserControl.Refresh
    End Sub
    One can either replace the Refresh-Routine via Copy&Paste -
    or use the following updated-ZipArchive (which contains everything again, including the fix):
    ucTileView2.zip

    Sorry about that.

    Olaf

  3. #3
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,603

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    Quote Originally Posted by Schmidt View Post
    If you want "Extras" (as e.g. MouseWheel-Support or Hovering), please put them in yourselves.
    Please, do show us how to do any of these without subclassing!

    cheers,
    </wqw>

  4. #4
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,105

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    Quote Originally Posted by wqweto View Post
    Please, do show us how to do any of these without subclassing!

    cheers,
    </wqw>

    The hover support doesn't require sub-classing but, yeah, the mouse-wheel sure does...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,429

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    Quote Originally Posted by wqweto View Post
    Please, do show us how to do any of these without subclassing!
    Sounds like some of my statements in the opener-post got you "riled up"...
    - is it my mentioning of the LOC?
    - or that I considered the comctl32-lib-API as "crazy to work against" (in the thread which caused this CodeBank-entry)?

    Well, whatever it was, let's take the question seriously...
    So here's how to do Hovering+MouseWheeling without SubClassing (Code into an empty Form):
    Code:
    Option Explicit
    
    Private Declare Function WaitMessage Lib "user32" () As Long
    Private Declare Function PeekMessageW Lib "user32" (pMsg As Any, ByVal hWnd As Long, ByVal MsgMin As Long, ByVal MsgMax As Long, ByVal RemoveMsg As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (pPnt As Any) As Long
    Private Declare Function WindowFromPoint Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    
    Private WithEvents PB As VB.PictureBox, WithEvents TM As VB.Timer
    
    Private Sub Form_Load()
      Set PB = Controls.Add("VB.PictureBox", "PB"): PB.Visible = True
    End Sub
     
    Private Sub PB_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
      If TM Is Nothing Then Set TM = Controls.Add("VB.Timer", "TM"): TM.Interval = 9: PB_MouseEnter
    End Sub
    
    Private Sub TM_Timer()
      Const WM_MOUSEWHEEL = &H20A: Dim Msg&(0 To 7), Pt&(0 To 1), i&
      
      GetCursorPos Pt(0)
      If WindowFromPoint(Pt(0), Pt(1)) <> PB.hWnd Then _
         Set TM = Nothing: Controls.Remove "TM": PB_MouseLeave
     
      WaitMessage
      If PeekMessageW(Msg(0), PB.hWnd, WM_MOUSEWHEEL, WM_MOUSEWHEEL, 1) Then _
         PB_MouseWheel Msg(2) \ 65536, Msg(2) And &HFFFF&, Msg(5), Msg(6)
    End Sub
     
    Private Sub PB_MouseEnter()
      PB.BackColor = vbGreen: Cls
    End Sub
    Private Sub PB_MouseLeave()
      PB.BackColor = vbRed
    End Sub
    Private Sub PB_MouseWheel(Direction, MouseKeys, MouseX, MouseY)
      Print Direction, MouseKeys, MouseX, MouseY
    End Sub
    And here the slightly adapted Code - built-into the updated TileView-Control
    (now with Tile-Item-Hovering and MouseWheel-support)
    ucTileView3.zip

    HTH

    Olaf

  6. #6
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,105

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    PeekMessageW! Of course...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  7. #7
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,603

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    Quote Originally Posted by Schmidt View Post
    Sounds like some of my statements in the opener-post got you "riled up"...
    Nothing like this, I was on my phone and the reply had to be succinct and your hacks always amuse me

    Like this one w/ PeekMessage + Timer -- thoroughly enjoy it, nice idea. . . that no production implementation should use :-))

    cjeers,
    </wqw>

  8. #8
    Addicted Member
    Join Date
    Aug 2016
    Posts
    191

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    Schmidt's last few posts (this and that) are good demo for showing new technique, but can't use directly due to slow and less stablity.

  9. #9
    Frenzied Member
    Join Date
    Jun 2012
    Posts
    1,317

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    I can understand that a control should not subclass out of it's "borders". But what the heck is the problem if a control subclasses itself? Only for IDE comfort? But that would be hard to make "everything" w/o subclass.
    I don't want to put this thread off-topic, I'm just curios whats the background(?)

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,429

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    Quote Originally Posted by Krool View Post
    ...what the heck is the problem if a control subclasses itself?
    Finally some "refreshing german directness" (@wqweto ... none of your "*****-footing" is needed).

    And no, I have no problem with "subclassing within controls" (it's wqweto who suggested that)...
    SubClassing is completely fine:
    - as long as the same subclassing-technique is used
    - throughout the whole App (including externally loaded Control-Binaries)
    - the SubClasser preferrably encapsulated in an external Dll
    - preferrably without any "ASM-thunking" (but that's just my personal opinion)

    Thats the sole reason why I prefer to post "Ctl-Demos which do not do any subclassing in the Ctl itself".
    (there's too many Controls - e.g. on PSC - which come with age old "In-Control-SubClassing-Hacks" which don't play well together with other SubClassing-techniques).

    For the given example that means, that you should not use the last ucTileView3.zip in your own Apps,
    but ucTileView2.zip instead (which still contains no MouseWheeling or Hover-Support).

    The purpose of the Demo was, to introduce the "basic approach" (how to implement virtual List-Controls).
    It is not "production-code" (there's currently no "Key-Handling-support" and also the VScroller needs to be changed to a version, which is not limited to max 32767).

    Olaf

  11. #11
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,603

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    Quote Originally Posted by Schmidt View Post
    A demonstration, how to implement a virtual TileView-Control without ListView-dependencies to comctl32.dll (no SubClassing, no Timers or anything).
    It was the "no subclassing, no timers" promise that hook me to download the zip in first place.

    Quote Originally Posted by Schmidt View Post
    If you want "Extras" (as e.g. MouseWheel-Support or Hovering), please put them in yourselves.
    This I immediately considered beyond my capabilities, so wanted to see how it's possible. Nicely done :-))

    cheers,
    </wqw>

  12. #12
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,931

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    Quote Originally Posted by Schmidt View Post
    SubClassing is completely fine:
    - as long as the same subclassing-technique is used
    - throughout the whole App (including externally loaded Control-Binaries)
    Do you mean when the two (or more) subclassing techniques subclass the same window, or even when they subclass different ones?

    Quote Originally Posted by Schmidt View Post
    Thats the sole reason why I prefer to post "Ctl-Demos which do not do any subclassing in the Ctl itself".
    The problem is that that requires other dependency files.
    And that can complicate the ussage for programmers not too experienced with subclassing.
    And the ones that are familiar with subclassing can, in general, figure out how to move to the subclassing technique that they normally use.

    But this issue is a dilemma.

  13. #13
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,683

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    Quote Originally Posted by Krool View Post
    I can understand that a control should not subclass out of it's "borders". But what the heck is the problem if a control subclasses itself? Only for IDE comfort? But that would be hard to make "everything" w/o subclass.
    I don't want to put this thread off-topic, I'm just curios whats the background(?)
    If we use VB6 to develop large applications, even occasional IDE crashes are unacceptable. 10 years ago, I removed all subclasses from my software and rewritten all custom controls, as a result, my VB6 IDE did not crash once in the next 10 years. Last year, I used The trick's subclass in an audio program, and the crash of the VB6 IDE reappeared, but the crashes were very few and I can still accept it. Every time the VB6 IDE crashes, the latest changes made to the code are lost.

    I tested a lot of subclasses, including yours, DEXWERX's, Olaf's, The trick's, LaVolpe's. No Subclass is 100% IDE safe. But I haven't had time to test wqweto's subclass, and I don't know if his subclass is better than others.
    Last edited by dreammanor; Nov 28th, 2019 at 07:49 AM.

  14. #14
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,603

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    Quote Originally Posted by dreammanor View Post
    But I haven't had time to test wqweto's subclass, and I don't know if his subclass is better than others.
    Yes, it absolutely is better than anything "on the market" but it's still *not* bullet-proof for subclassing in the IDE. I'm currently testing it (dog-fooding) in the IDE w/ my daily work and it shows some weaknesses. There are some conditions when hitting the End button crashes the IDE.

    It works in 90% of the cases though and has saved my bu... work in numerous occasions when I had to stop a subclassed project w/ the End button but I really want to make it bullet-proof and unfortunately there are still things in IDE that I don't understand well enough so this might take couple of years more to get there.

    cheers,
    </wqw>

  15. #15
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,683

    Re: VB6 Virtual (ownerdrawn) TileView-Ctl

    Quote Originally Posted by wqweto View Post
    Yes, it absolutely is better than anything "on the market" but it's still *not* bullet-proof for subclassing in the IDE. I'm currently testing it (dog-fooding) in the IDE w/ my daily work and it shows some weaknesses. There are some conditions when hitting the End button crashes the IDE.

    It works in 90% of the cases though and has saved my bu... work in numerous occasions when I had to stop a subclassed project w/ the End button but I really want to make it bullet-proof and unfortunately there are still things in IDE that I don't understand well enough so this might take couple of years more to get there.

    cheers,
    </wqw>
    Hi wqweto, thank you for your outstanding work. After I finish my work, I'll take time to test your subclass.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width