Qbasicnews.com

Full Version: mouse useage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
can someone tell me how you make buttons in qb and use a mouse to activate them. so i assume that you would use the call statement to goto another window

another question: how do you make windows that move and if you click the cross it shuts the window down like in an operating system
Please correction. Moving windows and stuff are not things of an operating system, but a windowing envirment. MSDOS is an OS and doesn't have moving windows itself, Windows 3.1 has moving windows and it is not an OS.

There are several ways of making windows, but it is not a simple task. You need a windows manager, a portion of code which just checks for clicks and keeps track of where every window is, to know if the user clicked on a window or not, and on which window the user clicked. It is somewhat complex.

If you want windows management without doing a line of code switch to Visual Basic, where windows are automaticly managed by the runtime. In QB, you have to code the windowing interface completely from scratch. In VBDOS, you have those neat windows in text mode.

The other question about having a clickable button: Well, it is done separately. Usually, you have a SUBroutine to draw the shape, and then you make loops to check if the user clicked. When the user clicks, you just check where, and that way you know if he or she clicked on a button and on which one he or she clicked.
im not the greatest qb progger, but heres how i did it
im using a font sub, though u dont 'need' one for this to work, just replace the font calls to print and adjust the X,Y cords for 'locate'ing where the button text should go.

ps, if anyone can improve this for me, id be grateful

Code:
DECLARE SUB button (X%, Y%, L%, H%, label$, Bcol%, Tcol%, stall%, mode%)

FOR i = 1 TO buttonstack%
           IF xmouse% > xbutton%(i) AND xmouse% < (xbutton%(i) + wbutton%(i)) AND ymouse% > ybutton%(i) AND ymouse% < (ybutton%(i) + hbutton%(i)) THEN
            MouseDriver 2, bx%, CX%, DX%, lb%, rb%, 0
            action$ = clickto$(i)
            GOTO actionbutton
            EXIT FOR
           END IF
        NEXT i

actionbutton:
    IF action$ = "press me" THEN
               'dosomething
        END IF

button X%, Y%, LENGTH%, WIDTH%,"pressme", MODE%, COLOR%,FOMTSTALL%, BUTTON(ON/OFF)%

SUB button (X%, Y%, L%, H%, label$, Bcol%, Tcol%,stall%, mode%)
    IF mode% = 1 THEN
        buttonstack% = buttonstack% + 1
        xbutton%(buttonstack%) = X%
        ybutton%(buttonstack%) = Y%
        wbutton%(buttonstack%) = L%
        hbutton%(buttonstack%) = H%
        clickto$(buttonstack%) = label$
    END IF
    

    IF Bcol% = -1 THEN                                                ' -1: Transparent Button Box
        LINE (X%, Y%)-(X% + L%, Y% + H%), Bcol%, B
        font label$, X%+3, Y%, Tcol%,stall%,0
    ELSEIF Bcol% = -2 THEN                                            ' -2: No Box, just text
        font label$, X%+15, Y%,Tcol%,stall%,0
    ELSEIF Bcol% = -3 THEN                                            ' -3: Hotspot invisible button
        'hidden button                                                                
    ELSE                                                              ' Default Button Box
        LINE (X%, Y%)-(X% + L%, Y% + H%), Bcol%, BF
        LINE (X%, Y%)-(X% + L%, Y% + H%), BScol%, B
        LINE (X%, Y%)-(X% + L%, Y%), BHcol%
        LINE (X%, Y%)-(X%, Y% + H%), BHcol%
        font label$, X%+3, Y%, Tcol%,stall%,0
    END IF
        
END SUB
heres my window one as well, its a graphical window, not just boxes

the window image is divided like this

--- --- ---
|a| |b| |c|
--- --- ---
|d| | | |e|
--- --- ---
|f| |g| |h|
--- --- ---

Code:
DECLARE SUB windowmake (X%, Y%, W%, H%, wintitle$, mode%)
DECLARE SUB image (imagename$,X%,Y%,size%)

'loads the peices of the window img into memory
image "window.img",0,0,2600:GET (0,0)-(8,15), winA%:GET (9,0)-(9,15), winB%:GET (30,0)-(38,15), winC%:GET (0,16)-(8,16), winD%:GET (30,16)-(40,16), winE%:GET (0,25)-(8,40), winF%: GET (9,25)-(9,40), winG%:GET (30,25)-(40,40), winH%:CLS


'make a window somewhere on the screen
windowmake X,Y,WIDTH,HEIGHT,"My new Window",1

SUB image (imagename$,X%,Y%,size%)
REDIM spritegrafix(size%)
            DEF SEG = VARSEG(spritegrafix(0)): BLOAD imagename$, 0
            PUT (X%, Y%), spritegrafix, PSET
            DEF SEG
END SUB  

SUB windowmake (X%, Y%, W%, H%, wintitle$, mode%)
    IF mode% = 1 THEN
        PUT (X%,Y%), winA%,PSET: PUT (X%+W%+1,Y%), winC%,PSET: PUT (X%,Y%+H%+1), winF%,PSET:PUT (X%+W%+1,Y%+H%+1), winH%,PSET                      
        FOR winL% = 1 TO W%-8:PUT (X%+winL%+8,Y%), winB%,PSET:PUT (X%+winL%+8,Y%+H%+1), winG%,PSET:NEXT winL%
        FOR winH% = 1 TO H%-15:PUT (X%,Y%+winH%+15), winD%,PSET:PUT (X%+W%+1,Y%+winH%+15), winE%,PSET:NEXT winH%
        font wintitle$, X%+2, Y%+2, 120,1,0
        LINE(X%+6,Y%+13)-(X%+W%+3,Y%+H%+8),0,BF
    END IF
    font wintitle$, X%+3, Y%+1, 15,1,0    
END SUB
Momoguru, your windowing/gui routines are really neat.

Here you can download the ones I did 5 years ago: http://usuarios.lycos.es/qbsux/guis.html

Not that "good loking" as yours, but I felt like showing them Wink
really, i guess im not as far behind as i thought... although i know they can be improved...'hint hint'
here's one I made a few years ago.
(right-click, save)
www.geocities.com/juice801980/windowmk.bas
momonguru i can't get your routines to work
explain what it is your doing / using, and ill tell you / give you what you need.

first off for the window routine, u will need to create, or use my window graphic AND use my font (or a font) routine.

if you would rather me upload everything for a GUI demo, lemme know and i will.
can you do that please
Pages: 1 2