HyperLinkGadget detecting change with GetGadgetColor

Just starting out? Need help? Post your questions and find answers here.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

HyperLinkGadget detecting change with GetGadgetColor

Post 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 .
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: HyperLinkGadget detecting change with GetGadgetColor

Post 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.
BERESHEIT
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: HyperLinkGadget detecting change with GetGadgetColor

Post 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
Egypt my love
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: HyperLinkGadget detecting change with GetGadgetColor

Post 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

 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: HyperLinkGadget detecting change with GetGadgetColor

Post 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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: HyperLinkGadget detecting change with GetGadgetColor

Post 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 
Egypt my love
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: HyperLinkGadget detecting change with GetGadgetColor

Post by PB »

> how can you detect or get the new Color it changes to ??

You have to set it yourself, so you already know. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: HyperLinkGadget detecting change with GetGadgetColor

Post by RASHAD »

He want to know when the color changed from normal to highlighted
GetGadgetColor() will NOT help in this case
Egypt my love
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: HyperLinkGadget detecting change with GetGadgetColor

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: HyperLinkGadget detecting change with GetGadgetColor

Post 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
Egypt my love
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: HyperLinkGadget detecting change with GetGadgetColor

Post 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)
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: HyperLinkGadget detecting change with GetGadgetColor

Post by IdeasVacuum »

...Use a webgadget for your links and all the issues are gone.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: HyperLinkGadget detecting change with GetGadgetColor

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: HyperLinkGadget detecting change with GetGadgetColor

Post 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
Egypt my love
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: HyperLinkGadget detecting change with GetGadgetColor

Post 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
BERESHEIT
Post Reply