Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

API DestroyWindow doesn't destroy my window 1

Status
Not open for further replies.

DirkVFP

Programmer
Aug 25, 2005
57
NL
With the following code I detect the presence of a window (MyWindow) and if it exists I try to destroy it. MyWindow is created using DO FORM ".\forms\MyWindow"

Code:
DECLARE INTEGER FindWindow IN user32;
    STRING lpClassName,;
    STRING lpWindowName
    
DECLARE INTEGER DestroyWindow IN user32;
    INTEGER hWnd
    
n = FindWindow(.NULL., "MyWindow")

IF n > 0 THEN 
    x = DestroyWindow(n)
ENDIF

x is > 0, however, I put a messagebox in the MyWindow's destroy event and that doesn't fire. It only fires when I manually close the form, or when I exit my VFP7 environment.

I'm forgetting something, but I don't know what!
 

Dirk,

You mention MyWindow's Destroy event. That suggests that MyWindow is a Visual FoxPro form. Is that right?

If so, why do you want to destroy it in this way? Why not just call its Release method? The Windows API doesn't know anything about VFP methods, so there's no reason for the Destroy to fire.

If MyWindow is not a VFP form, then it cannot have a VFP Destroy method.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

Thanks again for the quick reply :)
MyWindow is indeed a VFP form.

The situation is like this: I have a main form, from which the user can open all kinds of other forms (search a record, edit a record etc.). These are all VFP forms and may only be openened once. If they are already open I use the SetForegroundWindow API function to display it.

These forms can be lurking underneath my main form, and when the user closes the main form I just want all underlying forms to be closed, in the way I showed in the opening post.

I'm just wondering how to call the MyWindows' Release method when I opened it with DO FORM? Probably it's my Foxpro knowledge lacking, but using DO FORM I do not have any handle/reference to the new form.

Dirk
 
VFP forms are not "real" Windows Forms, so you cannot use DestroyWindow to remove your form. Try using this.

Code:
DO FORM myForm Name myForm1

Now you can reference your form's release with

Code:
myForm1.release()

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Thanks Mike,

This works fine!

VFP forms are not "real" Windows Forms, so you cannot use DestroyWindow to remove your form.
I guess I need to read up on how Foxpro handles these forms, might prevent me next time from asking questions here ;-)

Dirk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top