News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Destruction

Started by oex, March 01, 2012, 06:32:53 PM

Previous topic - Next topic

oex

No it's still an issue....

I can destroy the form in the WM_CREATE msg (Where I create the form) with the method below

But calling the destroy code in other messages such as WM_LBUTTONUP and WM_COMMAND -> BN_CLICKED will not remove the form....

      mov esi, FormFieldhWndPtrs
      .while DWORD PTR [esi]
         invoke DestroyWindow, [esi]
         add esi, 4
      .endw


OK.... Placing the following after the DestroyWindow code:

Fails
      invoke UpdateWindow, hWnd

Fails
      invoke InvalidateRect, hWnd, 0, TRUE
      invoke UpdateWindow, hWnd

Works
      invoke ShowWindow, hWnd, SW_HIDE
      invoke ShowWindow, hWnd, SW_SHOW

Can I do this without hiding and then reshowing the window?
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

jj2007

Peter,
It's almost impossible to find the solution without having the full code. One last attempt: SendMessage hWnd, WM_PAINT, 0, 0  ... brute force ::)

oex

OK I will pull it to pieces tomorrow and send the relevent sections.... The exe is 600Kb ASM app so it's rather complicated :lol.... I thought maybe it's just the order in which I call stuff or something....

I will make it an independant app tomorrow, the section with the issues is pretty small
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

dedndave

when you get the desired button click in the parent window, execute this...
        INVOKE  SendMessage,hEditControl,WM_SYSCOMMAND,SC_CLOSE,NULL

that should cause the default processing to prepare for closing, and send a WM_CLOSE message
when you receive the WM_CLOSE message in the Edit Control WndProc, execute this...
        INVOKE  DestroyWindow,hWnd
        xor     eax,eax
        ret

(hWnd from WndProc parms should now be same as hEditControl)

MichaelW

#19
I didn't have time to try this with an application window, but with a dialog it works as expected:

;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================
    .data
    .code
;==============================================================================
DlgProc proc hwndDlg:dword, uMsg:dword, wParam:dword, lParam:dword
    SWITCH uMsg
      CASE WM_INITDIALOG
      CASE WM_COMMAND
          .IF WORD PTR wParam+2 == BN_CLICKED
              invoke DestroyWindow, lParam
              add wParam, 1000
              invoke GetDlgItem, hwndDlg, wParam
              invoke DestroyWindow, eax
          .ENDIF
      CASE WM_CLOSE
        invoke EndDialog, hwndDlg, 0
    ENDSW
    xor eax, eax
    ret
DlgProc endp
;==============================================================================
start:
;==============================================================================
    Dialog "Test", "MS Sans Serif",10, \
           WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
           16,0,0,103,112,1024
    ID=1000
    Y=0
    REPEAT 8
        Y=Y+10
        DlgButton "X",WS_TABSTOP,10,Y,10,10,ID
        DlgEdit  WS_BORDER,30,Y,60,10,ID+1000
        ID=ID+1
    ENDM
    invoke GetModuleHandle, NULL
    CallModalDialog eax,0,DlgProc,NULL
    exit
;==============================================================================
end start


And now I have determined that it also works as expected in an application window.

;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================
    .data
        hWnd      HWND        0
        hInst     HINSTANCE   0
        wcx       WNDCLASSEX  <>
        msg       MSG         <>
        posx      dd          0
        posy      dd          0
        className db          "test_class",0
    .code
;==============================================================================
WindowProc proc hwnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    LOCAL rc:RECT
    SWITCH uMsg
      CASE WM_CREATE
        ID=1000
        Y=0
        REPEAT 8
          Y=Y+25
          invoke CreateWindowEx,0,chr$("BUTTON"),chr$("X"),
                                WS_CHILD or WS_VISIBLE or WS_TABSTOP,
                                25,Y,25,25,hwnd,ID,0,NULL
          invoke CreateWindowEx,WS_EX_CLIENTEDGE,chr$("EDIT"),0,
                                WS_CHILD or WS_VISIBLE or \
                                ES_AUTOHSCROLL or ES_NOHIDESEL,
                                75,Y,160,25,hwnd,ID+1000,0,NULL
          ID=ID+1
        ENDM
      CASE WM_COMMAND
          .IF WORD PTR wParam+2 == BN_CLICKED
              invoke DestroyWindow, lParam
              add wParam, 1000
              invoke GetDlgItem, hwnd, wParam
              invoke DestroyWindow, eax
          .ENDIF
      CASE WM_CLOSE
        invoke DestroyWindow, hwnd
      CASE WM_DESTROY
        invoke PostQuitMessage, NULL
      DEFAULT
        invoke DefWindowProc, hwnd, uMsg, wParam, lParam
        ret
    ENDSW
    return 0
WindowProc endp
;==============================================================================
start:
;==============================================================================
    invoke GetModuleHandle, NULL
    mov hInst, eax
    mov wcx.cbSize,        SIZEOF WNDCLASSEX
    mov wcx.style,         CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
    mov wcx.lpfnWndProc,   OFFSET WindowProc
    mov wcx.cbClsExtra,    NULL
    mov wcx.cbWndExtra,    NULL
    push hInst
    pop wcx.hInstance
    mov wcx.hbrBackground, COLOR_BTNFACE + 1
    mov wcx.lpszMenuName,  NULL
    mov wcx.lpszClassName, OFFSET className
    invoke LoadIcon, NULL, IDI_APPLICATION
    mov wcx.hIcon, eax
    invoke LoadCursor, NULL, IDC_ARROW
    mov wcx.hCursor, eax
    mov wcx.hIconSm, 0
    invoke RegisterClassEx, addr wcx
    WW = 260
    WH = 280
    invoke GetSystemMetrics, SM_CXSCREEN
    shr eax, 1
    sub eax, WW / 2
    mov posx, eax
    invoke GetSystemMetrics, SM_CYSCREEN
    shr eax, 1
    sub eax, WH / 2
    mov posy, eax
    invoke CreateWindowEx,  0,
                            ADDR className,
                            chr$("Test"),
                            WS_VISIBLE or WS_OVERLAPPED or WS_SYSMENU,
                            posx, posy, WW, WH,
                            NULL, NULL,
                            NULL, NULL
    mov   hWnd, eax
    invoke ShowWindow, hWnd, SW_SHOWDEFAULT
    invoke UpdateWindow, hWnd
  msgLoop:
    invoke GetMessage, addr msg, NULL, 0, 0
    .IF eax != 0
        invoke IsDialogMessage, hWnd, addr msg
        .IF eax == 0
            invoke TranslateMessage, addr msg
            invoke DispatchMessage, addr msg
        .ENDIF
        jmp   msgLoop
    .ENDIF
    exit msg.wParam
;==============================================================================
end start


Note that both versions have a problem with the Escape key. Since the message loop calls IsDialogMessage, pressing the Escape key causes a BN_CLICKED notification with the control ID value of IDCANCEL to be sent to the window procedure, and the third button gets deleted. I did not try to determine how whatever window handle was sent with the IDCANCEL BN_CLICKED notification could cause this, because I can't see how this could have any bearing on the behavior I am trying to test.

eschew obfuscation

oex

Sorry to not post all the code in a working example before....

This application doesnt quit properly (only closes the window, cant think what I have missed) however it shows the problem without too much added bs....
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

qWord

there are several issues:
- DefWindowProc is called at wrong place
- there is no background brush specified -> that is why InvalidateRect doesn't work
- PostQuitMessage is commonly used while handling WM_CLOSE
- WM-DESTROY is used to free resources
( - do not send WM_CLOSE explicit)
( - ExitProcess missing)
FPU in a trice: SmplMath
It's that simple!

oex

 :bdg yes a rush job also doesn't help.... I will check your post now q, cheers
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

MichaelW

Just setting the hbrBackground member of WNDCLASSEX will solve the primary problem. You can tell that there is problem with the background update by the transparent background and by dragging the window partially outside the desktop and dragging it back.
eschew obfuscation

oex

Yep perfect, thanks guys....!

This windows stuff is all new to me
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv