URGENT: Hidden form snapshot

alvifarooq
03-28-2003, 05:47 AM
hi guys...

this is rather urgent cause i gotta complete this project for office...
i have two forms B and C and a main form A. B and C have some simulation works running on them...

What I want to do is to create two small pictureboxes on form A and then possibly display whatever is going on in form B and C on this main form.

At present I am trying to get a snapshot of form B and C and then display them in reduced manner on the main form in the pictureboxes. This I can update at different instants to keep up with the simulation works. However, I cannot get a snapshot with the ususal bitbil and other functions unless form B and form C are displayed on the screen.

Is there a way to get a snapshot when these forms could be invisible while loaded or better yet unloaded!

Otherwise, is there a way that I can somehow display these forms on the mian page in the picturebox or any other control in a reduced manner? This would be a much better alternative...

Please advice!

Farooq.

Machaira
03-28-2003, 06:43 AM
If the forms are invisible there's nothing to get a snapshot of. Obviously when the forms are unloaded there's also nothing to get a snapshot of.

You can display the forms inside a picturebox using the SetParent API call. When you're done looking at the form, use SetParent to take it out of the picturebox:

'Put these in a module
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long

'This goes in form1
Dim lOldParent As Long

Private Sub Command1_Click()
lOldParent = GetParent(Form2.hwnd)
SetParent Form2.hwnd, Picture1.hwnd
Form2.Left = 0
Form2.Top = 0
Form2.Show
End Sub

Private Sub Command2_Click()
SetParent Form2.hwnd, lOldParent
End Sub

Private Sub Form_Load()
Load Form2
End Sub

Hope this helps.

alvifarooq
03-28-2003, 07:34 AM
man...u're a God sent...

it works like a charm...exactly what I wanted...better than the screenshot thing...

any idea how I can resize the child form (form2)...inside the picture box...I want to make it smaller so that I can fit two pictureboxes in form1...

plus when I press command button 2...the picturebox is cleared but then form2 pops up separately...although there is no form2.show there...how come?

Thanks again...like a zillion...

Regards,

Farooq.

Machaira
03-28-2003, 08:22 AM
You can set the Height and Width of form2 or call the form's Move method, although you'll have to handle moving or resizing the controls on the form, either through your own code or third party code/controls. The call to SetParent to remove the form from the picturebox doesn't need another call to Form2.Show since the form is already shown, it merely needs to change the parent of the form from the picturebox to the desktop. The Form2.Show is in the first command button's Click event since the form isn't initially shown, just loaded. You could replace the line:

Load Form2

with:

Form2.Show

and take that line out of the Click event.

alvifarooq
03-28-2003, 11:24 AM
hi...

thanks for the reply Machaira...I was working with this and I saw something that isn't exactly what is supposed to happen...

see this is the situation...form 2 or form 3 or...which are child forms have to be individual forms and i should have like instances of these forms or dupliates showing in form 1.

The software I am workin on is a Visual Factory software where simulation on form2 and form 3 will be displayed on two separate screens and on a controller screen I will have form1 with duplicates of form2 and form3 shown in pictureboxes...

However...duplicates is not such a nice word since what I want is like a picture of those two...I don't wanna use up too much memory and make separate form2 and form3 to be displayed on form1...

u think i can handle that with this method...?

Thanks...
Farooq

Merlin Sythove
03-30-2003, 12:48 PM
I have no shortcuts here - I would go for Form.AutoRedraw = true, paint whatever I need on the form itself (possibly behind existing controls). I've used a true prepared picture of a form as the Form.Picture in some cases as well, so all the controls are already on the form.picture itself. This won't work if the form can be resized or the controls can move position.
Then copy the Form.Image to another image control which of course will do the resizing if you need to. Or use PaintPicture to copy and resize it to a picture box. You won't have a title bar like this though, but you can do everything with an invisible form.

Weird guess - can Form.Print be redirected to a picturebox.hdc?? I guess Form.Print won't work if the form is not visible. Can't check it at the moment.

If you only need like a progress bar that actually changes, I would go another way. Create a true picture (BMP or GIF etc) of the form you want to show in advance, and use that in the image control that is to show the form working in progress. Just put a progress bar on top of the image control manually (Controlled by the hidden form).

If the form will be shown before being hidden, you can take a snapshot of the screen and copy the form like that.

All rather a lot of work though!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum