You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
You can subclass the graphics window and then catch WM_LBUTTONDOWN, WM_RBUTTONDOWN, and many other mouse messages.
The horizontal location of where the click occurred is in the lo word of the lParam and the vertical position is
in the hi word of lparam. Here is an example of creating a callback routine for the graphics window in PBCC 4.x
Code:
#COMPILE EXE
#DIM ALL
#INCLUDE "Win32Api.Inc"
'
GLOBAL GraphicWindowChildOldProc AS DWORD
GLOBAL hGraphicWindow AS DWORD
GLOBAL finished AS LONG
'
' Timer callback routines, called every 200ms
' Just a little routine to display colored boxes on the graphic window
SUB DisplayUpdate(BYVAL uID AS LONG, BYVAL uMsg AS LONG, _
BYVAL dwUser AS LONG, BYVAL dw1 AS LONG, BYVAL dw2 AS LONG)
LOCAL r, g, b AS LONG
LOCAL c AS LONG
LOCAL x, y AS LONG
LOCAL w, h AS LONG
'
GRAPHIC ATTACH hGraphicWindow, 0&, REDRAW
GRAPHIC GET CLIENT TO w, h
'
r = RND(0, 255)
g = RND(0, 255)
b = RND(0, 255)
'
x = RND(0, w-21)
y = RND(30, h-21)
'
c = RGB(r,g,b)
'
GRAPHIC BOX (x,y) - (x+25,y+25), 20, c, c
'
GRAPHIC REDRAW
END SUB
' This is the function that is called whenever a Key or Mouse click is detected in the Graphics Window
FUNCTION GraphicWindowChildNewProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
SELECT CASE wMsg
CASE %WM_NCHITTEST
CASE %WM_MOUSEMOVE
CASE %WM_LBUTTONDOWN
? "you clicked the left mouse button at ("+FORMAT$(LO(WORD, lParam))+","+FORMAT$(HI(WORD, lParam))+")"
CASE %WM_RBUTTONDOWN
? "you clicked the right mouse button at ("+FORMAT$(LO(WORD, lParam))+","+FORMAT$(HI(WORD, lParam))+")"
CASE %WM_KEYDOWN
IF CHR$(WPARAM) = "X" THEN
finished = 1
ELSE
? "you pressed the "+CHR$(wparam)+ " key"
END IF
END SELECT
'
FUNCTION = CallWindowProc(GraphicWindowChildOldProc, hWnd, wMsg, wParam, lParam)
END FUNCTION
FUNCTION PBMAIN
LOCAL w AS LONG
LOCAL tid AS LONG
'
RANDOMIZE
'
finished = 0
'
GRAPHIC WINDOW "SubClass", 0, 0, 320, 240 TO hGraphicWindow
'
' This function subclasses the Graphic Window
' Which means that any key or mouse presses in the Window
' Will cause the GraphicWindowChildNewProc Callback function to be called
GraphicWindowChildOldProc = SetWindowLong(hGraphicWindow, %GWL_WNDPROC, CODEPTR(GraphicWindowChildNewProc))
'
' Create an timer that runs the routine DisplayUpdate every 200ms
tid = TimeSetEvent(200, 10, CODEPTR(DisplayUpdate), BYVAL 0, %TIME_PERIODIC)
'
GRAPHIC ATTACH hGraphicWindow, 0&, REDRAW
GRAPHIC CLEAR %BLACK
GRAPHIC COLOR %BLUE, %YELLOW
GRAPHIC FONT "Times New Roman", 18, 1
GRAPHIC PRINT "press X to quit"
GRAPHIC REDRAW
'
w = 0
'
' loop until an X is pressed on the graphic window
WHILE finished = 0
INCR w
' Every third iteration of the loop give back
' one time slick to Windows too prevent 100% CPU utilization
' See the [url="http://www.powerbasic.com/support/help/pbcc/sleep_statement.htm"]SLEEP[/url] statement in the Help file
IF w MOD 3 = 0 THEN
SLEEP 0
END IF
WEND
'
' Stop the timer from running
TimeKillEvent(tid)
'
' Set the graphics window to use the original Callback routine
SetWindowLong(hGraphicWindow, %GWL_WNDPROC, GraphicWindowChildOldProc)
'
GRAPHIC ATTACH hGraphicWindow, 0&
GRAPHIC WINDOW END
END FUNCTION
I'm sure that works, but maybe the doc should be updated under the GRAPHIC WINDOW statement by adding the italicized text..
hWin??? The handle of the newly-created window. If the window could not be created, hWin??? will be 0. This handle may be used to set up a standard Windows subclass procedure if you want to receive and process keystroke [and other?] notifications [any special limitations or restrictions here]
MCM
[This message has been edited by Michael Mattias (edited May 11, 2007).]
Can I suggest in a future version of PBCC your function is wrapped
up in a simple command with the result already scaled to match the
current GRAPHIC SCALE. It seems to me clicking on a graphic
widget would be quite a basic requirement for many programs.
Something like this maybe...
You should send in your request to [email protected]
I once took a request from the forums and was quickly admonished
by a forum user for doing so. True, the forums are not an official
support line and you will have to send it in via email. Thanks.
"I once took a request from the forums and was quickly admonished
by a forum user for doing so.
Steve Rossell
PowerBASIC Staff"
That is a crazy restriction Steve. I encourage you to use these forums for ideas to expand the product.
In the fairly unlikely event that I make a suggestion that you think is useful, you have my permission, no you have my encouragement, to consider it and use it.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment