Announcement

Collapse
No announcement yet.

scope of GRAPHIC ATTACH

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

  • Chris Holbrook
    replied
    Got an answer from PowerBasic Inc today, I have not yet tried the remedy suggested, I'm still trying to understand out how it all works.

    Hi Chris,

    You need to subclass the dialog and static control. A graphic window is actually a Window with a static control on it. Some messages are sent to the static control and some are sent to the parent (window). Try subclassing both and see if this fixes the problem.

    Sincerely,
    Jeff Daniels
    PowerBASIC Staff

    Leave a comment:


  • Chris Holbrook
    started a topic scope of GRAPHIC ATTACH

    scope of GRAPHIC ATTACH

    Please could GW experts give me a sanity check on this before I bother PowerBasic Inc with it?

    Quoth the F1 help for GRAPHIC ATTACH:

    This statement chooses a graphic target. All further graphic operations will be directed to this target until another GRAPHIC ATTACH or GRAPHIC DETACH statement is executed, or the graphic target is deleted. All PowerBASIC graphical displays are persistent -- they will be automatically redrawn even if minimized or temporarily covered by another window.
    Yet if I GRAPHIC ATTACH a GW then subclass it and attempt to, say, GRAPHIC BOX on it from the subclass proc or a function called from it, the GW is blank - unless I have included a GRAPHIC ATTACH statement in the subclass proc etc. Changing the scope of the GW handle to GLOBAL does not seem to make much difference - I mean, I don't think that the scope of the ATTACHment is the same as the scope of the window handle.

    OK - this could be cruelty to GRAPHIC WINDOWS - or flagrant mixing of DDT and SDK styles - but it would be nice to know what the specific rules are for GRAPHIC ATTACH, or indeed where to find them, if not in the online help.

    Also, is there a downside to re-attaching a GW? Any special handling required when closing the GW?

    Just in case I have completely misread the situation - it has happened - here is some some code to show what I mean. If you comment out the GRAPHIC ATTACH in the "drawit" SUB, nothing is shown.

    Code:
    ' to investigate scope of GRAPHIC ATTACH
    ' Chris Holbrook 13 Dec 2008
    
    #compile exe
    #dim all
    #include once "win32api.inc"
    
    global GrDialogProc as long               ' used in subclassing the grapic control to get mouse msgs
    global GrOldProc as long                  ' used in subclassing the grapic control to get mouse msgs
    global currentrect as rect
    global hWin, hGW as dword
    '--------------------------------------------------------------------------------
    function GrProc(byval hWnd as dword, byval wMsg as dword, byval wParam as dword, byval lParam as long) as long
        static startpt, endpt as pointAPI
        static htimer as long
    
      select case wMsg
         '
         case %wm_mousemove
             if wparam and %MK_LBUTTON then ' we're dragging
                endpt.X = lo(word,lParam)
                endpt.Y = hi(word,lParam)
                drawit(startpt, endpt)
                startpt = endPT
             end if
        '
        case %wm_lbuttondown
            startpt.X = lo(word,lParam)
            startpt.Y = lo(word,lParam)
        '
        case %wm_lbuttonup
            startpt.X = 0: startpt.Y = 0
        '
      end select
     function = CallWindowProc(GrOldProc, hWnd, wMsg, wParam, lParam)
    
    end function
    '----------------------------------------------------------------------
    sub drawit ( startpt as pointapi, endpt as pointapi)
        local colour as long
        
        colour = %black
        offsetrect currentrect, endpt.X - startpt.X , endpt.Y - startpt.Y
        ? currentrect.nleft, max(70, currentrect.ntop),currentrect.nright, currentrect.nbottom
        graphic attach hwin, 0, redraw
        graphic box (0, 70) - (500, 500), 0, -2, -1, 0
        graphic box (currentrect.nleft, max(70, currentrect.ntop))-(currentrect.nright, currentrect.nbottom),0,colour,-2,0
        graphic redraw
    end sub
    '-----------------------------------------------------------------------------------
    function pbmain () as long
        local skey as string
    
        ' Create and show a Graphic window on screen
        graphic window "", 450, 130, 500, 500 to hWin
    
        graphic attach hWin, 0, redraw
        hGW = GetWindow(hWin, %GW_CHILD) ' Retrieve hWnd of graphic window
    
        ' Subclass the Graphic control
        GrOldProc = SetWindowLong(hGW, %GWL_WNDPROC, codeptr(GrProc))
    
        setrect currentrect, 100, 70, 250, 250
        'lastpt = gMousePt
        graphic print "to investigate scope of GRAPHIC ATTACH by Chris Holbrook 13-DEC-2008"
        graphic print "drag a box on a GRAPHIC WINDOW"
        graphic print "start with cursor in the graphic window(this one)"
        graphic print "Use the mouse with left button down to drag it"
        graphic print "<Esc> to exit"
        graphic redraw
        ' main program loop
        ' wait for the punter to press ESC then exit
        ' let the subclass proc do the work
        do
            skey = ""
            graphic inkey$ to skey
            if skey$ = $esc then exit loop
            sleep 50
        loop
    
        SetWindowLong(hGW, %GWL_WNDPROC, GrOldProc) ' remove subclassing
        graphic window end
    
    end function
Working...
X