• Welcome to Theos PowerBasic Museum 2017.

alternative graphic windows

Started by Frank Brübach, October 03, 2009, 11:58:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

good evening.

I have made this experiment for producing "graphic window".

my first question: what is the advantage of this kind of "graphic window" creation ? Who use it? I see not a lot of possibilities to change or add new styles, colors or background properties here, but I want to use graphic print and ellipse functions.

second qt: I would like further to know how I can push down left mouse button and click into window so I can get an message box with reply. My attempt is only a first but no serious way to get it. Perhaps somebody has an example of this board at this forum :)

I like this example, because it has made some fun. I included also a little counter function.

test example with "graphic window" function:

#COMPILE EXE
#DIM ALL

%radius = 100
%true = 1
%IDC_GRAPHIC1 = 2
%maxIterations = 20

GLOBAL getkey AS STRING
GLOBAL stops AS LONG
GLOBAL a, b AS SINGLE

FUNCTION PBMAIN () AS LONG

LOCAL hWin AS DWORD
LOCAL clicks AS DWORD
LOCAL getkey AS STRING
LOCAL x AS LONG
LOCAL nFile AS LONG
LOCAL nWidth AS LONG
LOCAL nHeight AS LONG
LOCAL y AS LONG
LOCAL counter AS Quad

MSGBOX "how to create alternative window style!", %MB_ICONINFORMATION, "10 Seconds Test Example :) "

   GRAPHIC WINDOW "Graphic Window Style", 300, 300, 400, 400 TO hWin
   GRAPHIC ATTACH hWin,0, REDRAW

   GRAPHIC FONT "Times New Roman", 36, 0

   GRAPHIC SET POS (-120,-40)
   GRAPHIC ELLIPSE (-%radius+50, %radius+50) - (%radius+50, -%radius+50), %RED, %BLUE
   GRAPHIC REDRAW
   INCR Counter
   GRAPHIC SCALE(-%radius*2,100)-(%radius*2,-500)
   GRAPHIC SET POS (-180,-140)
   GRAPHIC PRINT "alternative window"
   GRAPHIC SET POS (-180,-260)
   GRAPHIC PRINT "test for 10 seconds!"
   GRAPHIC FONT "Arial", 10, 0
   GRAPHIC SET POS (-180,-130)
   GRAPHIC COLOR RGB(100,0,255)
   GRAPHIC PRINT "push return key! " counter
   GRAPHIC REDRAW

   GRAPHIC BOX (10, 10) - (140, 140), 0, %BLUE
   GRAPHIC WINDOW CLICK hwin TO clicks, x, y
   IF clicks => 1 OR %true THEN
   MSGBOX "you have clicked the window", %MB_OK, "test button: "
   END IF

   GRAPHIC FONT "ARIAL", 14, 0
   GRAPHIC SET POS (-80,-220)
   GRAPHIC COLOR RGB(255,100,20)
   GRAPHIC LINE INPUT "gratulation! prompted reply" getkey
   GRAPHIC REDRAW

   FOR counter = 1 TO %maxIterations
       GRAPHIC SET POS (-180,-360)
       GRAPHIC COLOR RGB(RND(1,255),0,60)
       GRAPHIC PRINT " little test for counter: " counter
       GRAPHIC REDRAW
       NEXT
   SLEEP 10000

END FUNCTION



info: push a "return" key after the first message you have seen.

all work in progress !

cheerio, servus, Frank

Frank Brübach

#1
good morning.

After I was looking some minutes about "mouse handling" (mouse click and movements) there are no big possibilities for this kind of "graphic windows" and my wished mouse clicking like for example "ddt" call back functions or windows sdk apis. it was just and attempt. I found something like "%stn_clicked" for mouse clicking without call back functions. I am not sure if that's right. Anybody can give a hint ?

I can't use for graphic window: "CASE %WM_LBUTTONDOWN, %WM_LBUTTONDBLCLK or %WM_SETCURSOR".

I miss correct mouse functions or don't find the right and specific mouse handling for this "graphic window" until today ???

new: I set the counter higher. tried to use new click command for graphic window.

#COMPILE EXE
#DIM ALL

%radius = 100
%true = 1
%IDC_GRAPHIC1 = 2
%maxIterations = 250
%stn_clicked = 3
%stn_enable = 4

GLOBAL getkey AS STRING
GLOBAL stops AS LONG
GLOBAL a, b AS SINGLE

FUNCTION PBMAIN () AS LONG

LOCAL hWin AS DWORD
LOCAL clicks AS DWORD
LOCAL getkey AS STRING
LOCAL x AS LONG
LOCAL nFile AS LONG
LOCAL nWidth AS LONG
LOCAL nHeight AS LONG
LOCAL y AS LONG
LOCAL counter AS QUAD

MSGBOX "how to create alternative window style!", %MB_ICONINFORMATION, "10 Seconds Test Example :) "

   GRAPHIC WINDOW "Graphic Window Style", 300, 300, 400, 400 TO hWin
   GRAPHIC ATTACH hWin,0, REDRAW

   GRAPHIC FONT "Times New Roman", 36, 0

   GRAPHIC SET POS (-120,-40)
   GRAPHIC ELLIPSE (-%radius+50, %radius+50) - (%radius+50, -%radius+50), %RED, %BLUE
   GRAPHIC REDRAW
   INCR Counter
   GRAPHIC SCALE(-%radius*2,100)-(%radius*2,-500)
   GRAPHIC SET POS (-180,-140)
   GRAPHIC PRINT "alternative window"
   GRAPHIC SET POS (-180,-260)
   GRAPHIC PRINT "test for 10 seconds!"
   GRAPHIC FONT "Arial", 10, 0
   GRAPHIC SET POS (-180,-130)
   GRAPHIC COLOR RGB(100,0,255)
   GRAPHIC PRINT "push return key! " counter
   GRAPHIC REDRAW

   GRAPHIC BOX (10, 10) - (140, 140), 0, %BLUE
   GRAPHIC WINDOW CLICK hwin TO clicks, x, y
   IF clicks => 1 OR %true THEN
   MSGBOX "you have clicked the window", %MB_OK, "test button: "
   END IF

   SLEEP 100
   GRAPHIC FONT "ARIAL", 14, 0
   GRAPHIC SET POS (-80,-220)
   GRAPHIC COLOR RGB(255,100,20)
   GRAPHIC LINE INPUT "gratulation! prompted reply" getkey
   GRAPHIC REDRAW

    IF %stn_clicked => 1 THEN
      MSGBOX "TEST TWO: you have clicked left MOUSE!", %MB_OK, "test MOUSE button: "
    END IF

   FOR counter = 1 TO %maxIterations
       GRAPHIC SET POS (-180,-360)
       GRAPHIC COLOR RGB(RND(1,255),0,60)
       GRAPHIC PRINT " little test for counter: " counter
       GRAPHIC REDRAW
       NEXT
       MSGBOX " ..ends in ten second..  ",%MB_OK, " graphic window test"
   SLEEP 10000


END FUNCTION


that's not perfect I know, but who can show my an pb example how to do correct mouse handling?

IF %stn_clicked => 1 THEN
      MSGBOX "TEST TWO: you have clicked left MOUSE!", %MB_OK, "test MOUSE button: "
    END IF


and one favour. Would be nice to get any feedback of other users too. It seems here are a lot of professional powerbasic users. But I am quite new with PowerBasic language and it's not easy to fight through a new jungle of unknown basic language syntax. I want to learn new things and I am eager to learn fast. so long...

nice sunday. frank

José Roca

 
Quote
I have made this experiment for producing "graphic window".

my first question: what is the advantage of this kind of "graphic window" creation ? Who use it? I see not a lot of possibilities to change or add new styles, colors or background properties here, but I want to use graphic print and ellipse functions.

Here we mostly use GDI+, OpenGL, SDL, etc.

Quote
I can't use for graphic window: "CASE %WM_LBUTTONDOWN, %WM_LBUTTONDBLCLK or %WM_SETCURSOR".

You can, but you have to subclass the graphic window. Here is an example by Richard Angell taken from the PB Forum ( http://www.powerbasic.com/support/pbforums/showthread.php?t=38803&highlight=graphic+instat ):


#COMPILE EXE
#DIM ALL
#INCLUDE "Win32API.inc"

GLOBAL mx,my AS LONG    ' Mouse x and y
GLOBAL lb,rb AS LONG    ' Left and right mouse button
GLOBAL mm,mk AS LONG    ' Detect mouse movements and key presses
GLOBAL bg,fg AS LONG    ' Background and foreground colors
GLOBAL wm,mb AS LONG    ' Wheel mouse and middle button
GLOBAL mw    AS LONG    ' Wheel mouse detected
GLOBAL hGW,hGWChild, pOldCBProc,pOldChildGWProc,hFnt AS DWORD

FUNCTION ChildGWSubProc(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_MOUSEMOVE
      mm=1: mx=LO(WORD,lParam): my=HI(WORD,lParam)         ' Current Mouse X and Y Position in the graphic window
    CASE %WM_LBUTTONDOWN
      mk=1:lb=1: FUNCTION=0: EXIT FUNCTION                      ' Left button pressed
    CASE %WM_RBUTTONDOWN
      mk=1:rb=1: FUNCTION=0: EXIT FUNCTION                      ' Right button pressed
    CASE %WM_MBUTTONDOWN
      mk=1:mb=1: FUNCTION=0: EXIT FUNCTION                      ' Middle button pressed
'    CASE %WM_MBUTTONUP
'      mk=1:mb=0: FUNCTION=0: EXIT FUNCTION                      ' Middle button pressed
    CASE %WM_MOUSEWHEEL
      mw=1: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(pOldChildGWProc, hWnd, wMsg, wParam, lParam)

END FUNCTION
'------------------------------------------------------------------------------
FUNCTION MainGWSubProc (BYVAL hWnd AS DWORD, BYVAL Msg AS LONG, _
                        BYVAL wParam AS LONG, BYVAL lPARAM AS LONG) AS LONG
    SELECT CASE AS LONG Msg    'Select Case with AS LONG clause works faster

        CASE %WM_DESTROY
           IF hGW <> 0 THEN              'going to shut it all down
                IF hGWChild <> 0 THEN       'is the child still subclassed
                    SetWindowLong hGWChild, %GWL_WNDPROC, pOldChildGWProc   'un-sub it
                    hGWChild = 0    'no longer need to track the handle separatedly
                END IF
                SetWindowLong hWnd, %GWL_WNDPROC, pOldCBProc  'un-sub the main GW
                FONT END hFnt
                GRAPHIC ATTACH hGW,0
                GRAPHIC WINDOW END
                hGW = 0     'signal window is closed to exit program loop, if running
            END IF
     END SELECT
     'pass all other messages back to the original processor
     FUNCTION = CallWindowProc(pOldCBProc, hWnd, Msg, wParam, lParam)
END FUNCTION
'------------------------------------------------------------------------------
FUNCTION PBMAIN () AS LONG
    LOCAL rslt AS LONG
    FONT NEW "Arial",14,1 TO hFnt

    GRAPHIC WINDOW "Mouse Demo", 0, 0, 640, 480 TO hGW
    GRAPHIC ATTACH hGW,0, REDRAW
    GRAPHIC COLOR %YELLOW,%BLUE
    GRAPHIC SET FONT hFnt
    GRAPHIC CLEAR
    GRAPHIC SET POS (100, 400)
    GRAPHIC PRINT  "Move and click mouse or Press a key to quit"
    GRAPHIC REDRAW

    'subclass GW window  to intercept close
    pOldCBProc      = SetWindowLong(hGW, %GWL_WNDPROC, CODEPTR(MainGWSubProc))
    'find the graphic control child window handle
    hGWChild        = GetWindow (hGW, %GW_CHILD)
    'subclass graphic control child window for process the mouse and keys
    pOldChildGWProc = SetWindowLong(hGWChild, %GWL_WNDPROC, CODEPTR(ChildGWSubProc))

    WHILE hGW <> 0
        GRAPHIC INSTAT TO rslt
        IF rslt THEN
            GRAPHIC INPUT FLUSH
            PostMessage hGW,%WM_CLOSE,0,0
            EXIT DO
        END IF
        IF mm = 1 THEN
            GRAPHIC SET POS (100,100) :  GRAPHIC PRINT SPACE$(40)
            GRAPHIC SET POS (100,100) :  GRAPHIC PRINT FORMAT$(mx)
            GRAPHIC SET POS (300,100) :  GRAPHIC PRINT SPACE$(40)
            GRAPHIC SET POS (300,100) :  GRAPHIC PRINT FORMAT$(my)
            mm = 0  'reset flag
        END IF
        IF mk = 1 THEN
            IF lb = 1 THEN
                GRAPHIC SET POS (100,200) :  GRAPHIC PRINT SPACE$(50)
                GRAPHIC SET POS (100,200) :  GRAPHIC PRINT "Left Button Clicked"
                lb = 0
            ELSEIF mb = 1 THEN
                GRAPHIC SET POS (100,200) :  GRAPHIC PRINT SPACE$(50)
                GRAPHIC SET POS (100,200) :  GRAPHIC PRINT "Middle Button Clicked"
                mb = 0
            ELSEIF rb = 1 THEN
                GRAPHIC SET POS (100,200) :  GRAPHIC PRINT SPACE$(50)
                GRAPHIC SET POS (100,200) :  GRAPHIC PRINT "Right Button Clicked"
                rb = 0
            END IF
            mk = 0
        END IF

        IF mw = 1 THEN
            ' Wheel turned (+)=up (-)=down
            IF wm = -1 THEN
                GRAPHIC SET POS (100,300) :  GRAPHIC PRINT SPACE$(50)
                GRAPHIC SET POS (100,300) :  GRAPHIC PRINT "Wheeled Down"
            ELSE
                GRAPHIC SET POS (100,300) :  GRAPHIC PRINT SPACE$(50)
                GRAPHIC SET POS (100,300) :  GRAPHIC PRINT "Wheeled Up"
            END IF
            wm = 0
            mw = 0
        END IF

        GRAPHIC SET POS (100, 400)
        GRAPHIC PRINT  "Move, click or wheel mouse ... or Press a key to quit"
        GRAPHIC REDRAW
    WEND

END FUNCTION


Frank Brübach

thank you for the link and your example, jose! Mouse example looks good for my experiments. I will check it this week-end and tune my graphic window example. but I see it's more worth to use "open-gl", "sdi", "gdi+" or other api windows. Must give some closer orientation for myself ;)

frank