Announcement

Collapse
No announcement yet.

SubClassing worked for me in 8 but not 9

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

  • Richard Angell
    replied
    Good you remembered Dave. I'd forgot about Steve's post. But that is what I was talking about my last post.

    Leave a comment:


  • Dave Biggs
    replied
    CM
    Looks like the change that is affecting your code may have occured after PBWin803. See this post by Steve Rossell... http://www.powerbasic.com/support/pb...ad.php?t=35337
    Capturing mouse and keyboard messages from a graphic control or window in PBWin 8.04
    In PBWin 8.03 and previous versions of PBWin 8, you could subclass the graphic window and capture
    these messages, there was a change in PBWin 8.04, where you must subclass the static control on the
    graphic window to capture these messages.
    Here's an example of subclassing the child static control based on the sample code that you posted..
    Code:
    #COMPILE EXE
    #REGISTER NONE
    #DIM All
    #Include "win32API.inc"
     
    TYPE position
      origin As POINTAPI
    END TYPE
     
    GLOBAL gOldSubClassProc As DWORD
    GLOBAL patch1, patch2 As Position
    '------------------/
     
    FUNCTION PBMAIN () AS LONG
     LOCAL hWin, hGFX AS DWORD
     
      GRAPHIC WINDOW "Test", 100, 100, 400, 200  TO hWin
      GRAPHIC ATTACH hWin???, 0
     
      hGFX = GetWindow(hWin, %GW_CHILD)     ' NB "Graphic Window" is a dialog with a child static class built in
     
    'here's how I subclass the graphics window so it can intercept mouse messages
      gOldSubClassProc = SetWindowLong(hGFX, %GWL_WNDPROC, CODEPTR(SubClassProc))
     
      While IsWindow(hWin)
        Dialog DoEvents 1
      Wend
     
    END FUNCTION
    '------------------/PBMain
     
    'here's my subclass function
    FUNCTION SubClassProc(BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
     
        'process our messages in this subclass procedure
        SELECT CASE wMsg
            CASE %WM_LBUTTONDOWN
     
                CALL POILeft(GetParent(hWnd))   ' MOD - SubClassProc hWnd = handle to child control so..
     
            CASE %WM_RBUTTONDOWN
     
                CALL POIRight(GetParent(hWnd))  ' MOD
     
        END SELECT
     
        'pass the message on to the original window procedure...the DDT engine!
        FUNCTION = CallWindowProc(gOldSubClassProc, hWnd, wMsg, wParam, lParam)
     
    END FUNCTION
    '------------------/SubClassProc
     
    'here's a function to report the point of interest
    FUNCTION POIleft(BYVAL hWnd AS LONG) AS LONG
     
        DIM title AS STRING
     
        'see where the mouse is now
        GetCursorPos patch1.origin
        'and return its pozLeft in terms of the graphic window's client area
        ScreenToClient(hWnd, patch1.origin)
     
        DIALOG GET TEXT hWnd TO title
        DIALOG SET TEXT hWnd, "AVI "+FORMAT$(patch1.origin.x,"000") + ", " + FORMAT$(patch1.origin.y,"000")+";"+REMAIN$(title, ";")
     
    END FUNCTION
    '------------------/POIleft
     
    'another function to report the point of interest
    FUNCTION POIright(BYVAL hWnd AS LONG) AS LONG
     
        DIM title AS STRING
     
        'see where the mouse is now
        GetCursorPos patch2.origin
        'and return its pozLeft in terms of the graphic window's client area
        ScreenToClient(hWnd, patch2.origin)
     
        DIALOG GET TEXT hWnd TO title
        DIALOG SET TEXT hWnd, EXTRACT$(title,";")+";"+FORMAT$(patch2.origin.x,"000") + ", " + FORMAT$(patch2.origin.y,"000")
     
    END FUNCTION
    '------------------/POIright

    Leave a comment:


  • Richard Angell
    replied
    I seem to recall that one needs to subclass the graphic control of the graphic window in order to insert other message traps in the processing. Some time ago I seem to recall some of the same for Graphic Controls in this forum.

    The Graphic Window itself is a container window with a child graphic control. This allows it to hide its PB callback. Sometime back, I remember that several of us posted some code in the PBCC forum, perhaps here as well showing how this is done. At the moment I'm not sure where I might have it, but a search on GRAPHIC WINDOW and looking about 2 - 3 years back might find one of the posts.

    Leave a comment:


  • Rodney Hicks
    replied
    Thanks for that response Richard, I was pretty sure that was the situation regarding the GRAPHIC WINDOW as opposed to a GRAPHIC CONTROL, but I had no certain knowledge.
    The drawback with the GRAPHIC WINDOW CLICK appears to be that it does not do both the right and left button, which seems to be required.

    Leave a comment:


  • Richard Angell
    replied
    C.M.

    Are you using a Graphic Control or is it a Graphic Window? In PBWin 9, GRAPHIC WINDOW CLICk was added for Graphic Windows, but is not applicable to Graphic Controls. The Graphic Window default, hidden support handles the clicks and mouse X,y now.

    Leave a comment:


  • Gary Beene
    replied
    Here's a working example, to compare to your code. I took the sample app and deleted all but the important stuff.

    Code:
    #Compile Exe
    #Dim All
    #Include "ComDlg32.inc"
    Global OldGraphicProc As Dword, hDlg As Dword
    
    Function PBMain () As Long
      Dim hGraphic As Dword
      Dialog New 0, "Subclass Text", , , 301, 224,%WS_Caption Or %WS_SysMenu, 0 To hDlg
      Control Add Graphic, hDlg, 500,"", 4, 4, 202, 182, %SS_Notify, %WS_Ex_ClientEdge
      Control Handle hdlg, 500 To hGraphic
      OldGraphicProc = SetWindowLong(hGraphic, %GWL_WNDPROC, CodePtr(GraphicProc))
      Dialog Show Modal hDlg
    End Function
    
    Function GraphicProc (ByVal hWnd As Dword, ByVal wMsg As Dword, ByVal wParam As Dword, ByVal lParam As Long) As Long
      Select Case wMsg
          Case %WM_LButtonDown : MsgBox "down"
          Case %WM_LButtonUp   : MsgBox "up"
      End Select
      Function = CallWindowProc (OldGraphicProc, hWnd, wMsg, wParam, lParam)
    End Function

    Leave a comment:


  • Gary Beene
    replied
    Oh yes, I knew I was forgetting something. If you just want the stn_clicked message, you don't have to subclass. the ss_notify lets it come in under the main callback under WM_COMMAND.

    Code:
        CallBack Function dlgproc
            If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Hi(Word,Cb.WParam) = %STN_Clicked Then
               Control Set Text hDlg, 102, "Click"
            End If
        End Function
    But the sample I mentioned shows responding to mouse up/down/move with subclassing.
    Last edited by Gary Beene; 13 May 2009, 12:51 PM.

    Leave a comment:


  • Rodney Hicks
    replied
    PBWin 9.0 added a 'GRAPHIC WINDOW CLICK' statement which may have something to do with why the PBWin 8.x code doesn't work the way it did before.
    GRAPHIC WINDOW CLICK [hwin&] TO click&, x!, y!
    The mouse position is assigned to the x!, y!
    It checks for click or double click, but there is no designation regarding the left or right button.
    Page 411 in the Manual!

    Leave a comment:


  • Gary Beene
    replied
    Here's a PBWin9 subclassing example that came with PB. I tried it and it works - includes clicking on the graphic control.

    \pbwin\samples\ddt\graphic\pwrpaint\pwrpaint.bas

    Leave a comment:


  • Gary Beene
    replied
    And, did you use the %ss_notify style? I don't have v8 to know if it was required then.

    From Help:
    %SS_NOTIFY
    Send %STN_CLICKED and %STN_DBLCLK notification messages to the Callback Function when the user

    Leave a comment:


  • Gary Beene
    replied
    It's not obvious to me just yet - can you post a short compilable to test?

    Leave a comment:


  • C.M. Rouleau
    started a topic SubClassing worked for me in 8 but not 9

    SubClassing worked for me in 8 but not 9

    Hello,

    Recompiled some code with 9, and now it doesn't work completely. Basically, the problem is I had a graphics window that one could click in, and the mouse position would be reported. It's not doing that anymore. As you can see below, I've included the subclass function, how I subclass the graphics window, and the two functions that are called when the left or right mouse buttons are pressed. Any thoughts on why all this worked in 8 and not 9?

    -CMR

    Code:
    'here's my subclass function
    FUNCTION SubClassProc(BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
    
        'process our messages in this subclass procedure
        SELECT CASE wMsg
            CASE %WM_LBUTTONDOWN
    
                CALL POILeft(hWnd)
    
            CASE %WM_RBUTTONDOWN
    
                CALL POIRight(hWnd)
    
        END SELECT
    
        'pass the message on to the original window procedure...the DDT engine!
        FUNCTION = CallWindowProc(gOldSubClassProc, hWnd, wMsg, wParam, lParam)
    
    END FUNCTION
    
    
    'here's how I subclass the graphics window so it can intercept mouse messages
    gOldSubClassProc = SetWindowLong(hGFX, %GWL_WNDPROC, CODEPTR(SubClassProc))
    
    
    'here's a function to report the point of interest
    FUNCTION POIleft(BYVAL hWnd AS LONG) AS LONG
    
        DIM title AS STRING
    
        'see where the mouse is now
        GetCursorPos patch1.origin
        'and return its pozLeft in terms of the graphic window's client area
        ScreenToClient(hWnd, patch1.origin)
    
        DIALOG GET TEXT hWnd TO title
        DIALOG SET TEXT hWnd, "AVI "+FORMAT$(patch1.origin.x,"000") + ", " + FORMAT$(patch1.origin.y,"000")+";"+REMAIN$(title, ";")
    
    END FUNCTION
    
    'another function to report the point of interest
    FUNCTION POIright(BYVAL hWnd AS LONG) AS LONG
    
        DIM title AS STRING
    
        'see where the mouse is now
        GetCursorPos patch2.origin
        'and return its pozLeft in terms of the graphic window's client area
        ScreenToClient(hWnd, patch2.origin)
    
        DIALOG GET TEXT hWnd TO title
        DIALOG SET TEXT hWnd, EXTRACT$(title,";")+";"+FORMAT$(patch2.origin.x,"000") + ", " + FORMAT$(patch2.origin.y,"000")
    
    END FUNCTION
Working...
X