Hi,
Im writing a program that takes screen shots at user determined intervals for a number of seconds (that way you can change frame rates), after each screen shot a new MDI child is loaded and the picture placed inside the image box on the form. When the set number of seconds is up, i want the MDI parent to go through each Child Form in the order it was created and save the image contained within the form, close it, and move on to the next form.

The problem is getting the forms in the order of creation then closing it (i know how to save the images when i can get the window containing the image i want to save).

So... how do i get each of the Child Forms in the order created(i dont mean arranging the workspace,) and then close them one at a time?

Thankyou.

U can store the hwnds of the Child forms as they are created in an array. Later u can go through the array and close/manipulate them from the MDI.

hmmm, that might just work... Ill give it a try

Or in a couple of arrays, that are in sync with each other, 1 for the hwnd's and 1 for a time stamp and then you can enumerate them by time stamp.

Is the second array necessary ? if the hwnds are appended sequentially, they should be sorted by time. If you need the exact time when they were loaded, then of course you need the second array for the time stamp.

they SHOULD be in the same order they are loaded into the array, yes. So you're right, it's not necessary.... I do a lot of array sorting, so in my mind I'm thinking about it in a future proof scenario.

I have done some array sorting but in this case its not needed and i dont need time stamps, because the array should be in the correct order.

How do I set an active MDI Child,I tried using SetActiveWindow API but it didnt work, is there a VB command for this?

it wouldnt happen to be SetFocus(hwnd)?

<ChildformName>.setfocus

All that did was create a blank Child and set focus, i want to set focus by handle

To set focus to a particular form whose hwnd is mhwnd ( you can get the value from the array) u can use in MDI form

Dim f as form
For Each f in forms
     If f.hwnd = mhwnd then
          f.show
          f.setfocus
          exit for
      end if
next

so then i just nead to run a loop to change mhwnd?

You run the loop to iterate through the Child forms. When u find the form you are looking for (matching hwnds), you stop. Since you are using an array, this seems to be the simplest way to me

i need to go through all of the elements one at a time so this should work.

Dim f as form 
for counter = 0 to ubound(HwndArray())
mhwnd=HwndArray(counter)
For Each f in forms
If f.hwnd = mhwnd then
f.show
f.setfocus
'Do my code
f.unload
exit for
end if
next
next counter
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.