Activating image control as ActiveImage at runtime

I have a queue and based on its contents I create image controls at runtime. So if I have 5 records in the queue, I use CREATE() to put 5 image controls on the window. This works.

But I want these images to become ActiveImages because I need to get mousedown events when user clicks on any of these images.

I’ve manually added INCLUDE(‘’),once in global embeds, I’ve declared:
img1 ActiveImage in data of the window

Now here’s the problem. If I put an image control in designer onto the window and call img1.init(window,?image1,0,0) anywhere in ThisWindow.Init embed, it works.

So for some reason INIT has to be rather early in the process. But the trick is I’m not putting image controls in designer, I’m creating them at runtime. And calling img1.init after CREATE() sometime later on does not work, meaning mousedown is not reported as event. Sort of chicken-egg issue.

Any idea how can I make this work? Create image controls at runtime and catch an event when users clicks on any of them (of course I need to know on which control the user has clicked so I can act properly later on). If this can be done without using activeimage, no problem. I just need events fired when users clicks on those images.

Thanks for the help



Put FEQs of the created controls in a queue and then check for them inside the accept loop
smth like
CurrentField = FIELD()
CRCNTQ:FEQ = CurrentField
If ~ErrorCode()
CASE CurrentField
OF Image1FEQ
OF EVENT:Accepted

Will try but if I understand correctly, image controls without ActiveImage do not fire any events at all, no focus or anything…

You can try creating matching REGION controls

Yeh, I thought about it.

RIght now I’ve checked the activeimage source and one thing did the trick. I called INIT after creating the control and after that I called post(event:openwindow,ImgFEQ#) and it works. Seems like source expects the “usual” OpenWindow event fired to process all needed to activate activeimage.

Now only one thing remains. I can have 50 records in my queue, so my loop creates 50 controls. All good, but for activeimage I need to declare:
img1 activeimage
img2 activeimage
img50 activeimage
in DATA section.

Can this also be somehow declared at runtime?

or perhaps ditch whole activeimage and just somehow properly use REGISTEREVENT? But that’s above my knowledge, there are some pointers and addresses involved :slight_smile:

Perhaps you could use an ImageEx viewer control (or multiple ones if you need them separate). Not sure the result you’re trying to achieve. You could maintain a queue of ImageEx bitmaps, and load into the viewer as needed. I do that for maintaining multiple UNDO.

I’m reading jpg files from a folder, trying to display thumbnails vertically and using imageex to display a larger image of selected thumbnail. Obviously number of jpgs varies hence I make image controls on the fly. I like vertical positioning of thumbnails with scroll attribute on window so i get nice scrollbar to move down the thumbnails. I’m closw but would need to figure out how to properly register mousedown events on images at runtime - use part of activeimage class. Then it would all be done at runtime. I guess more cw developers could use this as image gallery then too…

Sounds neat. You could also use a single bitmap to contain all of the thumbnails. If you maintain a queue of coordinates, you could identify which thumbnail was clicked on. It would scroll just like a single image.

Would not take all that much work to write a function that receives a list of files and:

  1. Renders a thumbnail with the thumbnail class within the size constraints you define.
  2. Saves the thumbnailed bitmap object to a queue, along with the height/width, and position within the grid.
  3. Processes the queue, and based on the total size and quantity of thumbnails, creates a host bitmap where you can draw all of the thumbnails. As you draw each thumbnail, save the position in the queue.

I think if you spent the time to get that working as desired, you would have a product that’s much easier to maintain than ### image controls.

1 Like

Made it work without activeimage. What activeimage does is actually create regions around all images and deal with that. I’m quite happy with the solution :slight_smile:

Here’s how it looks:


Wow! Well done.

This is exactly what we need for a product list. The Sales Agent needs to send a photo a client and this will really help.

We would consider buying the source if!
Please contact me privately if you would consider?

you could use Mark Goldberg’s solution with images inside an image control but we found that problems can occur with positioning images Xpos and Ypos

another solution is to display the image controls over a list with the height of the list set to the height of the images to scroll…

as the list scrolls it scrolls your images but you run into the problem of when to hide the images into and out of view.

The help used to show an OCX solution for this but of course that wont show up if you use the new Internet solution from SV and the Anyscreen development group.

I’m rather happy with what I’ve done, works great, is dynamic regarding data etc. Only annoyance is when you scroll the images up and down, for some reason window flickers sometimes, no idea why or how to eliminate that…

it might be worth experimenting with prop:buffer if you haven’t already

for example:

myWindow{PROP:Buffer} = 1

Tried it. Values from 0 to 2, same. Slow scrolling is better, fast scrolling is much worse.

Just wrote Image Selector control using pure winapi and gdiplus. Not a Bostjan’s competitor, just an example.


Looks beautiful, I like it!

Wow! Looks awesome Mike!

Best regards