Announcement

Collapse
No announcement yet.

Destroy Mouse Pointer position

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

  • Lynn Wakefield
    replied
    Chris & Guy, Thanks for helping me out. Both your ideas fixed the problems for me!
    It's nice to have help when a semi-novice runs into trouble. Windows Graphics programming is another ball park, but I'm learning, slow but sure. Thanks again and the Best of luck to you, Lynn

    Leave a comment:


  • Guy Dombrowski
    replied
    Heavy CPU usage

    And, when using the INKEY$ command, it is important to keep the permanent graphics like your grid outside the loop that keep redrawing all the time.
    You should only redraw what has been changed.
    If done properly, a SLEEP 1 should be enough to do the job and keep the CPU usage low.

    Leave a comment:


  • Guy Dombrowski
    replied
    Logic problem

    Lynn,

    Chris is right

    If you replace CLICK with Aclick and then you add this line after the GRAPHIC WINDOW CLICK command :

    IF Aclick THEN PrintBoxFlag=0 else PrintBoxFlag=1

    The printing option will work every time

    Leave a comment:


  • Chris Holbrook
    replied
    Hm.

    Don't like using "language words" as variable names, so replace your long CLICK with ACLICK - that probably has no effect other than to please me!

    Test the value of ACLICK after the loop in which you get it, and skip all the code down to GRAPHIC INKEY$ at the bottom of your big DO loop if it is zero.

    I won't go into style points at length because a) it is personal and b) I haven't got all night, but you might find debugging a bit easier if you spelt out your conditional statements, using ENDIF a bit more and continuation characters a bit less.

    You are using LOTS of CPU in this program BTW! SLEEP 50 just before the GRAPHIC INKEY$ calmed it down quite a lot and shouldn't make it feel different. There is probably a better way of doing this.

    Leave a comment:


  • Lynn Wakefield
    replied
    Chris, click on the Print Puzzle, it will print the puzzle. Now click on Print Puzzle, it will not print it again.
    Lynn

    Leave a comment:


  • Chris Holbrook
    replied
    Lynn, thanks - I'm trying to relate the problem you reported to what I see on the screen when the application is running.

    What exactly do I have to do to invoke the problem?

    How will I recognize that it is happening?

    Leave a comment:


  • Lynn Wakefield
    replied
    Chris, here's the code:

    Code:
    #COMPILE EXE      'Sudoku_Graphic.bas       10/21/2008
    #BREAK ON
    #DIM ALL
    #CONSOLE OFF
    GLOBAL a,BNum,Block,CLICK,col,row,x,y,w,z,zz,zzz,PossNumToPrint AS LONG
    GLOBAL PrintFlag,Flag,Block(),Col(),Row(),PrintMouse,offset AS LONG
    GLOBAL BlockNum(),LoadFlag,PrintBoxFlag,SaveFlag AS LONG
    GLOBAL BoxNum(),i,PuzzleName,PossFinal(),Path_Location,Temp AS STRING
    GLOBAL n1(),n2(),n3(),n4(),n5(),n6(),n7(),n8(),n9() AS STRING
    GLOBAL NumStr(),FlagNum() AS STRING
    GLOBAL hWin AS DWORD
    DECLARE SUB MainProgram
    DECLARE SUB PrintScreen
    DECLARE SUB SoundBeepBeepBeep
    DECLARE SUB XprintMainBox
    DECLARE SUB LoadPuzzle
    DECLARE SUB SavePuzzle
     
    FUNCTION PBMAIN () AS LONG
        DIM BoxNum(1 TO 81) AS STRING
        DIM PossFinal(1 TO 81) AS STRING
        DIM BlockNum(1 TO 81) AS GLOBAL LONG
        PrintMouse = 1  '0 = Print off ROW,COL --- 1 = print on
        PrintFlag  = 1  '1 = Print to PDF  2 = Print to Choose  3 = Print to Default
        Path_Location = "\Program Files\SDK\"
        FOR z = 1 TO 81
            BlockNum(z) = CEIL(z/3 MOD z) MOD 3.1
            IF z > 27 THEN BlockNum(z) = BlockNum(z) + 3
            IF z > 54 THEN BlockNum(z) = BlockNum(z) + 4
        NEXT z
        'GRAPHIC WINDOW                                Horiz_start , Vert_start, Width, Height
        GRAPHIC WINDOW "Sudoku_Graphic.exe ---- Hit Escape to Quit", 0 , 0, 1015, 725  TO hWin
        GRAPHIC ATTACH hWin,0
        PrintScreen
        MainProgram
    END FUNCTION
    SUB MainProgram
        LOCAL BoxNum,BoxMain,CellCount,n,Spoty,Spotx,xx,yy AS LONG
        DIM Total(1 TO 9) AS LOCAL LONG
        DIM Block(1 TO 9),Col(1 TO 9),Row(1 TO 9) AS GLOBAL LONG
        DIM N1(1 TO 81),N2(1 TO 81),N3(1 TO 81) AS GLOBAL STRING
        DIM N4(1 TO 81),N5(1 TO 81),N6(1 TO 81) AS GLOBAL STRING
        DIM N7(1 TO 81),N8(1 TO 81),N9(1 TO 81) AS GLOBAL STRING
        DIM NumStr(1 TO 81) AS GLOBAL STRING
        FOR z = 1 TO 81 : BoxNum(z) = "" : NEXT z  '----- Set BoxNum() array to ""
        DO
            IF hWin = 0 THEN EXIT SUB
            GRAPHIC GET CLIENT TO x,y : IF x = 0 AND y = 0 THEN EXIT SUB
            PossNumToPrint = 0
            '(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
            IF PrintMouse = 1 THEN      '----------- Show location of mouse clicks
                GRAPHIC SET POS(1,115)  'col,row
                GRAPHIC FONT "Times New Roman", 10, 1
                GRAPHIC WINDOW CLICK hWin TO CLICK , y,x 'col,row
                GRAPHIC PRINT x;","y;"          "
                GRAPHIC SET POS(1,135)  'col,row
                GRAPHIC PRINT "Row,Col"
                GRAPHIC FONT "Times New Roman", 14, 1
            END IF
            ')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
            z = 0  '---------------------------------------- Get box number to set
            FOR w = 84 TO 884 STEP 100
                INCR z
                IF x >= 57 AND x <= 104 AND y >= w AND y <= w + 45 THEN _
                    BoxNum = z : EXIT FOR
            NEXT w
     
            '------------------------------------------------------- 'Set printer to . . .
            IF x >= 57 AND x =<  70 AND y >= 939 AND y <= 1009 THEN PrintFlag = 1   'PDF
            IF x >= 79 AND x =<  91 AND y >= 939 AND y <= 1009 THEN PrintFlag = 2  'Choose
            IF x >= 98 AND x =< 112 AND y >= 939 AND y <= 1009 THEN PrintFlag = 3   'Printer
            IF PrintFlag = 1 THEN GRAPHIC SET POS (940,55) : GRAPHIC PRINT "*"; ELSE GRAPHIC SET POS (940,55) : GRAPHIC PRINT "  ";
            IF PrintFlag = 2 THEN GRAPHIC SET POS (940,76) : GRAPHIC PRINT "*"; ELSE GRAPHIC SET POS (940,76) : GRAPHIC PRINT "  ";
            IF PrintFlag = 3 THEN GRAPHIC SET POS (940,96) : GRAPHIC PRINT "*"; ELSE GRAPHIC SET POS (940,96) : GRAPHIC PRINT "  ";
            IF y >= 485 AND y <= 528 AND x >= 8 AND x <= 47 THEN BoxNum = 10
            GRAPHIC SET POS(600,5)
            IF BoxNum > 0 AND BoxNum < 10 THEN GRAPHIC PRINT BoxNum;"      "
            IF BoxNum = 10 THEN GRAPHIC PRINT "Erase"
            GRAPHIC FONT "New Courier", 14, 1
             '-------------------------- Get BoxMain Number & location to print on grid
            z = 0 : BoxMain = 0
            IF BoxNum > 0 AND BoxNum < 11 THEN
                FOR xx = 150 TO 550 STEP 50  'ROW
                    FOR yy = 275 TO 675 STEP 50  'COL
                        INCR z
                        IF x > xx AND x < xx + 50 AND y > yy AND y < yy + 50 THEN _
                            Spotx = xx + 12 : Spoty = yy + 12 : BoxMain = z : _
                            BoxNum(BoxMain) = STR$(z) : EXIT FOR
                    NEXT yy                 'Spotx = ROW   Spoty = Col
                NEXT xx
            END IF
            '--------------------------------------------------------------- Erase Box
            IF BoxNum =10 AND BoxMain > 0 THEN GRAPHIC SET POS (Spoty,Spotx) : GRAPHIC PRINT "   " : _
                BoxNum(BoxMain) = ""
            IF BoxNum > 0 AND BoxNum < 10 THEN IF BoxMain > 0 THEN IF y >= 275_
                AND y <= 725 AND x >= 150 AND x <= 600 THEN GRAPHIC SET POS (Spoty,Spotx) :_
                    GRAPHIC PRINT BoxNum; : BoxNum(BoxMain) = STR$(BoxNum)
     
     
            '------row-------------------col-------------------------------- Load File
            IF x >= 7 AND x <= 48 AND y >= 182 AND y <= 230 AND LoadFlag = 0 THEN LoadPuzzle
            '------row-------------------col-------------------------------- Save File
            IF x >= 7 AND x <= 48 AND y >= 880 AND y <= 930 AND SaveFlag = 0 THEN SavePuzzle
    '        '-------------------------------------------------------------- Erase File
    '        IF MOUSEY >= 1 AND MOUSEY <= 5 AND MOUSEX >= 5 AND MOUSEX <= 11 THEN ErasePuzzle
            '-------------------------------------------------- Print Puzzle to Printer
            IF x >= 627 AND x <= 672 AND y >= 63 AND y <= 196 THEN IF PrintBoxFlag = 0 THEN XprintMainBox
            GRAPHIC INKEY$ TO i
        LOOP UNTIL i = $ESC
    END SUB
    SUB PrintScreen
        GRAPHIC WIDTH 3
        'GRAPHIC BOX (Upper Left horiz corner, Upper Left vert corner)
        '(Lower Right horiz corner, Lower Right vert corner)
        'GRAPHIC BOX (300, 150) - (723, 573),2
        GRAPHIC BOX (275, 150) - (725, 600),2
        'Graphic line (col,row)-(col,row)
        GRAPHIC LINE (425,600)-(425,150) 'Vert Line 3
        GRAPHIC LINE (575,600)-(575,150) 'Vert Line 6
        GRAPHIC LINE (275,300)-(725,300) 'Horiz line 3
        GRAPHIC LINE (275,450)-(725,450) 'Horiz line 6
        GRAPHIC WIDTH 1
        GRAPHIC LINE (325,600)-(325,150) 'Vert Line 1
        GRAPHIC LINE (375,600)-(375,150) 'Vert Line 2
        GRAPHIC LINE (475,600)-(475,150) 'Vert Line 4
        GRAPHIC LINE (525,600)-(525,150) 'Vert Line 5
        GRAPHIC LINE (625,600)-(625,150) 'Vert Line 7
        GRAPHIC LINE (675,600)-(675,150) 'Vert Line 8
        GRAPHIC LINE (275,200)-(725,200) 'Horiz line 1
        GRAPHIC LINE (275,250)-(725,250) 'Horiz line 2
        GRAPHIC LINE (275,350)-(725,350) 'Horiz line 4
        GRAPHIC LINE (275,400)-(725,400) 'Horiz line 5
        GRAPHIC LINE (275,500)-(725,500) 'Horiz line 7
        GRAPHIC LINE (275,550)-(725,550) 'Horiz line 8
        'Top boxes
        'GRAPHIC BOX (Upper Left horiz corner, Upper Left vert corner)
        '(Lower Right horiz corner, Lower Right vert corner)
        GRAPHIC BOX (81, 5) -  (131, 50),20
        GRAPHIC BOX (181, 5) -  (231, 50),20
        GRAPHIC BOX (481, 5) -  (531, 50),20
        GRAPHIC BOX (881, 5) -  (931, 50),20
        '             horiz,vert
        GRAPHIC SET POS (88,10)  : GRAPHIC PRINT "Erase"
        GRAPHIC SET POS (190,10)  : GRAPHIC PRINT "Load"
        GRAPHIC SET POS (488,10)  : GRAPHIC PRINT "Erase"
        GRAPHIC SET POS (544,10)  : GRAPHIC PRINT "Number ="
        GRAPHIC SET POS (885,10)  : GRAPHIC PRINT " Save"
        GRAPHIC SET POS (88,30)  : GRAPHIC PRINT " File"
        GRAPHIC SET POS (190,30)  : GRAPHIC PRINT " File"
        GRAPHIC SET POS (488,30)  : GRAPHIC PRINT " Num"
        GRAPHIC SET POS (885,30)  : GRAPHIC PRINT "  File"
        GRAPHIC FONT "Times New Roman", 10, 1
        GRAPHIC SET POS (941,10)  : GRAPHIC PRINT "Set Print"
        GRAPHIC SET POS (941,25)  : GRAPHIC PRINT "     To:"
        GRAPHIC SET POS (941,55)  : GRAPHIC PRINT "   PDF"
        GRAPHIC SET POS (941,75)  : GRAPHIC PRINT "   Choose"
        GRAPHIC SET POS (941,95)  : GRAPHIC PRINT "   Printer"
        y = 131
        FOR x = 1 TO 9
            GRAPHIC BOX (y - 50, 55) -  (y, 105),20
            y = y + 100
        NEXT x
        GRAPHIC SET POS (145,115)
        GRAPHIC FONT "Times New Roman", 12, 3  ' bold + Italic = (1+2)
        GRAPHIC PRINT "Esc to Quit --- Click on a number then click";
        GRAPHIC PRINT " on the Sudoku grid to place that number"
        GRAPHIC FONT "Times New Roman", 18, 1  'points=18,1 = bold
        FOR x = 1 TO 9  '      horiz,vert
            GRAPHIC SET POS (x * 100,63) : GRAPHIC PRINT TRIM$(STR$(x))
        NEXT x
        '------------------------------------------------ Print bottom boxes
        'GRAPHIC BOX (Upper Left horiz corner, Upper Left vert corner)
        '(Lower Right horiz corner, Lower Right vert corner)
        GRAPHIC BOX (60, 625) - (200, 675),2
        GRAPHIC BOX (220, 625) - (300, 675),2
        GRAPHIC BOX (301, 625) - (450, 675),2
        GRAPHIC BOX (470, 625) - (650, 675),2
        GRAPHIC BOX (670, 625) - (950, 675),2
        GRAPHIC FONT "Arial", 10, 1  '  1 = bold
        '             horiz,vert
        GRAPHIC SET POS (80,640) : GRAPHIC PRINT "Print Puzzle"
        GRAPHIC SET POS (240,640) : GRAPHIC PRINT "Print"
        GRAPHIC SET POS (340,630) : GRAPHIC PRINT "Solved"
        GRAPHIC SET POS (325,650) : GRAPHIC PRINT "Possibilities"
        GRAPHIC SET POS (485,640) : GRAPHIC PRINT "Print All 9 Numbers"
        GRAPHIC SET POS (725,630) : GRAPHIC PRINT "Print Possibilities &"
        GRAPHIC SET POS (720,650) : GRAPHIC PRINT "Puzzle on same page"
        GRAPHIC SET POS (250,675) : GRAPHIC PRINT "(1)               p%3B;nbsp;  (2)"
        GRAPHIC REDRAW
    END SUB
    SUB XprintMainBox       '-------------- Main box to printer
        LOCAL blocks AS LONG
         SoundBeepBeepBeep
        IF PrintFlag = 1 AND BNum = 0 THEN XPRINT ATTACH "PrimoPDF"
        IF PrintFlag = 2 AND BNum = 0 THEN XPRINT ATTACH CHOOSE
        IF PrintFlag = 3 AND BNum = 0 THEN XPRINT ATTACH DEFAULT
        XPRINT WIDTH 9
        'xprint line (col,row)  - (col,row)
        XPRINT BOX (1400,2070+BNum)  - (3520,4220+BNum) ' Box 2100 x 2100
        XPRINT LINE (1400,2790+BNum) - (3520,2790+BNum) 'horiz line 3
        XPRINT LINE (1400,3510+BNum) - (3520,3510+BNum) 'horiz line 6
        XPRINT LINE (2100,2070+BNum) - (2100,4220+BNum) 'vert line 3
        XPRINT LINE (2810,2070+BNum) - (2810,4220+BNum) 'vert line 6
        XPRINT WIDTH 2
        FOR row = 2070 TO 4220 STEP 240   '-------- Print horiz lines
            XPRINT LINE(1400,row+BNum) - (3520,row+BNum)
        NEXT row
        FOR col = 1400 TO 3520 STEP 235   '-------- Print vert lines
            XPRINT LINE (col,2070+BNum) - (col,4220+BNum)
        NEXT col
        'XPRINT FONT "New Courier",18,0          '1 = bold    '---- Print Numbers
        XPRINT FONT "Times New Roman",22,0       '1 = bold 0 = regular
        col = 0 : row = 0
        FOR z = 0 TO 72 STEP 9
            FOR blocks = 1 TO 9
                col = col + 235
                XPRINT SET POS (1240 + col, 2100 + row+BNum)
                XPRINT TRIM$(BoxNum(z + blocks))
            NEXT blocks
            row = row + 238 : col = 0
        NEXT z
        XPRINT WIDTH 2
        XPRINT FONT "New Courier",6,0
        XPRINT SET POS (3200,4250+BNum) : XPRINT PuzzleName;
        XPRINT CLOSE
        PrintBoxFlag = 1
    END SUB
    'File format:
    '--92--4-8
    '-4--9-6--
    '-2-4-8-9-
    '7----4---
    '2148-3-69
    '--------4
    '45238--76
    '--6-4----
    '3-1--684-
    SUB LoadPuzzle   '---------------------- Load from file & Print numbers to Grid
        LOCAL Dummy AS STRING
        DIM ADir AS STRING
        DIM Listing(1 TO 19) AS STRING
        SoundBeepBeepBeep
        GRAPHIC FONT "New Courier", 12, 1
        z = 153
        ADir = DIR$(Path_Location + "*.sdk")
        GRAPHIC SET POS (1,z) : GRAPHIC PRINT " 0= CANCEL * * * * * * * * * *"
        z = z + 23
        FOR w = 1 TO 19
            Listing(w) = ADir
            ADir = DIR$
            GRAPHIC SET POS (40,z) : GRAPHIC PRINT Listing(w)
            GRAPHIC SET POS (1,z)
            IF w > 9 THEN GRAPHIC PRINT TRIM$(STR$(w)) + "=" ELSE GRAPHIC PRINT " " + TRIM$(STR$(w)) + "="
            z = z + 23
        NEXT w
        GRAPHIC FONT "Arial", 10, 1
        GRAPHIC SET POS (235,4)  : GRAPHIC PRINT "Enter a number, then Enter . .";
        GRAPHIC SET POS (235,20) : GRAPHIC PRINT "Enter '0' to Cancel . .";
        PuzzleName = ""
        GRAPHIC LINE INPUT Dummy
        FOR w =1 TO 19
            IF w = VAL(Dummy) THEN PuzzleName = Listing(w) : EXIT FOR
        NEXT w
        FOR w = 150 TO 600 STEP 23
            GRAPHIC SET POS (1,w) : GRAPHIC PRINT "                                                     ";
            GRAPHIC SET POS (1,w+ 8) : GRAPHIC PRINT "                                                     ";
        NEXT w
     
        GRAPHIC SET POS (235, 5) : GRAPHIC PRINT "                                                 "
        GRAPHIC SET POS (235,15) : GRAPHIC PRINT "                                                 "
        GRAPHIC SET POS (235,20) : GRAPHIC PRINT "                                                 "
        IF PuzzleName <>"" THEN
            GRAPHIC SET POS (240,5) : GRAPHIC PRINT "FileName="
            GRAPHIC SET POS (240,20)
            GRAPHIC PRINT PuzzleName
            BEEP
            GRAPHIC FONT "New Courier", 14, 1
            OPEN Path_Location + PuzzleName FOR INPUT AS #1
            w = 0 : row = 162
            FOR y = 300 TO 700 STEP 50
                z = 295  'col
                INPUT #1,Dummy
                FOR x = 1 TO 9
                    INCR w
                    BoxNum(w) = MID$(Dummy,x,1)
                    IF BoxNum(w) = "-" THEN BoxNum(w) = " "
                    GRAPHIC SET POS (z,row) : GRAPHIC PRINT BoxNum(w);" "
                    z = z + 50
                NEXT x
                row = row + 50
            NEXT y
            CLOSE #1
         END IF
         LoadFlag = 1
    END SUB
    SUB SavePuzzle '------------------------------------ Save Grid numbers to file
        DO
            GRAPHIC FONT "Arial", 8, 1
            GRAPHIC SET POS (740,160) : GRAPHIC PRINT "Enter FileName ( no .ext )"
            IF PuzzleName <>"" THEN GRAPHIC SET POS (740,180) : GRAPHIC PRINT "Hit Enter For:  ";PuzzleName;"  "
            GRAPHIC SET POS (740,200) : GRAPHIC LINE INPUT "FileName:"; Temp
            IF INSTR(Temp,".") THEN Temp = LEFT$(Temp,INSTR(Temp,".")-1)
            IF Temp <>"" THEN PuzzleName = Temp + ".sdk"
            GRAPHIC SET POS (740,180) : GRAPHIC PRINT "                                                     "
            GRAPHIC SET POS (740,180) : GRAPHIC PRINT "Sudoku Saved:                                        "
            GRAPHIC SET POS (740,200) : GRAPHIC PRINT "                                                     "
            GRAPHIC SET POS (740,200) : GRAPHIC PRINT PuzzleName                                            "
            SoundBeepBeepBeep
        LOOP UNTIL PuzzleName <>""
        ON ERROR RESUME NEXT
        MKDIR Path_Location
        OPEN Path_Location + PuzzleName FOR OUTPUT AS #1
        FOR zz = 1 TO 81 STEP 9
            FOR w = 0 TO 8
                'IF BoxNum(zz+w) = "" OR BoxNum(zz+w) = "  " OR BoxNum(zz+w) = " " THEN BoxNum(zz+w) = "-"
                IF BoxNum(zz+w) = "" OR BoxNum(zz+w) = " " THEN BoxNum(zz+w) = "-"
                PRINT #1, TRIM$(BoxNum(zz+w));
            NEXT w
            PRINT #1,
        NEXT zz
        CLOSE #1
        FOR w = 1 TO 81
            IF BoxNum(w) = "-" THEN BoxNum(w) = ""
        NEXT w
        SaveFlag = 1
    END SUB
     
    SUB SoundBeepBeepBeep  '------------------------- Sound 3 Beeps
        SLEEP 200
        MOUSE OFF : MOUSE ON
        BEEP : SLEEP 150 : BEEP : SLEEP 150 : BEEP : SLEEP 150
    END SUB

    Leave a comment:


  • Chris Holbrook
    replied
    It would be helpful to show your code, preferably compileable.

    If you are using V5, then presumably you are getting the click something like:

    Code:
     GRAPHIC WINDOW CLICK TO clicked, clickX, clickY
    ??

    Leave a comment:


  • Lynn Wakefield
    started a topic Destroy Mouse Pointer position

    Destroy Mouse Pointer position

    If I click the mouse on a graphic box example:

    DO

    (print something if this box is clicked)
    (Load a file if this box is clicked)
    ........
    etc

    GRAPHIC INKEY$ TO x
    LOOP UNTIL x = $ESC

    That box is set into a loop, which keeps doing it over and over. How can I destroy the mouse pointers location after clicking on a box so it only does the action clicked on once (but still be able to click the same box to do the action again)?
    I can set a Flag, which works, but clicking on that box again does nothing.

    Hope this is not a stupid question.
    Thanks, Lynn
Working...
X