Results 1 to 3 of 3

Thread: Totally stumped, please help!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2000
    Location
    Denver
    Posts
    265

    Totally stumped, please help!

    I'm stumped! Here's what happens...I click my "go" menu to create a new instance of a form (in this case an MDIChild) and populate it with the controls in a frame that is on another form in the dll I'm referencing. (toward the end of the menu's sub I add the references that obj and objWind hold to a collection for use later on....)

    Code:
    Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    
    Private Sub mnugo_Click()
        Dim obj As Object
        Dim objWind As Object
        Dim tForm As frmChild
        
        Set obj = CreateObject("myProject.myClass")
        Set objWind = obj.getwindow
        Set tForm = New frmChild
        
        Call SetParent(objWind.hwnd, tForm.hwnd)
        
        mColObj.Add obj
        mColObjWind.Add objWind
        
        Set pluginwindow = Nothing
        Set plugin = Nothing
        Set tForm = Nothing
    End Sub
    This part works just fine...it does EXACTLY what I want it to...
    But when I close the form (after having called the DestroyWindow API to remove the references to the controls in the dll) and then try to click the "go" menu again, it doesn't work. No errors occurr, but when the "SetParent" API is called, (which normally returns the hWnd of the dll form's frame via objWind.hwnd), no hWnd value is returned. The value is just 0, and the MDIChild form isn't populated with anything...

    I can't figure out for the life of me why this is. If you have any ideas at all please let me know. I can post more code...and more detailed code... if you need, just say so

    Thanks!

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2000
    Location
    Denver
    Posts
    265
    *Sigh*

  3. #3
    jim mcnamara
    Guest
    Use can the
    Set whatever = Nothing syntax.

    But it doesn't work in the client the way you think. It actually calls the destructor for the class to do the dirty work.

    1. In the destructor for your class you need to call
    SendMessage(hWnd,WM_QUIT) then WM_DESTROY for all the windows you created (controls are mostly windows, except VB labels which you can ignore).

    2. Call EnumChildWindows for the parent form to get all the hWnds so you can WM_DESTROY them one by one

    The reason this all bombs is that you have WndProcs for windows that no longer exists - still in memory. You have to get the window(control) to kill itself. VB controls do that when you do a set .###. = Nothing. You apparently are not doing that. Since 98% of your code isn't here, this is what I'm assuming is going on.

    Note this from MSDN You don't have to mess with WM_NCDESTROY:

    WM_NCDESTROY
    The WM_NCDESTROY message informs a window that its nonclient area is being destroyed. The DestroyWindow function sends the WM_NCDESTROY message to the window following the WM_DESTROY message. WM_DESTROY is used to free the allocated memory object associated with the window. <<-- note!

    The WM_NCDESTROY message is sent after the child windows have been destroyed. In contrast, WM_DESTROY is sent before the child windows are destroyed.

    A window receives this message through its WindowProc function.

    LRESULT CALLBACK WindowProc(
    HWND hwnd, // handle to window
    UINT uMsg, // WM_NCDESTROY
    WPARAM wParam, // not used
    LPARAM lParam // not used
    );
    Parameters
    [/quote]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width