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.
Sendmessage WM_CLOSE
alternatively, ShowWindow SW_HIDE
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
Thanks for your help. That was a very comprehensive explanation MichaelW I shall try it out in my code. :U
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?
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.
Thanks MichaelW, I'll keep those facts in mind for future use.