Page 1 of 1
Hyperlink Gadget over image [solved]
Posted: Thu Jun 15, 2006 12:27 am
by neomember
I want to create an 'Autorun CD Menu' to launch programs from a cd. I used to do it with Multimedia Builder before but now i think that i should be able to create my own.
This is what i need:
Text which change color on mouse over (colors that i can choose);
Keep text transparency (to put an image underneath);
Open urls or launch programs by single clicking on text.
I tried several methods but none of them worked perfectly. I used a lot of code found of this forum.
I've tried the 'drawing stuff' approach.
I've tried the 'send transparency message to static' approach.
I've tried the 'Hyperlink library from somebody' approach.
I've tried the 'HyperLinkGadget' approach.
I always end up at least one thing not working properly. I have problems layering text over image. If i set the 'static' transparency, the background of the 'static' is gray (from the window) instead of showing the image underneath the control. I've tried the 'HyperLinkGadget' but i end up with some other problems which i don't remember (i think it was the color, it's been a while). The only thing i haven't tried is to draw both the image and the controls on the form.
I know it sounds simple but i've never seen a working example so far (that met all these conditions).
I'm wondering now if it's possible to do so with a reasonably simple piece of code.
Any advices??
Thanks in advance!!!
Posted: Thu Jun 15, 2006 3:46 am
by netmaestro
Well, I don't suppose this is necessarily the most elegant or simple solution, but it's guaranteed to work or double your money back.
Code: Select all
;==========================================================
; Program: Transparent Hyperlink Menu
; Author netmaestro
; Date: June 15, 2006
; Target OS: Windows All
; Target Compiler: PureBasic Version 4.0
;==========================================================
;
; Prairie Wind.bmp should be in your windows folder, if not
; pick something else.
;
Declare ProcessSomething()
Declare ProcessSomethingElse()
Declare ProcessAThirdThing()
Structure MenuItem
text.s
loc.RECT
action.l
EndStructure
Global NewList HotSpot.MenuItem()
AddElement(HotSpot())
With HotSpot()
\text = "Go Somewhere And Do Something"
\loc\left = 200
\loc\top = 200
\loc\right = 425
\loc\bottom = 220
\action = @ProcessSomething()
EndWith
AddElement(HotSpot())
With HotSpot()
\text = "Go Elsewhere And Do Something Else"
\loc\left = 200
\loc\top = 240
\loc\right = 455
\loc\bottom = 260
\action = @ProcessSomethingElse()
EndWith
AddElement(HotSpot())
With HotSpot()
\text = "Go Elsewhere And Do a Third Thing"
\loc\left = 200
\loc\top = 280
\loc\right = 455
\loc\bottom = 300
\action = @ProcessAThirdThing()
EndWith
Global handcursor = LoadCursor_(0, #IDC_HAND)
Global arrowcursor = LoadCursor_(0, #IDC_ARROW)
LoadFont(0,"Arial", 14, #PB_Font_Bold)
Macro ShowMenuItem(hs,color)
StartDrawing(WindowOutput(0))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(hs\loc\left, hs\loc\top, hs\text, color)
StopDrawing()
EndMacro
Procedure.l MouseInRect(*region.menuitem, x, y)
If (x >= *region\loc\left) And (x <= *region\loc\right)
If (y >= *region\loc\top) And (y <= *region\loc\bottom)
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndIf
EndProcedure
Procedure ProcessHotspots(x,y,caller)
livespot = #False
Select caller
Case #WM_MOUSEMOVE, #WM_PAINT, #WM_LBUTTONUP
;*********************************
; Display Section
;*********************************
StartDrawing(WindowOutput(0))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(0))
DrawText(240,140,"Things to Do:", #White)
StopDrawing()
ForEach Hotspot()
If MouseInRect(HotSpot(),x,y)
ShowMenuItem(HotSpot(),#Yellow)
livespot = #True
Else
ShowMenuItem(HotSpot(),#Red)
EndIf
Next
If livespot
SetCursor_(handcursor)
Else
SetCursor_(arrowcursor)
EndIf
Case #WM_LBUTTONDOWN
;*********************************
; Action Section
;*********************************
ForEach HotSpot()
If MouseInRect(HotSpot(),x,y)
CallFunctionFast(HotSpot()\Action)
ProcessHotSpots(WindowMouseX(0),WindowMouseY(0),#WM_PAINT)
Break
EndIf
Next
EndSelect
EndProcedure
OpenWindow(0, 0, 0, 640, 480, "Transparent Hyperlink", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
hBrush = CreatePatternBrush_(CatchImage(0, ?Image))
SetClassLong_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(WindowID(0), 0, #True)
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #WM_LBUTTONDOWN,#WM_MOUSEMOVE,#WM_PAINT,#WM_LBUTTONUP
ProcessHotSpots(WindowMouseX(0),WindowMouseY(0),EventID)
EndSelect
Until EventID=#PB_Event_CloseWindow
DeleteObject_(hBrush)
End
DataSection
Image: IncludeBinary "c:\windows\prairie wind.bmp"
EndDataSection
Procedure ProcessSomething()
Debug "OK, Got Something! I'll get right on it!"
EndProcedure
Procedure ProcessSomethingElse()
Debug "OK, Got Something Else! I'll get right on it!"
EndProcedure
Procedure ProcessAThirdThing()
Debug "OK, Got a Third Thing! I'll get right on it!"
EndProcedure
Posted: Thu Jun 15, 2006 4:03 am
by neomember
Well... is it for PB 4.0??
I have PB 3.94 and it doesn't compile. Gives me syntax error on line 15.
Posted: Thu Jun 15, 2006 4:05 am
by netmaestro
Sorry, the forum was butchering my code. But everything I write is for 4.0.
[edit] Got past the forum problem, the latest code is posted correctly now.
Posted: Thu Jun 15, 2006 7:24 am
by mskuma
netmaestro, nice example, thanks! Lots of good learning value in that one

Posted: Thu Jun 15, 2006 5:17 pm
by neomember
That will get me occupied for a while.
Thanks!!
Posted: Thu May 15, 2008 5:44 am
by Blue
Wow! A buried gem.
Thanks, NetMaestro.