Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

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
0
kulikuli
Asked:
kulikuli
  • 6
  • 4
  • 2
1 Solution
 
watyCommented:
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.
0
 
kulikuliAuthor Commented:
hwnd property might be subjected to changes. Since it is an index-like identification the property is not guaranteed to contain the same value
0
 
watyCommented:
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.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
MirkwoodCommented:
Use findwindowex. FindWindowEx allows you to find within a parent window.
In  your case first find the Access window and then find your child window. Use the Access window handle as parameter hwnd1.
Make sure that the classname of the window is right.


Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

0
 
kulikuliAuthor Commented:
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.
0
 
MirkwoodCommented:
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

0
 
kulikuliAuthor Commented:
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?
0
 
MirkwoodCommented:
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"
0
 
kulikuliAuthor Commented:
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?
0
 
kulikuliAuthor Commented:
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
0
 
MirkwoodCommented:
Spy is a microsoft product. So the microsoft site is a good starting point.
0
 
kulikuliAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now