Page 1 of 1
MessageBox is repeating itself!
Posted: Sat Apr 15, 2023 9:33 am
by rozbud
Hello Dear PB Team,
I created a Window & image inside it.
image event on click, gives MessageBox.
The
PROBLEM is that, once you close the MessageBox & hover-over the image by Mouse (quickly), the MessageBox
trigger again!!
Any help?
Here is my CODE:
Code: Select all
Enumeration
#WIN_MAIN
#BUTTON_CLOSE
EndEnumeration
Global Quit.b = #False
#FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If OpenWindow(#WIN_MAIN, 0, 0, 200, 80, "Repeated Message Issue!", #FLAGS)
ButtonGadget(#BUTTON_CLOSE, 70, 30, 60, 20, "Close"):SetClassLong_(hWnd, #GCL_HCURSOR, LoadCursor_(0, #IDC_HAND))
Img_Window_1_0 = LoadImage(#PB_Any,"C:\Settings.bmp")
Image_0 = ImageGadget(#PB_Any, 10, 18, 20, 20, ImageID(Img_Window_1_0))
Repeat
Event.l = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #BUTTON_CLOSE
MessageRequester("", "im a button.") ; This Message are Not Repeated.
Case Image_0
MessageRequester("", "im an image.") ; This Message are Repeated (the Problem here ...)
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
End
Re: MessageBox is repeating itself!
Posted: Sat Apr 15, 2023 9:53 am
by Caronte3D
Code: Select all
Enumeration
#WIN_MAIN
#BUTTON_CLOSE
EndEnumeration
Global Quit.b = #False
#FLAGS = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If OpenWindow(#WIN_MAIN, 0, 0, 200, 80, "Repeated Message Issue!", #FLAGS)
ButtonGadget(#BUTTON_CLOSE, 70, 30, 60, 20, "Close"):SetClassLong_(hWnd, #GCL_HCURSOR, LoadCursor_(0, #IDC_HAND))
Img_Window_1_0 = LoadImage(#PB_Any,"C:\Settings.bmp")
Image_0 = ImageGadget(#PB_Any, 10, 18, 20, 20, ImageID(Img_Window_1_0))
Repeat
Event.l = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #BUTTON_CLOSE
MessageRequester("", "im a button.") ; This Message are Not Repeated.
Case Image_0
If EventType()=#PB_EventType_LeftClick
MessageRequester("", "im an image.") ; This Message are Repeated (the Problem here ...)
EndIf EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
End
Re: MessageBox is repeating itself!
Posted: Sat Apr 15, 2023 10:32 am
by chi
Code: Select all
EnableExplicit ; use EnableExplicit to avoid typo bugs
Enumeration Window
#WIN_MAIN
EndEnumeration
Enumeration Gadget
#BUTTON_CLOSE
#IMAGE_VIEW
EndEnumeration
Enumeration Image
#IMG_SETTINGS
EndEnumeration
If OpenWindow(#WIN_MAIN, 0, 0, 200, 80, "Repeated Message Issue!", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(#BUTTON_CLOSE, 70, 30, 60, 20, "Close")
SetClassLongPtr_(GadgetID(#BUTTON_CLOSE), #GCL_HCURSOR, LoadCursor_(0, #IDC_HAND)) ; don't use SetClassLong: use SetClassLongPtr (and SetWindowLongPtr) for x64 compatibility...
LoadImage(#IMG_SETTINGS, "C:\Settings.bmp")
ImageGadget(#IMAGE_VIEW, 10, 18, 20, 20, ImageID(#IMG_SETTINGS)) ; place the cursor somewhere in the word 'ImageGadget' and press F1. You'll find usefull infos there. (e.g. EventType() under Remarks)
SetWindowLongPtr_(GadgetID(#IMAGE_VIEW), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#IMAGE_VIEW), #GWL_STYLE)|#WS_CLIPSIBLINGS) ; clip the button
Repeat
Define Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #BUTTON_CLOSE
MessageRequester("", "im a button.")
Case #IMAGE_VIEW
If EventType() = #PB_EventType_LeftClick ; ...will only trigger the MessageRequester on LMB click
MessageRequester("", "im an image.")
EndIf
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
Re: MessageBox is repeating itself!
Posted: Sat Apr 15, 2023 4:56 pm
by rozbud
Lot of THANKS for Mr. CARONTE3D & Mr. CHI, for their kind assistance.
Re: MessageBox is repeating itself!
Posted: Sat Apr 15, 2023 10:29 pm
by rozbud
Dear Mr. CHI,
When I add another Button (without setting it's cursor), the Hand Cursor appear on it!
Any explanation?
chi wrote: Sat Apr 15, 2023 10:32 am
Code: Select all
EnableExplicit ; use EnableExplicit to avoid typo bugs
Enumeration Window
#WIN_MAIN
EndEnumeration
Enumeration Gadget
#BUTTON_CLOSE
#IMAGE_VIEW
EndEnumeration
Enumeration Image
#IMG_SETTINGS
EndEnumeration
If OpenWindow(#WIN_MAIN, 0, 0, 200, 80, "Repeated Message Issue!", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(#BUTTON_CLOSE, 70, 30, 60, 20, "Close")
SetClassLongPtr_(GadgetID(#BUTTON_CLOSE), #GCL_HCURSOR, LoadCursor_(0, #IDC_HAND)) ; don't use SetClassLong: use SetClassLongPtr (and SetWindowLongPtr) for x64 compatibility...
LoadImage(#IMG_SETTINGS, "C:\Settings.bmp")
ImageGadget(#IMAGE_VIEW, 10, 18, 20, 20, ImageID(#IMG_SETTINGS)) ; place the cursor somewhere in the word 'ImageGadget' and press F1. You'll find usefull infos there. (e.g. EventType() under Remarks)
SetWindowLongPtr_(GadgetID(#IMAGE_VIEW), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#IMAGE_VIEW), #GWL_STYLE)|#WS_CLIPSIBLINGS) ; clip the button
Repeat
Define Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #BUTTON_CLOSE
MessageRequester("", "im a button.")
Case #IMAGE_VIEW
If EventType() = #PB_EventType_LeftClick ; ...will only trigger the MessageRequester on LMB click
MessageRequester("", "im an image.")
EndIf
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
Re: MessageBox is repeating itself!
Posted: Sun Apr 16, 2023 1:43 pm
by chi
rozbud wrote: Sat Apr 15, 2023 10:29 pm
Any explanation?
When using SetClassLongPtr_() on a Button, you are modifying the whole "button" class (incl. ButtonGadget, CheckboxGadget, OptionGadget, ...). That's why you also see the hand cursor over the button in a messagebox.
Re: MessageBox is repeating itself!
Posted: Mon Apr 17, 2023 5:43 pm
by rozbud
This is good by the way!
Thank you.