No announcement yet.

SubClassing Window from Dialog

  • Filter
  • Time
  • Show
Clear All
new posts

  • SubClassing Window from Dialog

    I have subclassed controls before and they have worked fine,
    but for some reason this subclass of an entire window from
    a dialog is not working. The modal dialog calls the window
    and it draws successfully, but when it closes, the dialog
    callback is still disabled, so the program cannot resume.
    I'm re-setting the callback to the previous callback, but I
    think it is going to the main wndproc instead of the dialogproc.
    Anyone ever had this problem? I can't find any documentation
    that says you can't subclass a window from a modal dialog, yet
    it isn't working. I've included a simple shell of what I'm
    doing below; anybody see a reason why it wouldn't return control
    to the dialog callback?

    Jim Seekamp

    global hbrks&

    style&=%ws_popup or %ws_visible or %ws_caption or %ws_sysmenu or %ws_maximizebox or %ws_minimizebox

    hwnd&=createwindow(wclassname,_ ''window class name
    wcaption,_ ''window caption
    style&,_ ''window style
    0,_ ''initial x position
    0,_ ''initial y position
    640,_ ''initial x size
    480,_ ''initial y size
    htakeoff&,_ ''parent window handle
    %null,_ ''window menu handle
    hinstance&,_ ''program instance handle
    %null) ''creation parameters


    showwindow hwnd&,%sw_show
    updatewindow hwnd&
    end sub

    function brkproc(byval hwnd&,byval msg&,byval a&,byval xparam&) as long

    select case msg&
    case %wm_paint
    dim ps as paintstruct
    ''drawing takes place successfully here
    deletedc hdc&
    exit function
    case %wm_syscommand

    if lowrd(a&)=%sc_close then
    destroywindow hwnd&
    exit function
    end if

    case %wm_destroy
    setwindowlong hwnd&,%gwl_wndproc,hbrks&
    exit function
    end select

    end function

    Jim Seekamp
    Jim Seekamp

  • #2
    Jim -
    what about inserting additional line
    after Case %WM_DESTROY before setwindowlong (I mean first of all to supply standart processing)



    • #3
      In your CallWindowProc() line, you should be passing the original windows procedure's address (hbrks&) rather then an explicit CODEPTR().

      As Semen points out, you should let the %WM_DESTROY message flow through to CallWindowProc(), so remove the EXIT FUNCTION from that handler.

      Also, try it without the dialog as the parent of the window, but explicitly disable and reenable the dialog by program control instead.

      If you are still having problems, post a complete compilable example of the proble code.

      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      mailto:[email protected]