Page 1 of 2
HyperLinkGadget detecting change with GetGadgetColor
Posted: Fri Sep 13, 2013 7:39 pm
by VB6_to_PBx
HyperLinkGadget detecting change with GetGadgetColor
when you Hover above HyperLinkGadget it changes Color ,
how can you detect or get the new Color it changes to ??
GetGadgetColor of the HyperLinkGadget does not seem
to be able to get the new Color of the HyperLinkGadget when you Hover ontop it .
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Fri Sep 13, 2013 8:19 pm
by netmaestro
Set/GetGadgetColor is usable for the normal state of the gadget, but for the highlighted state the coder sets that himself, so theoretically he should know it already. It's one of those things that if you're going to be switching it up you'll have to keep track of it.
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Fri Sep 13, 2013 8:57 pm
by RASHAD
Your request is not clear
But the next snippet maybe good but not so perfect
Code: Select all
ExamineDesktops()
If OpenWindow(0, 0, 0, 270, 160, "HyperlinkGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
HyperLinkGadget(0, 10, 10, 250,20,"Red HyperLink",RGB(255,0,0))
HyperLinkGadget(1, 10, 30, 250,20,"Arial Underlined Green HyperLink", RGB(0,255,0), #PB_HyperLink_Underline)
SetGadgetFont(1, LoadFont(0, "Arial", 12))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Repaint
If DesktopMouseX() > GadgetX(0,#PB_Gadget_ScreenCoordinate) And DesktopMouseX() < (GadgetX(0,#PB_Gadget_ScreenCoordinate)+ GadgetWidth(0)) And DesktopMouseY() > GadgetY(0,#PB_Gadget_ScreenCoordinate) And DesktopMouseY() < (GadgetY(0,#PB_Gadget_ScreenCoordinate)+GadgetHeight(0))
Debug Str(RGB(255,0,0))
ElseIf DesktopMouseX() > GadgetX(1,#PB_Gadget_ScreenCoordinate) And DesktopMouseX() < (GadgetX(1,#PB_Gadget_ScreenCoordinate)+ GadgetWidth(1)) And DesktopMouseY() > GadgetY(1,#PB_Gadget_ScreenCoordinate) And DesktopMouseY() < (GadgetY(1,#PB_Gadget_ScreenCoordinate)+GadgetHeight(1))
Debug Str(RGB(0,255,0))
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Case 1
EndSelect
EndSelect
Until Quit = 1
End
EndIf
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 5:47 am
by VB6_to_PBx
RASHAD i was trying to modify and simplify your Code you Posted here with HyperLinkGadget in it :
http://www.purebasic.fr/english/viewtop ... 98#p424198
here's what i was trying to do :
eliminate using :
Code: Select all
GetWindowRect_(GadgetID(2),r.RECT)
GetCursorPos_(p.POINT)
If PtInRect_(r,p\y << 32 + p\x)
ShellExecute_(0,"open","http://www.purebasic.com",0,0,#SW_SHOWNORMAL)
EndIf
and just use HyperLinkGadget "changing Color" along with Case #WM_LBUTTONUP,#PB_Event_LeftClick
to trigger ShellExecute_(0,"open","http://www.purebasic.com",0,0,#SW_SHOWNORMAL)
like in following Code, but
GetGadgetColor does not work like i thought it might ???
Code Example not working as expected :
Code: Select all
; Hyperlink_Test_v1.pb
; http://www.purebasic.fr/english/viewtopic.php?p=424198#p424198
LoadFont(0,"Tahoma",12,#PB_Font_HighQuality)
OpenWindow(1,0,0,400,500,"Hyperlink Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
EditorGadget(1,10,10,380,480,#WS_CLIPSIBLINGS)
AddGadgetItem(1,-1,"In case of emergecy Visit PureBasic to get help")
AddGadgetItem(1,-1,"Have fun")
HyperLinkGadget(2,160,12,106,22,"Visit PureBasic", #Red,#PB_HyperLink_Underline|#WS_CLIPSIBLINGS)
SetGadgetColor(2,#PB_Gadget_BackColor,#White)
SetGadgetColor(2,#PB_Gadget_FrontColor,#Gray)
BringWindowToTop_(GadgetID(2))
SetGadgetFont(1,FontID(0))
SetGadgetFont(2,FontID(0))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #WM_LBUTTONUP,#PB_Event_LeftClick
Color = GetGadgetColor(2, #PB_Gadget_FrontColor)
If Color = RGB(255,0,0)
ShellExecute_(0,"open","http://www.purebasic.com",0,0,#SW_SHOWNORMAL)
EndIf
EndSelect
Until Quit = 1
End
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 9:52 am
by rsts
Where are the hyperlinks originating?
Created in your program or from some external source?
If they're from an external HTML source they may not adhere to the "standard" colors.
cheers
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 12:10 pm
by RASHAD
Hi
GetGadgetColor() will get the color set by SetGadgetColor() not the highlighted
Simplified code
Code: Select all
Case #WM_LBUTTONUP,#PB_Event_LeftClick
If WindowFromPoint_ (DesktopMouseY() << 32 + DesktopMouseX()) = GadgetID(2)
ShellExecute_(0,"open","http://www.purebasic.com",0,0,#SW_SHOWNORMAL)
EndIf
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 12:18 pm
by PB
> how can you detect or get the new Color it changes to ??
You have to set it yourself, so you already know.

Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 12:23 pm
by RASHAD
He want to know when the color changed from normal to highlighted
GetGadgetColor() will NOT help in this case
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 12:26 pm
by PB
> He want to know when the color changed from normal to highlighted
I know. But he has to set that highlight color himself, so he already knows.
It's not something that gets changed by the OS or anything else at random.
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 12:36 pm
by RASHAD
You did not get the point
He want to know that the cursor is over the HyperLink() when he clicked the left mouse button by checking the color under the cursor
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 1:18 pm
by VB6_to_PBx
RASHAD wrote:You did not get the point
He want to know that the cursor is over the HyperLink() when he clicked the left mouse button by checking the color under the cursor
RASHAD ... you got it correct !
i already know the HyperLinkGadget is going to turn RED Color = RGB(255,0,0)
when i hover my Mouse Cursor over it
Then when i have "BOTH" a Mouse LeftClick + the HyperLinkGadget 's Color = RED
then i execute the following code =
ShellExecute_(0,"open","http://www.purebasic.com",0,0,#SW_SHOWNORMAL)
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 1:33 pm
by IdeasVacuum
...Use a webgadget for your links and all the issues are gone.
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 1:57 pm
by PB
VB6_to_PBx wrote:RASHAD ... you got it correct !

I was just confused by what you said here:
VB6_to_PBx wrote:when you Hover above HyperLinkGadget it changes Color ,
how can you detect or get the new Color it changes to ??
Very misleading, but I'm glad you got the answer you needed.
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 3:05 pm
by RASHAD
@VB6_to_PBx
You can use StringGadget() so you can control the font ,color,cursor ..etc
exam.
Code: Select all
Global Run,cur1,cur2
LoadFont(0,"Tahoma",12,#PB_Font_HighQuality)
LoadFont(1,"Tahoma",12,#PB_Font_HighQuality|#PB_Font_Underline)
cur1 = LoadCursor_(0,#IDC_HAND)
cur2 = LoadCursor_(0,#IDC_ARROW)
OpenWindow(1,0,0,400,500,"Hyperlink Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
EditorGadget(1,10,10,380,480,#WS_CLIPSIBLINGS)
AddGadgetItem(1,-1,"In case of emergecy Visit PureBasic to get help")
AddGadgetItem(1,-1,"Have fun")
StringGadget(2,156,12,106,22,"Visit PureBasic",#PB_String_BorderLess|#PB_String_ReadOnly|#WS_CLIPSIBLINGS)
SetGadgetColor(2,#PB_Gadget_BackColor,#White)
SetGadgetColor(2,#PB_Gadget_FrontColor,#Gray)
SetGadgetFont(1,FontID(0))
SetGadgetFont(2,FontID(0))
BringWindowToTop_(GadgetID(2))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #WM_MOUSEMOVE
If WindowFromPoint_(DesktopMouseY() << 32 + DesktopMouseX()) = GadgetID(2)
SetGadgetFont(2,FontID(1))
SetGadgetColor(2,#PB_Gadget_FrontColor,#Red)
SetCursor_(cur1)
Else
SetGadgetFont(2,FontID(0))
SetGadgetColor(2,#PB_Gadget_FrontColor,#Gray)
SetCursor_(cur2)
EndIf
Case #WM_LBUTTONUP,#PB_Event_LeftClick
If GetGadgetColor(2,#PB_Gadget_FrontColor) = #Red
ShellExecute_(0,"open","http://www.purebasic.com",0,0,#SW_SHOWNORMAL)
SetActiveGadget(1)
EndIf
EndSelect
Until Quit = 1
End
Re: HyperLinkGadget detecting change with GetGadgetColor
Posted: Sat Sep 14, 2013 3:27 pm
by netmaestro
Then when i have "BOTH" a Mouse LeftClick + the HyperLinkGadget 's Color = RED
then i execute the following code =
ShellExecute_(0,"open","http://www.purebasic.com",0,0,#SW_SHOWNORMAL)
Code: Select all
Procedure pbsite_linkhandler()
RunProgram("http://www.purebasic.com")
EndProcedure
OpenWindow(0, 0, 0, 270, 160, "HyperlinkGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
HyperLinkGadget(0, 20, 40, 250,20,"PureBasic Website", RGB(255,0,0))
BindGadgetEvent(0, @pbsite_linkhandler(), #PB_EventType_LeftClick)
Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow