Results 1 to 11 of 11

Thread: [VB6] "Virtual" Control Array

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    [VB6] "Virtual" Control Array

    This is just a proof-of-concept rather than some code you can just copy and paste into a real application.

    The idea is that using a vast number of controls can be expensive and it can even place you over the limit. One answer is control arrays, but even that can get to be pretty heavy.

    Another option we have is using the DataRepeater control as a container, but that normally requires that you compile the repeated control as an OCX and we all know how much people prefer to avoid maintaining binary compatibility and dealing with proper deployment practices. DataRepeater also has some layout limitations and also requires you to use ADO Recordsets and data binding, something else feared and loathed.

    Taking the idea behind the DataRepeater, I decided to leverage an MSHFlexGrid, a custom UserControl, and some plumbing logic to create a "custom repeater."

    Name:  sshot.png
Views: 491
Size:  35.9 KB

    Here we have a large number of virtual instances of the "Comby" ComboBox container UserControl. It looks chaotic to me, but with a little jiggering you could create somewhat different layouts with more spacing, row and column labels, etc.

    The upper Command button has focus when the program starts.

    You can Tab to get to the first Comby instance. Ctrl-Tab moves to the next, Ctrl-Shift-Tab moves to the previous.

    Tab will take you to the lower Command button, but you must Tab twice for reasons I haven't worked out yet. Shift-Tab also doesn't work to get you back to the first Command button.

    So there is some work to do here yet. It is just something I was playing with.
    Attached Files Attached Files
    Last edited by dilettante; Dec 9th, 2018 at 05:40 PM. Reason: replaced attachment

  2. #2
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: [VB6] "Virtual" Control Array

    Looks interesting...but no attachment? Just not ready yet, or an oversight?

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] "Virtual" Control Array

    What? Did I forget it? No, I see it there and it looks like the right thing.

    I'll reload the page, maybe there is some problem on my end.

  4. #4
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: [VB6] "Virtual" Control Array

    Ah, I figured it out. If a user is on your ignore list and you show their post, it doesn't show attachments. After removing you from my ignore list the attachment appears.

    Interesting approach with the single control and the WM_PAINT message, but I find it is quite slow (on my machine at least). Takes about 5 seconds for the grid of images to appear in the demo, and it gets noticeably worse the more cells there are.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] "Virtual" Control Array

    Five seconds seems a bit high, it takes maybe 1.5 seconds on my very old system I tested on. But it is true I hadn't tried any optimization.

    I optimized initial painting and reposted that above.

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: [VB6] "Virtual" Control Array

    Got similar timings as jpbro on my Win 8.1 VM (about 5sec until the Form shows).

    The approach is not bad - most of the time (90% or so) is lost in "adding items to the combobox" (to be able to make the first screenshot).
    If a "virtual combobox" would be used (or if just the .Text-Property would be set for the "first initial screenshot") the Form_Load- (or "Cell-Load")-timings would improve significantly.

    Olaf

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] "Virtual" Control Array

    Name:  Crudity.png
Views: 377
Size:  20.9 KB

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] "Virtual" Control Array

    Here's a slightly different version where the FlexGrid is scrollable.
    Attached Files Attached Files

  9. #9
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    597

    Re: [VB6] "Virtual" Control Array

    Ask few 'stupid' questions:
    1. I didn't see any definitions for hDC and Image, are they hidden somewhere?
    2. Regarding to Snapshot Function:
    I watch the EnumChildProc only looped once only to get the combobox's child window, how we can get snapshot of the combination of "textbox" + "combobox button"? So smart. Please explain the priciple.

    Thanks.
    Last edited by DaveDavis; Dec 11th, 2018 at 02:31 AM.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] "Virtual" Control Array

    Both hDC and Image are properties of the UserControl itself and within its namespace so we don't have to say UserControl.hDC unless there is ambiguity such as a local variable named hDC.


    Snapshot asks the "outer" window of the ComboBox to paint to the UserControl.

    Then it finds the "inner" Edit control window that the ComboBox wraps and the EnumChildProc asks that window to paint to Picture1. Then Picture1.Image is rendered to the UserControl "on top of" the first image, offset to avoid painting over the border painted as the "outer" window's image.

    Since there are no more windows to worry about it stops enumerating after the first child window.

  11. #11
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    597

    Re: [VB6] "Virtual" Control Array

    Quote Originally Posted by dilettante View Post
    Both hDC and Image are properties of the UserControl itself and within its namespace so we don't have to say UserControl.hDC unless there is ambiguity such as a local variable named hDC.


    Snapshot asks the "outer" window of the ComboBox to paint to the UserControl.

    Then it finds the "inner" Edit control window that the ComboBox wraps and the EnumChildProc asks that window to paint to Picture1. Then Picture1.Image is rendered to the UserControl "on top of" the first image, offset to avoid painting over the border painted as the "outer" window's image.

    Since there are no more windows to worry about it stops enumerating after the first child window.
    Thanks.
    It is brilliant idea and could be useful to put multiple Comboboxes onto UC.

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