1. Clickable windows areas
Is there an easy(+ or -) way to make certain areas of a window clickable?
I have an image of a piano keyboard and I'd like to be able to make the
keys clickable.
I could use an onMouse event and check to see if the mouse was in the
area of a certain key, but I am hoping there is an easier way.
2. Re: Clickable windows areas
----- Original Message -----
From: "Evan Marshall" <evan at net-link.net>
To: "EUforum" <EUforum at topica.com>
Subject: Clickable windows areas
>
> Is there an easy(+ or -) way to make certain areas of a window clickable?
> I have an image of a piano keyboard and I'd like to be able to make the
> keys clickable.
> I could use an onMouse event and check to see if the mouse was in the
> area of a certain key, but I am hoping there is an easier way.
>
Hi Evan,
yes there is an easy way to do this. You can create a child window that only
has a border and detect clicks in that. Here is an example:
------------------
include win32lib.ew
without warning
constant w1 = createEx(Window, "Test", 0, 0, 0, 600, 400, 0, 0),
sb = createEx(StatusBar, "", w1, 0, 0, 0, 0, 0, 0)
sequence PKeys
integer x,y,z,h,w
procedure click_PKeys(integer self, integer event, sequence parms)
integer n
n = find(self, PKeys)
setText(sb, sprintf("Key ID %d, #%d", {self, n}))
end procedure
PKeys = repeat(0, 88)
w=45
h=34
x = 5-w
z = 0
for i = 1 to 11 do
x += w
y = 5-h
for j = 1 to 8 do
y += h
z += 1
PKeys[z] = createEx(Window, "", w1,
x, y, w, h, {WS_VISIBLE,WS_CHILD,WS_BORDER},0)
end for
end for
setHandler(PKeys, w32HClick, routine_id("click_PKeys"))
WinMain(w1, Normal)
---------
Derek
3. Re: Clickable windows areas
Thanks Brian and Derek.
I think I'll try the child window method that Derek suggested. That is
what I had in mind but had a major brain lapse and couldn't figure it out.
Now, is there a way to make the border invisible? I haven't looked into
this yet so it may be a simple question from a lazy person.
4. Re: Clickable windows areas
Sure, just don't specify WS_BORDER in the create() call.
----- Original Message -----
From: "Evan Marshall" <evan at net-link.net>
To: "EUforum" <EUforum at topica.com>
Subject: Re: Clickable windows areas
>
> Thanks Brian and Derek.
>
> I think I'll try the child window method that Derek suggested. That is
> what I had in mind but had a major brain lapse and couldn't figure it out.
>
> Now, is there a way to make the border invisible? I haven't looked into
> this yet so it may be a simple question from a lazy person.
>
>
>
>
5. Re: Clickable windows areas
Oh, duh, to make the border invisible, just delete the WS_BORDER from
the window definition.
6. Re: Clickable windows areas
Evan,
I tried Derek's suggestion about making an array of captionless windows, but
found that I couldn't make the black keys in their proper positions,
"overlaying" portions of the white keys; I tried buttons, too, with same
problem. I then tried making a drawing of a piano keyboard, with the
intention of saving each key as a separate .bmp, and then pasting them onto
the screen so they looked like one keyboard, but as I was doing that it
finally dawned on me that it would actually be simpler to just...test
against x-y position of mouse!!
So my inexpert conclusion is that isn't really a useful easier way than what
you were already aware of.
Dan Moyer
----- Original Message -----
From: "rudy toews" <rltoews at ilos.net>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, March 30, 2002 4:06 AM
Subject: RE: Clickable windows areas
>
>
> Evan Marshall wrote:
> > Is there an easy(+ or -) way to make certain areas of a window
> > clickable?
> > I have an image of a piano keyboard and I'd like to be able to make the
> > keys clickable.
> > I could use an onMouse event and check to see if the mouse was in the
> > area of a certain key, but I am hoping there is an easier way.
> >
> >
> hi Evan
> i am only beginning to learn the win32lib myself trying to creata a
> windows program. if you turn your piano keys into bitmaps that are used
> as icons assigned a name when creating buttons then:
> you can probably stay away from mouse coordinates(and calculations).
>
> or
>
> my first atempt was to create a keypad where all the keys are beside one
> another in a rectangle. basexy = [0,x,y]
> mouseat returns 3 item sequence, x in position 1, y = position 2
> a keypad that is 13 keys accross by 4 rows up
> using the left bottom corner of the rectangle as a base and a common
> keyshape then:
>
> amhere = mouseat()
> keyx = int((amhere[1]-base[1]) / 13)+1
> keyy = int((amhere[2]-base[2]) / 4) + 1
> keynum = keyx * keyy
>
> hope this helps
> rudy
> lotterywars
>
>
>
>
7. Re: Clickable windows areas
- Posted by euman at bellsouth.net
Mar 30, 2002
> > Evan Marshall wrote:
> > > Is there an easy(+ or -) way to make certain areas of a window
> > > clickable?
> > > I have an image of a piano keyboard and I'd like to be able to make the
> > > keys clickable.
> > > I could use an onMouse event and check to see if the mouse was in the
> > > area of a certain key, but I am hoping there is an easier way.
Hi Evan,
Here is a short (not very) tutorial on subclassing for interested parties.
the (below) routine will be used to create buttons "Push type"
global function makebutton(atom hwnd, atom cid, integer x1, integer y1, integer
x2, integer y2)
atom id
id =
CreateWindow(WS_EX_TRANSPARENT,"button","",or_all({WS_CHILD,WS_VISIBLE,BS_OWNERDRAW}),
x1,y1,x2,y2,hwnd,cid,hInst,0)
return id
end function
initially because I use WS_EX_TRANSPARENT the buttons arent seen on screen and
BS_OWNERDRAW allows
me to put bitmaps or just about anything onto the buttons face.
you need to setup a routine that will tell you your mouse is either in or has
left your buttons:
(this routine works in Windows 95b and up)
integer x_TrackMouseEvent
x_TrackMouseEvent = define_c_proc( comctl32, "_TrackMouseEvent",{C_LONG})
TME = allococate(16)
poke4(TME + TME_cbSize, 16)
poke4(TME + TME_dwFlags,TME_LEAVE)
poke4(TME + TME_dwHoverTime, HOVER_DEFAULT)
then I subclass the buttons inside my MainWindowProc's WM_CREATE:
DefBtnCtrlProc = SetWindowLong(buttonname,GWL_WNDPROC,iBtnCtrlProc)
and finally the subclass routine itself (below):
"This allows me to catch anything that happens to my buttons by handle"
atom DefBtnCtrlProc
integer inControl, isClicked
function BtnCtrlProc(atom handle, atom iMsg, atom wParam, atom lParam)
if iMsg = WM_LBUTTONDOWN then
if handle = buttonname then
-- do something
end if
end if
elsif iMsg = WM_MOUSEMOVE then
poke4(TME + TME_hwndTrack, handle)
c_proc(x_TrackMouseEvent,{TME})
hdc = GetDC(hwnd)
if handle = buttonname then
-- do something
end if
ReleaseDC(hwnd, hdc)
inControl = 1
end if
elsif iMsg = WM_MOUSELEAVE then
InvalidateRect(hwnd, tbrect, 0)
inControl = 0
end if
end if
return c_func(xCallWindowProc,{DefBtnCtrlProc, handle, iMsg, wParam, lParam})
end function
constant iBtnCtrlProc = call_back(routine_id("BtnCtrlProc"))
tbrect (above) is used to paint the area of a paticular button.
this is very helpfull to eliminate screen flicker by not repainting the
entire window. This if you plan on highlighting your buttons when
your mouse is inside and turning it off when your mouse has left.
Subclassing is very easy stuff once you get the initial hang of it.
Sure it might take alittle more typing than if you were to use Win32lib
but this is much faster in execution, much smaller in size
and you have total control of what happens in your application.
95% of this code is transferable or will never need to be re-typed
so the advantages are very clear.
Alot of people would say that Im crazy for not using Win32lib for everything
but this just isnt so, I dont think Im crazy at all.
Euman
euman at bellsouth.net