Page 1 of 2

A 'PopupList' control (implemented with OOP).

Posted: Thu Jan 31, 2008 7:45 pm
by srod
Update - Jan 1st 2008.
Bug fixed.

The PopupList control was destroying all other ownerdrawn controls placed on the same window! Doh! :oops:

Download

===============================================

Hi,

I was in need of a simple (and easy to implement! :wink: ) control which combined the functionality of a basic popup menu with a scrollable listbox gadget and one which could be positioned anywhere. By simple I mean that I wanted Windows to do all the hard work of tracking the mouse, dealing with overlap, keyboard control etc. :wink:

Hence, a whopping great cheat was in order!

Still, minimal testing aside, it seems to work okay.

Here's a quick demo Windows exe which you can try :

http://www.purecoder.net/PopupList.exe
(Simply run it and right-click anywhere in the Window etc.)

Methods exposed by the PopupList class :

Code: Select all

AddItem(position, text.s)
ClearItems()
Destroy()
GetColor.l(colorType)
GetFont.l()
GetHeight.l()               
GetItem.s(position)
GetItemCount.l()
GetState.l()
GetWidth.l()
GetX.l()
GetY.l()
RemoveItem(position)
Resize(x, y, width, height)
SetColor(colorType, color)
SetFont(font)
Show.l(state=-1)
NOTES.
  • There is no help manual / user guide. Instead, look at the residents file for a few comments on each method where appropriate. Most methods are completely and utterly self explanatory.
  • This can easily be extended to allow for icons etc.
  • Embedding other controls within this control is quite feasible. It would be quite a bit of work though and it is not something which I require just yet, so I will leave this for another day.
  • I haven't done much testing!
Download the complete source

Posted: Thu Jan 31, 2008 8:47 pm
by rsts
Too cool. :D

Thanks.

Posted: Fri Feb 01, 2008 12:54 am
by SFSxOI
very nice, Thank You :)

Posted: Fri Feb 01, 2008 12:58 am
by srod
You're both welcome.

@SFSxOI : I saw your recent post in which you asked about something like this; however at that time I wasn't in need of this myself! Today, however, I found myself needing exactly this! :)

Posted: Fri Feb 01, 2008 1:32 am
by DoubleDutch
I think I can find a good use for this control. :)

Posted: Fri Feb 01, 2008 1:41 am
by srod
DoubleDutch wrote:I think I can find a good use for this control. :)
I already have! :wink:

Posted: Fri Feb 01, 2008 1:49 am
by Dare
Very nice.

Small (tiny, miniscule) thing - It is smart enough to know how to position the popup when the window is at the bottom or almost off the bottom of the screen (goes up from pointer rather than down) however on the right edge of the screen it disappears. That is, it always appears to the right of the mouse pointer.

I assume that this means the calling code needs to check X position - although it appears that it doesn't need to check Y position?.

Very nice!

Posted: Fri Feb 01, 2008 1:58 am
by srod
It's actually an ownerdrawm combobox (rather than a popup menu) and so the automatic repositioning is all down to Windows; nowt to do with me! :)

As for disappearing off the right edge of the screen, yes it's down to the 'dodgy' demo. In a proper application you'd have to take a little care with that simply because, as I say, the control is based upon a combobox and not a popup menu. It would be a simple task to code around this.

Posted: Fri Feb 01, 2008 2:08 am
by Dare
Thanks for confirming.

Weird that windows bothers to check Y and not X in this case.

Posted: Fri Feb 01, 2008 2:17 am
by srod
It does make sense.

When the listbox which pops up disappears beneath the screen, the actual selection field of the combobox is still fully within the bounds of the main window. All windows does is then move the listbox (not the combo) up the screen.

However, if the listbox disappears off the right of the screen, it means that the selection field of the original combo was positioned in such a way that it did not fit within the bounds of the parent window etc. It then doesn't seem unreasonable that windows should refuse to do anything about it.

You must remember that in my demo, when you right click, an entire combo box is being placed on the screen so that the top left corner of the selection field is positioned exactly where you click. Thus if you click too close to the right edge of the screen... :)

Easy to get around.

Posted: Fri Feb 01, 2008 2:27 am
by Dare
srod wrote:Easy to get around.
Yes. And now my curiosity is satisfied as well. :) Thanks!

Posted: Fri Feb 01, 2008 3:15 am
by SFSxOI
@srod

Yes! I was needing exactly this very thing. Thank You very much...this will really clean up some menu stuff for something I was working on and make it much neater and cleaner, even lend a 'snappy crisp' feel to the project. :)

Posted: Fri Feb 01, 2008 3:19 pm
by srod
:) Glad it is of use.

There is a little bit of flicker within the client area when scrolling the control. I may address this at some point as it should be easy enough to prevent. Depends on how annoying it gets!

Posted: Fri Feb 01, 2008 4:26 pm
by Marco2007
Excellent!!

Thank you very much! :D

BTW: Why does Srod have only three stripes?

Posted: Fri Feb 01, 2008 4:51 pm
by srod
You're welcome.
Marco2007 wrote:BTW: Why does Srod have only three stripes?
hehe, I think I used to have 4... too many off-topic posts! :wink:

It's like my old girlfriend used to say; 'it's not how many you've got or how big they are, it's what you do with 'em that counts!'

Uhm, thinking about it, how the hell did she knew how many stripes I had or indeed how big they were?

Wait, hang on a moment ......

:)