Click event for Imagegadget

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by effigy.

Is there any way to detect the click event for an imagegadget?

I was told that with the textgadget I could add the #ss_notify flag
I tried that with the imagegadget to no avail. I realize I can use a
routine to watch when a click event is triggered then ready the windowmousex()
but that seems cumbersome compared to the #ss_notify.

See viewtopic.php?t=5544 for an example of the #ss_notify.

I could also use the buttonimage gadget if you can stop it from pressing
down like a button. Thanks for the input.

Derek
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

Try something like this:

Code: Select all

eventid=waitwindowevent()
select eventid
  case #WM_LBUTTONDOWN
    screen.rect
    getwindowrect_(GadgetID(#imagegadget),screen)
    maus.point
    GetCursorPos_(maus)
    if screen\left=maus\x and screen\top=maus
      debug "click in the image"
endselect
PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

You can use the notify style:

Code: Select all

;GADGET IDs
#Image0=0

;WINDOW ID
#Window1=0

#SS_NOTIFY=256 

;WINDOW
OpenWindow(#Window1,150,70,550,350,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar,"Window1")
CreateGadgetList(WindowID(#Window1))

LoadImage(0,"C:\yourimage.bmp")
hwimage=ImageGadget(#Image0,10,16,300,232,UseImage(0))
os=getwindowlong_(hwimage,#GWL_STYLE)
setwindowlong_(hwimage,#GWL_STYLE,os|#SS_NOTIFY)

;EVENT LOOP
Repeat
  EventID=WaitWindowEvent()
    Select EventID
      Case #PB_EventGadget
        Select EventGadgetID()
          case #Image0
            beep_(1000,100)

        EndSelect
    EndSelect
Until EventID=#PB_EventCloseWindow

BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by effigy.

Thanks guys... I have decided to go a different way with this.

I have my Imagegadget created on another window. That way I always know where the mouse is relative to my picture.

I'm sure I will use the other suggestions is the future though.

Thanks Again,
Derek
Post Reply