Link to home
Start Free TrialLog in
Avatar of kulikuli
kulikuli

asked on

destroy/close childwindow

I am using MS Access and the SetParent API call. I use SetParent to make a window (it actually is an executing mpg-file that was executed by mcisendstring function) the child of MS Access MDI.
At this point everything is ok. BUT: when I close MS Access while the mpg-file is still running, then MS Access closes indeed but short after that an MS Access fatal exception error is displayed.

I suspect this to be the result of the mci-object trying to continue to play while the window already has been closed (along with MS Access being its parent).

I need to know how I can properly close the childwindow. However, after the window becomes a child of MS Access, I can't find the hwnd using FindWindow function. So I don't know how to close/destroy it. Any suggestions?

Best regards,
kulikuli
Avatar of waty
waty
Flag of Belgium image

Before the call of SetParent, store the HWND of the future window child. When you close your application, send a WM_Close message to close the child.
Avatar of kulikuli
kulikuli

ASKER

hwnd property might be subjected to changes. Since it is an index-like identification the property is not guaranteed to contain the same value
Where did you see that the hwnd could change? The Hwnd will change only if you destroy and recreate the window. So long your window will stay alive, your Hwnd will stay valid an will identify this window.
ASKER CERTIFIED SOLUTION
Avatar of Mirkwood
Mirkwood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Waty, this behavior is documented in several Help-files (in the MS Access helpfile for sure, but I believe it also is in the VB Help-file)
Mirkwood, I'll try your solution. However, I may need some an example. As I take a quick look at the API, I wonder how to get the child window since I don't know the hwnd property.
First do a findwindow to find the Access main window.
Now do a findwindowex to find the MDI child.

Here is a sample that finds the edit box inside internet explorer.

   hwndexpl = FindWindow("IEFrame", 0)   ' Find Internet Explorer
    hwndsizerebar = FindWindowEx(hwndexpl, 0,   "SizableReBar", "")    ' Find the sizable rebar toolbar control
    hwndrebar = FindWindowEx(hwndsizerebar, 0, "ReBarWindow32", "") ' Find the rebar toolbar control
    hwndcomboex = FindWindowEx(hwndrebar, 0, "ComboBoxEx32", "")  ' Find the extended combobox control on the toolbar
    hwndcombo = FindWindowEx(hwndcomboex, 0, "ComboBox", "")  ' Find the combobox control with the extended combo
    hwndedit = FindWindowEx(hwndcombo, 0, "Edit", "") 'Find the editbox within the combobox

I seem required to know 1 more thing: How can I retreive the class name and does the class name change after it has become a child?
No a class name of a window never expires. The class name is defined when a window is created during design time and will always be the same.
So use a utility like spy32.

I can give u the following class names.
The access main window class is "OMain"
The mdi window name is "MDIClient"
And the database windows is "ODb"
It took me a lot of time to retreive spy32 from the Internet. Now that I got it: it seems to be a utility to monitor users' actions. It seems to me it is more like an administrator tool on a network. How should it be used for a purpose like retreiving the class name of a window?
I got spy32.zip from the net. When I take a look at its readme.txt file it says this software is called 'Omnicad Desktop Serveillance 98'. I got some feeling I got the wrong file (about 5 meg). If this is the wrong file, could you send me in the right direction to find the correct one?

Best regards,
kulikuli
Spy is a microsoft product. So the microsoft site is a good starting point.
I received the C++ Spy program in my email box. I suppose it was you who sent it (the email identity differs from your experts-identity). Thank you very much. I will go after the controls you asked for. Of course I'll grade you Excellent.

Best regards,
me