News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Problem: Getting a scrollbar to appear in a custom control

Started by NoCforMe, August 27, 2022, 02:39:36 PM

Previous topic - Next topic

NoCforMe

OK, something new: You can add images (icons or bitmaps) to each item. Check it out. (Be sure to get the attached image files.)

The first 3 are .ICOs, the last one's a .BMP. They must be 16x16. Later could accept different sizes. Programming interface isn't too bad; to add an item (with or without image) you pass a small structure to the SendMessage() call:


MLB_ITEM STRUCT
  txtPtr DD ?
  imageHandle DD ?
  flag DD ?
MLB_ITEM ENDS

; Item-image flags:
MLBF_IMAGE_ICON EQU 4000H
MLBF_IMAGE_BITMAP EQU 8000H


If there's an image wanted you pass its handle, otherwise you set this member to NULL. The user (caller) also needs to set the flag to the type of image file; the control handles it appropriately depending on the type.

One thing I discovered is that DrawIcon() didn't work too well for some reason; I ended up using DrawIconEx(), with size params of 0 (the files are all 16x16) and the DI_NORMAL flag. (For bitmaps you have to go through that whole CreateCompatibleDC/SelectObject/BitBlt rigamarole.)
Assembly language programming should be fun. That's why I do it.

zedd151

This is looking more like "NoCforMe's custom control workshop" than the current topic title.  :thumbsup:
Looks fine indeed.

NoCforMe

Yeah, I changed the subject line to reflect how things are going.

Pretty soon I'll be looking for volunteers to actually use the thing. Complete package coming soon, including (gasp!) documentation. (Wait: programmers are like electricians: they're never supposed to document anything! That's the job of that illiterate slob over there in the corner.)
Assembly language programming should be fun. That's why I do it.

zedd151

Hobby programmers like me are like DIYers. They never read instructions.  :tongue:


Just kidding of course, except for the DIYers. Sounds like you could possibly write a tutorial on using scroll bars, list boxes and the like.

jj2007

Quote from: NoCforMe on August 31, 2022, 01:01:38 PM
OK, something new: You can add images (icons or bitmaps) to each item. Check it out. (Be sure to get the attached image files.)

:thumbsup:

NoCforMe

OK, if anybody still cares, here's the latest and greatest. @Swordfish, notice that scrolling is now fully implemented, including thumb-tracking. (Wasn't hard to get working; I just wasn't tracking it properly in my paint handler.) Also notice that long items now are drawn with ellipsis (...) at the end if they're wider than their "cell". This is due to using DrawText() rather than ExtTextOut() (see below for some gory details).

It's getting close; I'm not ready to release the code into the wild yet, because I don't want to have to go chasing versions all over the place as I continue to tweak things and go through my todo list:

  • Proper memory management (halfway there, but still not robust)
  • Keyboard interface (none currently)
  • Maybe make it resizeable?
  • Take Greenhorn's suggestion and store instance data pointer in the control's "extra bytes"
Anyhow, play around with it as usual. Next time I'll explain the programming interface for adding items and solicit comments on it.

Regarding drawing text: I learnt something about this. I was using ExtTextOut(), which works OK, except I wanted to add text ellipsis (...) for items that don't fit in their cell. So I tried DrawText(), which has this capability. At first I couldn't get anything at all to show. I was using the following flags:


DT_END_ELLIPSIS or DT_LEFT or DT_TOP or DT_NOPREFIX


Nothing. I searched online and found a couple discussions of why this function doesn't work sometimes, but no solutions that made it work for me.

Then I went back to the documentation and noticed some additional flags. One of them, DT_SINGLELINE, says it "Displays text on a single line". I hadn't figured I needed this--isn't this the default?--but when I added it, things started to work. Way to go, Micro$oft, for incomplete explanations of your API!

Moral of the story: if things don't work, after consulting the oracle (the Intertubes), it pays to experiment.
Assembly language programming should be fun. That's why I do it.

zedd151


Quote from: NoCforMe on September 02, 2022, 05:37:19 AM
@Swordfish, notice that scrolling is now fully implemented, including thumb-tracking.
Okay. I gotta go take the dog for a walk, brb.

zedd151

Okeedokee, I'm back.
The example looks fine. Nice job. There is some noticeable flickering of the 'items' while scrolling though.
Not a show stopper by any means. Just something for your todo list.

NoCforMe

Yes, thumb-scrolling isn't as smooth as I'd like. Icing on the cake for later. (I consider that in the "chrome" category: chrome bumpers, not the carburetor or fuel pump.)
Assembly language programming should be fun. That's why I do it.

zedd151

Yeah, nothing to halt progress over. You're really making good strides with it.  :thumbsup:

NoCforMe

OK, here are the gory details of adding an item to my mcListbox. (Pronounced like an Irish or Scottish name.) From my documentation:

Adding Items to mcListbox Controls

Items are added to a mcListbox control by means of the MLBM_ADDITEM message. Items are always added to the end of the list. An item can also have an image (icon or bitmap) attached to it.

To add an item, create a MLB_ITEM structure:

typedef struct {
  DWORD txtPtr;
  DWORD imageHandle;
  DWORD flag;
} MLB_ITEM;


Put a pointer to the text to be added in the txtPtr member. Pass a pointer to this structure via the wParam parameter to SendMessage.
If images are to be added to items, you need to first enable this functionality through the MLBM_SETAPPEARANCE message:


MLBAPPEARANCE mlba;

mlba.flag = MLBF_SETIMAGESYES;
SendMessage (ctrlHandle, MLBM_SETAPPEARANCE, &mlba, 0);


After that you can pass a handle to an image that has been loaded through the imageHandle member of the MLB_ITEM structure. You must also set the type of image by setting a flag value in the flag member:

  • MLBF_IMAGE_ICON: Icon (.ico) image
  • MLBF_IMAGE_BITMAP: Bitmap (.bmp) image

If you have enabled image display with the MLBF_SETIMAGESYES flag, and you do not want an image displayed for an item, then set the imageHandle member to NULL.

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

So, any comments? As a programmer, would you be offended at all by this interface? Because there are more than two parms, they can't just be passed in wParam and lParam to SendMessage(), therefore the need for the structure.
Assembly language programming should be fun. That's why I do it.

zedd151

No, it seems the best way to pass multiple arguments. It's much better than fetching the variables you need discreetly in the code that follows. That's exactly what one of the purposes for using structures. In'nt it?


I'll have a quarter pounder, a McListBox, and a large order of fries to go btw.

NoCforMe

Quote from: swordfish on September 02, 2022, 07:10:52 AM
It's much better than fetching the variables you need discreetly in the code that follows.

How would you even do that? (And I think the word you're looking for is "discretely". No need for discretion here.)
Assembly language programming should be fun. That's why I do it.

zedd151


Quote from: NoCforMe on September 02, 2022, 07:24:33 AM
How would you even do that?

Not sure really.  I just know that passing pointer to the structure, as an arg,  is a perfect use of it.

Quote
(And I think the word you're looking for is "discretely". No need for discretion here.)
discreet as in discreet values for instance, or discreet variable rather than an argument.
Maybe not the right word though. :mrgreen:
Parental discretion advised though, in either case.

I know what I'm thinking even though I don't always have the right words in mind to articulate my thoughts. But I try.





NoCforMe

Discrete: separate.
Discreet: tactful, using discretion.

One of the common homophone mix-ups. (Reign/rein, principle/principal, etc.)
Assembly language programming should be fun. That's why I do it.