Announcement

Collapse
No announcement yet.

GfxCtl Subclass

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • GfxCtl Subclass

    Been quite a while since I've subclassed a graphic control. The following does not appear to be catching mouse events although previous usage of the modifications of the subclass routine works. Don't understand why.

    Thanks in advance.

    Code:
    #COMPILE EXE
    #DEBUG ERROR ON
    #DEBUG DISPLAY ON
    
    #INCLUDE "WIN32Api.inc"
    
    DEFLNG I - N
    
    %GFX  = 100
    %DLGMESS = %WM_USER + 500
    
    TYPE Mouse_Struct
      X               AS LONG
      Y               AS LONG
    END TYPE
    
    TYPE MouseBtn_Struct
      Lbd             AS BYTE
      Lbu             AS BYTE
      Rbd             AS BYTE
      Rbu             AS BYTE
    END TYPE
    
    TYPE Handle_Struct
      MainDlg         AS DWORD
      GfxCtl          AS DWORD
      OrgCb           AS DWORD
    END TYPE
    
    GLOBAL tMouse   AS Mouse_Struct
    GLOBAL tMb      AS MouseBtn_Struct
    GLOBAL tHndls   AS Handle_Struct
    
    FUNCTION PBMAIN () AS LONG
    
    DIALOG NEW PIXELS, 0, "subclass", , , 200, 200, %WS_OVERLAPPEDWINDOW TO tHndls.MainDlg
    
    DIALOG SHOW MODAL tHndls.MainDlg, CALL PbMain_CB()
    
    END FUNCTION
    
    '----------------------------------------------------------------------------------------
    '----------------------------------------------------------------------------------------
    
    CALLBACK FUNCTION PbMain_CB() AS LONG
    
    LOCAL Hndl  AS DWORD
    
    LOCAL Xs, _
          Ys    AS LONG
    
    Hndl = CBHNDL
    
    SELECT CASE CBMSG
      CASE %WM_INITDIALOG
        DIALOG GET CLIENT Hndl TO Xs, Ys
        CONTROL ADD GRAPHIC, Hndl, %GFX, "", 0, 0, Xs, Ys
        CONTROL HANDLE Hndl, %GFX TO tHndls.GfxCtl
        GRAPHIC ATTACH tHndls.GfxCtl, 0
        GRAPHIC CLEAR 0
        DIALOG POST Hndl, %DLGMESS, 0, 0
        FUNCTION = 1
        EXIT FUNCTION
    
      CASE %DLGMESS
        CALL SetPoint()
    
    END SELECT
    
    END FUNCTION
    
    '----------------------------------------------------------------------------------------
    '----------------------------------------------------------------------------------------
    
    FUNCTION GfxSubClass(BYVAL Hndl AS DWORD, BYVAL Msg AS LONG, BYVAL wParam AS LONG, _
             BYVAL lParam AS LONG) AS LONG
    
    LOCAL MainCb AS DWORD
    
    MainCb = tHndls.OrgCb
    
    SELECT CASE Msg
      CASE %WM_MOUSEMOVE
        MSGBOX "move"
    END SELECT
    
    FUNCTION = callwindowproc(MainCb, Hndl, Msg, wParam, Lparam)
    END FUNCTION
    
    '----------------------------------------------------------------------------------------
    '----------------------------------------------------------------------------------------
    
    SUB SetPoint()
    
    GRAPHIC ATTACH tHndls.GfxCtl, 0
    GRAPHIC LINE (0, 0) - (200, 200), %RED
    
    tHndls.OrgCb = setwindowlong(tHndls.GfxCtl, %GWL_WNDPROC, CODEPTR(GfxSubClass))
    DIALOG DOEVENTS
    
    DO
      DIALOG DOEVENTS
      IF ISWIN(tHndls.MainDlg) = 0 THEN EXIT DO
    LOOP
    END SUB
    
    '----------------------------------------------------------------------------------------
    '----------------------------------------------------------------------------------------
    Added:

    It appears that by changing:
    tHndls.OrgCb = setwindowlong(tHndls.GfxCtl, %GWL_WNDPROC, CODEPTR(GfxSubClass))

    to :

    tHndls.OrgCb = setwindowlong(tHndls.MainDlg, %GWL_WNDPROC, CODEPTR(GfxSubClass))

    the subclass works, but I'm not subclassing the gfxctrl, but it's parent which produces coordinate problems.

    Last edited by Walt Decker; 15 Apr 2018, 01:27 PM. Reason: add information
    Walt Decker

  • #2
    Your Graphic control needs %SS_NOTIFY to capture the mouse.

    CONTROL ADD GRAPHIC, Hndl, %GFX, "", 0, 0, Xs, Ys, %WS_CHILD OR %WS_VISIBLE OR %SS_OWNERDRAW OR %SS_NOTIFY

    Comment


    • #3
      Thanks, Stuart. I knew it was something simple, just could not see it. Getting old I guess.
      Walt Decker

      Comment

      Working...
      X