Announcement

Collapse
No announcement yet.

New to Pbcc40

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

  • New to Pbcc40

    I am just starting to use pbcc40 to update a dos version of a program. Since I don't want to reinvent the wheel does somebody have some code the I could copy to handle the mouse in pbcc?
    Thanks in advance.
    Jack Jasperson
    Jack Jasperson

  • #2
    if you use inkey$ or waitkey$ mousex/mousey will give you coordinates of the mouse cursor.

    See inkey$ in the help for the values related to buttons if the variable is 4 characters long (indicates mouse event)

    So, it's much easier than using a call interrupt for example.

    If you already have routines for the mouse, you can substitute the pbcc statements for the values previousely used.
    Last edited by Fred Buffington; 20 Jul 2009, 03:08 PM.
    Client Writeup for the CPA

    buffs.proboards2.com

    Links Page

    Comment


    • #3
      Don't forget to use MOUSE ON first. That one's got me a couple of times.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        and Mouse buttons,DOUBLE,UP/DOWN to trap double clicks
        example: MOUSE 3, DOUBLE, DOWN

        Note: the buttons are not the number of buttons on the mouse
        but rather have a meaning. 3=left and right. See Mouse in help
        Last edited by Fred Buffington; 21 Jul 2009, 02:02 PM.
        Client Writeup for the CPA

        buffs.proboards2.com

        Links Page

        Comment


        • #5
          It makes a difference whether you want to use the mouse in the console window or in a graphic window.
          Fred's and Michael's replies refer to the use of the mouse in a console window.
          PBCC 5 also supports the use of the mouse in a graphic window, but PBCC 4 does not.
          However it is very well possible to use the mouse in a graphic window with PBCC 4 using a technique that is called subclassing.
          I once posted a set of screen handlers that demonstrate this at http://www.powerbasic.com/support/pb...ad.php?t=36795

          Arie Verheul

          Comment


          • #6
            I've been using PBCC5 for a while now and still haven't found a good way to read a key or mouse event at the same time.

            Graphic Waitkey$ solves all the key issues, but no mouse read.

            All the mouse read functions like
            Graphic Window Click To Click&, xx!, yy!
            work, but get held up by waitkey

            I still need a function that will detect any mouse movement, click, or key press.

            Comment


            • #7
              >I still haven't found a good way to read a key or mouse event at the same time.
              ???

              They don't happen at the same time.

              You get one, you handle it. You get the other, you handle it.

              ???

              I think you might want INKEY instead of WAITKEY.. WAITKEY 'works as advertised' and WAITS UNTIL A KEY is hit.

              Maybe you need something like INKEY which returns immediately...
              Code:
               
               IF INKEY = NO KEY THEN 
                   Check for mouse click 
                   ....
              .. or something like that.

              I am NOT a CC guy leave alone a CC "GRAPHICS" guy but I have to believe someone has written CC-GRAPHICS code which can handle keys and/or mouses at the same time.

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

              Comment


              • #8
                Doug:

                You posted a question on the same subject on May 2nd. 2009, and I posted a code for you in reply. Does'nt it work?

                Comment


                • #9
                  Not to hijack his thread...

                  Yes Manuel. I was looking for something simpler - maybe there is not!

                  I think Michael's answer may send me back to your code.

                  "They don't happen at the same time.

                  You get one, you handle it. You get the other, you handle it."

                  That's not the way I learned to program (I'm too linear).

                  I was using Graphic Waitkey$ to get input, but also wanted to know if a mouse event occured. The Inkey is most likely the answer. I wrote a routine to try that, but the screen flashes at the input point and I may be hogging computer resource.

                  It just seems like it would be simpler, but maybe not.

                  It would have to continuously scan for mouse or keyboard input. Would you need to release the procedure on each pass?

                  Comment


                  • #10
                    >That's not the way I learned to program (I'm too linear).

                    Everyone coming from MS-DOS is too linear at first.

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

                    Comment


                    • #11
                      Detecting mouse in a graphic window with PB/CC

                      You have to use a bit of subclassing to make it work.

                      Here is the way to do it :

                      Code:
                      #COMPILE EXE
                      #BREAK ON
                      #CONSOLE OFF
                      #DEBUG ERROR ON                 ' Remove in final version
                      #INCLUDE "Win32Api.inc"
                      DEFLNG a-z
                      GLOBAL GrDialogProc AS LONG
                      GLOBAL GrStaticProc AS LONG
                      GLOBAL mx AS LONG,my AS LONG    ' Mouse x and y
                      GLOBAL lb AS LONG,rb AS LONG    ' Left and right mouse button
                      GLOBAL mm AS LONG               ' Detect mouse movements
                      GLOBAL bg AS LONG,fg AS LONG    ' Background and foreground colors
                      GLOBAL wm AS LONG,mb AS LONG    ' Wheel mouse and middle button
                      GLOBAL TabKey AS INTEGER        ' Detect Tab Key
                      
                      FUNCTION GrDlgProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                      FUNCTION = CallWindowProc(GrDialogProc, hWnd, wMsg, wParam, lParam)
                      END FUNCTION
                      
                      FUNCTION GrProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                        LOCAL p AS pointapi
                        SELECT CASE wMsg
                          CASE %WM_CHAR
                            car%=LO(WORD,wParam): IF car%=9 THEN TabKey%=9       ' Tab Key not caught by GRAPHIC INKEY$
                          CASE %WM_MOUSEMOVE
                            mm=1: mx=LO(WORD,lParam): my=HI(WORD,lParam)         ' Current Mouse X and Y Position in the graphic window
                          CASE %WM_LBUTTONDOWN
                            lb=1: FUNCTION=0: EXIT FUNCTION                      ' Left button pressed
                          CASE %WM_RBUTTONDOWN
                            rb=1: FUNCTION=0: EXIT FUNCTION                      ' Right button pressed
                          CASE %WM_MBUTTONDOWN
                            mb=1: FUNCTION=0: EXIT FUNCTION                      ' Middle button pressed
                          CASE %WM_MOUSEWHEEL
                            wm=HI(WORD,wParam): IF wm>32768 THEN wm=-1 ELSE wm=1 ' Wheel turned (+)=up (-)=down
                            FUNCTION=0: EXIT FUNCTION
                        END SELECT
                       FUNCTION = CallWindowProc(GrStaticProc, hWnd, wMsg, wParam, lParam)
                      END FUNCTION
                      Put that code before your PBMAIN() and you will even enjoy the wheel mouse also.
                      If you want a complete program check on my GRAPHIC CONSOLE post

                      http://www.powerbasic.com/support/pb...7&d=1232064938

                      http://www.powerbasic.com/support/pb...6&d=1232064915
                      Last edited by Guy Dombrowski; 22 Jul 2009, 07:18 PM.
                      Old QB45 Programmer

                      Comment


                      • #12
                        Doug:

                        Thanks for your reply. Regarding your concern about hijacking Jack’s thread, hopefully this subject is of general interest, including him if he eventually gets some interest in PBCC5’s GRAPHIC WINDOW.

                        Risking to be too obvious, two points are very important: First, the option “REDRAW” when you start with a graphic window, and second, to enclose the sequence within a loop whose exit is granted only for a key press OR a mouse click (the program is waiting for user’s action).

                        Code:
                         
                        [SIZE=3][FONT=Calibri]DO[/FONT][/SIZE]
                        [SIZE=3][FONT=Calibri]      GRAPHIC INKEY$ TO CH$[/FONT][/SIZE]
                        [SIZE=3][FONT=Calibri]      GRAPHIC WINDOW CLICK TO clk&, xm!, ym![/FONT][/SIZE]
                        [SIZE=3][FONT=Calibri]      IF CH$<>"" OR clk& THEN EXIT LOOP[/FONT][/SIZE]
                        [SIZE=3][FONT=Calibri]LOOP[/FONT][/SIZE]
                        This way nothing happens until one of the two events occurs. You can monitor the use of resources in the meanwhile, and you will see that it’s OK.

                        I have just released a program (2,500 lines of code) using frequently the same statements and I haven’t noticed what you point out. You can also check out a code I posted in the Source Code section named Color Display Applet .

                        Even though I got encouraged to work in PBCC’ GRAPHIC WINDOW because of Guy Dombrosky’s posts on the subject, I prefer not to use the #INCLUDE "Win32Api.inc" statement. In my opinion to detect the mouse moving, or the mouse wheel action is not really necessary for a good program.

                        With all due respect for Michael Mattias, whose professorship in my opinion is highly appreciated by everybody, I have to admit my preferences for the “procedural programming” instead of the “event driven programming”.
                        Last edited by Manuel Valdes; 22 Jul 2009, 09:26 PM.

                        Comment


                        • #13
                          Well, there is another way to solve the immediate problem...

                          Eschew the Console with/without the GRAPHICS WINDOW functions for the user interface and use 'conventional' windows/dialogs and drawing functions.

                          If you don't want to get into SDK-Style window/dialog management, you can license the PB/Windows compiler to obtain access to the 'DDT' syntax.

                          Using a standard GUI window/dialog pretty much forces you into the 'event-driven' programming style.....

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

                          Comment


                          • #14
                            Well.... I am merely a caveman programmer, but this works for me.

                            I used Manuel's simple approach ... though I reserve the right to read the scroll wheel etc. at some future date (given the right amount of inspiration).

                            (This is incomplete as I'm not using all the keys - it's just to get what I want.)

                            Code:
                            Function ikeys(w1%,mox&,moy&)As Integer
                            Local i$,ink%,ink2%,clk&,xm!,ym!                         'w1% is for later (advanced mouse functions)  
                            Do 
                             Do   
                                  Sleep 0                                            'keep the loop from overusing resource
                                  Graphic INKEY$ To i$
                                  Graphic Window Click To clk&, xm!, ym!
                                  If i$<>"" Or clk& Then Exit Loop                   'one or the other
                             Loop 
                             
                                ink2=Asc(Left$(i$,1)):ink=Asc(Right$(i$,1))
                                If ink<>ink2 Then ink=ink+300                        'move special keys to 300 range
                                If ink >= 97 And ink <= 122 Then ink = ink - 32      'take out if you need lowercase as well
                                         'Graphic Set Pos (10,0)
                                         'Graphic Print Len(i$);ink;ink2;clk&;xm!;ym!
                                         'Graphic ReDraw                             'only in to view keys hit and mouse position
                               Select Case ink                                       'only keep the keys I want
                               Case -1:mox&=xm!:moy&=ym!
                               Case 8,9,13,27,32                                     'used keys   
                               Case 44,43,45,46,48 To 57,61                          'numbers and operators 
                               Case 39,91,93,96,123,125                              'other used keys
                               Case 65 To 90                                         'letters  
                               Case 371,372,373,375,377,379,380,381,382,383          'the arrows moved to the 300 level
                               Case 359 To 368:ink=ink+42                            'f1 to f12 moved to 401-412
                               Case 387,388:ink=ink+24
                               Case 1 to 26:ink=200+ink                              'ctrl a,b,c etc. moved to 201,202, etc.
                               Case Else:ink=0
                               End Select      
                               If ink Then Exit Loop
                            Loop
                             ikeys=ink
                            End Function
                            Last edited by Doug Ingram; 23 Jul 2009, 12:40 PM.

                            Comment

                            Working...
                            X