Announcement

Collapse
No announcement yet.

About mouse usage

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

  • About mouse usage

    Hi, basically all I know how to do in QuickBasic is use the statements, functions, etc.
    What I do is import sections of code from other programs if I don't understand how to
    accomplish something. I now have PB/CC 4.04, however I can't or don't know how to use the built in mouse stuff without the console. Is there any easy way to use the mouse?

  • #2
    Originally posted by Joshua Winn View Post
    Is there any easy way to use the mouse?
    If you want to be able to detect both left and right clicks, double clicks and do drag operations, you will need to subclass the GRAPHIC WINDOW (see e.g. recent examples in this forum from Guy Dombrowski).

    This code deals with (some)keypresses, single and double clicks, mouseovers and drag operations in the subclass routine. Instead of calling functions it calls methodes of members of an array of objects so is not much good with V4 compiler! But it may give you ideas...

    Code:
    '--------------------------------------------------------------------------------
    function GrProc(byval hWnd as dword, byval wMsg as dword, byval wParam as dword, byval lParam as long) as long
        local p as pointapi
        static LClickTime as dword
        static wlx as long
        local dw as dword
        local i, j, bestz, besti as long
        local r as RECT
    
      select case wMsg
        case 0 ' special case - initialisation. winlet index set to -1
            if hWnd = 0 then
                select case wparam
                    case 0
                        wlx = -1
                        for i = 0 to ubound(Wl): ? i, Wl(i).ControlType: next
                end select
            end if
            exit function ' do NOT pass the event on to the classproc
         '
         case %wm_char
             if wlx <> -1 then
                 WL(wlx).CtlKeypress(wparam)
             else
                 if wparam = 27 then gFormStatus = %PBFCLOSEME
             end if
         '
         case %wm_keyup
             if wlx <> -1 then
                 select case wparam
                     case %VK_RIGHT, %VK_LEFT, %VK_UP, %VK_DOWN
                         WL(wlx).CtlKeypress(wparam or 128)
                 end select
             end if
    
         '
         case %wm_mousemove
            gMouseMoved = %TRUE
            gMouseX = lo(word,lParam)
            gMouseY = hi(word,lParam)  ' Current Mouse X and Y Position in the graphic window
            if gLBDOWN then
                if wlx <> -1 then
                    if WL(wlx).WLDragSizemode <> 0 then
                        WL(wlx).drawdrag
                    else
                        Wl(wlx).startdrag
                    end if
                end if
            else
                i = getCtlatPoint(gmouseX, gmouseY)
                if i <> -1 then ' the mouse was over a winlet
                    '?"p:mouseover=", i
                    WL(i).mouseover(%true, gmouseX, gmouseY)
                    for j = 0 to ubound(WL)
                        if j <> i then WL(j).mouseover(%false, 0, 0)
                    next
                else ' the mouse was not over a winlet
                    for i = 0 to ubound(WL)
                        '?"p:mouseover<>";, i
                        WL(i).mouseover(%false, 0, 0)
                    next
                end if
            end if
            exit function
        '
        case %wm_lbuttondown
            gMouseX = lo(word,lParam)
            gMouseY = hi(word,lParam)         ' Current Mouse X and Y Position in the graphic window
            gLBDOWN = 1
            exit function                      ' Left button pressed
        '
        case %wm_lbuttonup
            glbdown = 0
            dw = lclicktime xor gettickcount ' double-click detection
            if dw < 500 then  ' it is a double click
                lclicktime = 0
                i = getctlatpoint(gMouseX, gMouseY) ' get ctl index in wlx
                if i = -1 then ' clicked outside any winlet
                    'if a winlet is currently selected, unselect it
                    if wlx <> -1 then
                        if WL(wlx).selected then
                            WL(wlx).unselect
                            wlx = -1
                            exit function
                        else
                            exit function
                        end if
                    end if
                else
                    if wlx <> -1 then
                        WL(wlx).unselect
                    end if
                    wlx = i
                    WL(wlx).WLselect
                    WL(wlx).dblclick
                    exit function
                end if
            else              ' not a double click
                if wlx <> -1 then
                    if Wl(wlx).WLDragSizeMode then  ' end of a drag
                        WL(wlx).enddrag
                        lclicktime = 0
                        exit function
                    end if
                end if
                ' so it's just a click
                ' find the window with the highest Z position
                ' which underlies the current mouse position
                i = getctlatpoint(gMouseX, gMouseY) ' get ctl index in wlx
                if i = -1 then ' clicked outside any winlet
                    'if a winlet is currently selected, unselect it
                    if wlx <> -1 then
                        if WL(wlx).selected then
                            WL(wlx).unselect
                            wlx = -1
                            exit function
                        else
                             exit function ' ignore clickuot if no winlet selected
                        end if
                    end if
                else
                    if WL(i).ControlType = %PBFCloseme then
                        WL(i).showcloseicon(2)
                        wlx = -1
                        gFormStatus = %PBFCLOSEME
                    else
                        if wlx <> -1 then WL(wlx).unselect
                        wlx = i
                        WL(wlx).makecurrent
                    end if
                end if' tell the subclassed GR window proc which winlet is selected
            end if
            lclicktime = gettickcount
            exit function
        '
        case %wm_rbuttondown
            gRBDOWN = 1
            exit function                      ' Right button pressed
        '
        case %wm_rbuttonup
            gLeftDoubleClick = %false
    
            gRBDOWN = 0
            exit function                      ' Right button pressed
    
      end select
        ' other messages are passed on to the Class Proc
     function = CallWindowProc(GrOldProc, hWnd, wMsg, wParam, lParam)
    
    end function
    Last edited by Chris Holbrook; 3 Dec 2008, 05:36 PM. Reason: speling!

    Comment


    • #3
      But Chris, with CC if you capture inkey$, and the len is 4 it means a mouse
      event.

      Check out
      Code:
      MOUSE 3,DOUBLE,UP (or DOWN)
      MOUSE ON
      while A$=""
      A$=inkey$
      wend
      IF LEN(A$)=4  THEN 'mouse event
        IF MID$(A$,3,1)=chr$(2)  then 'double click
        IF MID$(A$,3,1)=CHR$(1) THEN 'movement
        IF MID$(A$,3,1)=CHR$(4) THEN  'button press
              IF MID$(A$,4,1)=CHR$(1) THEN 'left button
              IF MID$(A$,4,1)=CHR$(2) THEN 'rightt button
      not complete, of course, just a snippet.
      .
      .
      Client Writeup for the CPA

      buffs.proboards2.com

      Links Page

      Comment


      • #4
        Mouse use without Console

        Joshua

        If you want to use the mouse without console, you should upgrade to CC5 as you will have some new commands like GRAPHIC INKEY$ to better control the inputs.

        See my post "Graphic Console" it does work quite well.
        Old QB45 Programmer

        Comment


        • #5
          >Is there any easy way to use the mouse?

          There is no elevator to success, there are only the stairs.
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Originally posted by Fred Buffington View Post
            But Chris, with CC if you capture inkey$, and the len is 4 it means a mouse event.
            Correct, I was only working with GRAPHIC WINDOWS in which the GRAPHIC stuff is a bit more restrictive with the mouse, you can't get it via GRAPHIC INKEY$. But the subclassing approach, being event-driven, has given me far smoother results than I got using the INKEY/WAITKEY to handle the mouse in non-GW applications, so I'm likely to stick with it.

            In a way using subclassing is counter-intuitive because of a) the novelty and b) the need for a more code to accomplish "unit result", but in my experience it allows a more efficient, event-driven, application to be developed, and there comes a point when this is necessary.

            For me at least, MCM has hit the nail on the head. The "easy way" INKEY$ gives (at least in my hands) less pleasing results than the apparently more difficult way, subclassing.

            Comment


            • #7
              Another option

              In addition to the above, the screenhandler code i posted at http://www.powerbasic.com/support/pb...ad.php?t=36795 might provide some help.

              Arie Verheul

              Comment


              • #8
                Yuu don't need to use GRAPHIC WINDOWs with subclassing to get a nice screen with mouse action from PB/CC.

                Just create your screens either with CreateWindowEx or use the dialog functions CreateDialog and/or DialogBox.

                eg this demo: http://www.powerbasic.com/support/pb...ad.php?t=37555 and probably several others run "as is" with either PB/CC or PB.WIN. (That's kind of a 'thing' I like to do, make demo work with either compiler).

                (Note to self for "top ten things every PB programmer should know" : "How to use CreateWindowEx and the dialog functions CreateDialog and DialogBox to create screens 'SDK-style')

                MCM
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Come to think on it, nobody has asked what Joshua wants to do with the mouse.

                  Comment


                  • #10
                    Well, no he didn't, but I inferred he wanted to use it as a user input device. After all, that's the purpose for which it was invented.

                    I know, I know, I am far too naive to understand you younger people.......
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Is this the right example

                      Michael,

                      I am interested in your example, but the link you give points to code for "Directory list with non-ASCII charaters in file names", which uses the console in PBCC mode. Is this the example you meant ?

                      Arie Verheul

                      Comment


                      • #12
                        Yes it is. That code can be compiled and run 'as is' using either PB/CC or PB/Win.

                        I'm pretty sure some of my other demos work like that, too. (More would work with either compiler, but by popular request I started maybe two years ago to use "DDT" so those of course work only with PB/Windows).

                        The point being.... GRAPHICS WINDOW + Subclassing is not the only way to "to use the built in mouse stuff without the console. "

                        Of course in context, much depends on the meaning of "built in", but if Mr. Winn means the assorted "MOUSE xxxx" commands available in the PB/CC compiler, I did not want to be the one who had to tell him those only work with the console.

                        (Note to self for "List of Top Ten Things Every PB Progammer should Know:" "There's always more than one way to skin a cat.")

                        MCM
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Originally posted by Michael Mattias View Post
                          After all, that's the purpose for which it was invented.
                          smartass.

                          Originally posted by Michael Mattias View Post
                          ...you younger people...
                          Well, someone did call me "sonny" the other day - thanks, Mum!. But usually it's "grandpa".

                          Comment


                          • #14
                            Or Greatgrandpa for me LOL.
                            Client Writeup for the CPA

                            buffs.proboards2.com

                            Links Page

                            Comment

                            Working...
                            X