The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Neil on May 14, 2008, 06:46:07 AM

Title: Remove controls from main window
Post by: Neil on May 14, 2008, 06:46:07 AM
How do you remove a control from a main window i.e. a subclassed edit box. I assume it must be something like invoke close, handle etc. I can't find an API function that does this.
Title: Re: Remove controls from main window
Post by: jj2007 on May 14, 2008, 07:41:46 AM
Sendmessage WM_CLOSE
alternatively, ShowWindow SW_HIDE
Title: Re: Remove controls from main window
Post by: MichaelW on May 14, 2008, 08:45:01 AM
Sending a WM_CLOSE message or calling DestroyWindow will work, with no apparent problems and without having to unhook the subclass procedure. ShowWindow with nCmdShow set to SW_HIDE will deactivate the window and hide it, but not actually remove it.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      hInstance   dd 0     
      oldEditProc dd 0
      hWndEdit    dd 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
EditProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
    invoke CallWindowProc, oldEditProc, hWnd, uMsg, wParam, lParam
    ret
EditProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
DlgProc proc hDlg:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
    SWITCH uMsg
      CASE WM_INITDIALOG
        invoke GetDlgItem, hDlg, 1000
        mov hWndEdit, eax
        invoke SetWindowLong, hWndEdit, GWL_WNDPROC, EditProc
        mov oldEditProc, eax
      CASE WM_COMMAND
        SWITCH wParam
          CASE IDCANCEL
            invoke EndDialog, hDlg, 0
          CASE IDOK
            ;invoke SendMessage, hWndEdit, WM_CLOSE, 0, 0
            ;invoke DestroyWindow, hWndEdit
            invoke ShowWindow, hWndEdit, SW_HIDE
            invoke Sleep, 1000
            invoke ShowWindow, hWndEdit, SW_SHOW
        ENDSW           
      CASE WM_CLOSE
        invoke EndDialog, hDlg, 0
    ENDSW
    return 0
DlgProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
    invoke GetModuleHandle, NULL
    mov hInstance, eax

    Dialog "Test","MS Sans Serif",8,WS_OVERLAPPEDWINDOW, \
            2,5,5,80,60,1024
    DlgEdit WS_BORDER or WS_VSCROLL or ES_AUTOVSCROLL or ES_MULTILINE \
            or ES_WANTRETURN or WS_TABSTOP,5,8,70,30,1000
    DlgButton "OK",WS_TABSTOP or BS_DEFPUSHBUTTON,25,45,30,10,IDOK
    CallModalDialog hInstance,0,DlgProc,NULL

    invoke ExitProcess, 0
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

Title: Re: Remove controls from main window
Post by: Neil on May 14, 2008, 12:29:05 PM
Thanks for your help. That was a very comprehensive explanation MichaelW I shall try it out in my code. :U
Title: Re: Remove controls from main window
Post by: Neil on May 14, 2008, 12:45:22 PM
Tried the code out both

             invoke SendMessage, hWndEdit, WM_CLOSE, 0, 0
                                &
             invoke DestroyWindow, hWndEdit

work OK. Is there any advantage of using one or the other. Or do the both do the same thing?
Title: Re: Remove controls from main window
Post by: MichaelW on May 15, 2008, 12:05:52 AM
Either can be used to destroy the window.  DestroyWindow (http://msdn.microsoft.com/en-us/library/ms632682(VS.85).aspx) is more direct and easier to call, but sending a  WM_CLOSE (http://msdn.microsoft.com/en-us/library/ms632617(vs.85).aspx) notification would probably be preferable where your WM_CLOSE handler is set up to notify the user and/or prompt for confirmation.
Title: Re: Remove controls from main window
Post by: Neil on May 15, 2008, 07:26:42 AM
Thanks MichaelW, I'll keep those facts in mind for future use.