Solved

destroy/close childwindow

Posted on 1998-11-04
12
303 Views
Last Modified: 2010-04-30
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
Comment
Question by:kulikuli
  • 6
  • 4
  • 2
12 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1443106
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
 
LVL 5

Author Comment

by:kulikuli
ID: 1443107
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
 
LVL 14

Expert Comment

by:waty
ID: 1443108
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Accepted Solution

by:
Mirkwood earned 40 total points
ID: 1443109
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
 
LVL 5

Author Comment

by:kulikuli
ID: 1443110
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
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1443111
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
 
LVL 5

Author Comment

by:kulikuli
ID: 1443112
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
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1443113
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
 
LVL 5

Author Comment

by:kulikuli
ID: 1443114
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
 
LVL 5

Author Comment

by:kulikuli
ID: 1443115
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
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1443116
Spy is a microsoft product. So the microsoft site is a good starting point.
0
 
LVL 5

Author Comment

by:kulikuli
ID: 1443117
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question