June 16, 2024, 06:20:23 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Icons for websites

Started by Andy, May 23, 2012, 03:43:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Another feature that would be nice in the browser would be to display the current website's icon.

Took sometime to find out these are called favicons - and the icon itself is called "favicon.ico".

My idea is to have the icon for the site you are currently visiting to be loaded onto a small button just to the left of the URL address - just like IE, Firefox etc.

Attached is a sample of how to 'grab' the icon and save it, but struggling to load the icon image to a button.

I wanted to ask is this - firstly how do I load a downloaded icon to a button, trying the rgb_button example but no luck yet.

Secondly, what's the view on copyright? can you download icons OR is there a way of getting the website fav icon and load it into a button without downloading?  ???

Think it's an interesting question!

Thanks,
Andy.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Attachment here:
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Below is a slightly modified version of a program that Sapero wrote years ago.
Remember that each time you use LOADIMAGE you have to use DELETEIMAGE when you no longer need it displayed.
This should at least get you headed in the direction you want to go.

$include "windowssdk.inc"
Const ID_Button1 = 301
Const ID_Button2 = 302
Const ID_Button3 = 303
WINDOW d1

OpenWindow d1,0,0,105, 150,@CAPTION|@SYSMENU|@TOPMOST,0,"Caption",&handler
UINT hButton1, hButton2, hButton3, hFont
hButton1 = CreateWindowExA(0, "button", "", WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, 10,  5, 80, 40, d1.hwnd, ID_Button1, _hInstance, 0)
hButton2 = CreateWindowExA(0, "button", "", WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, 10, 45, 80, 40, d1.hwnd, ID_Button2, _hInstance, 0)
hButton3 = CreateWindowExA(0, "button", "", WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, 10, 85, 80, 40, d1.hwnd, ID_Button3, _hInstance, 0)
hFont = CreateFontA(12,4, 0,0, 0, 0,0,0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma")
SetWindowColor d1, rgb(221,221,221)
SendMessageA(hButton1, WM_SETFONT, hFont, True)
SendMessageA(hButton2, WM_SETFONT, hFont, True)
SendMessageA(hButton3, WM_SETFONT, hFont, True)
UINT hBrush1, hBrush2, Icon
Icon = LOADIMAGE(getstartpath+"favicon.ico", @IMGICON)

hBrush1 = CreateSolidBrush(rgb(0, 0, 255))
hBrush2 = CreateSolidBrush(rgb(255, 255, 0))
UINT winoriginal
winoriginal = GetWindowLong(d1.hwnd, GWL_WNDPROC)
SetWindowLong(d1.hwnd, GWL_WNDPROC, &SubclassWindow)
waituntil d1.hwnd=0
DELETEIMAGE Icon,@IMGICON

end

Sub handler(),int
   Select @MESSAGE
      Case @IDCREATE
         CenterWindow d1
      Case @IDCLOSEWINDOW
         DeleteObject(hBrush1) : DeleteObject(hBrush2)
         CloseWindow d1
      Case @IDCONTROL
         SetCaption d1, str$(@CONTROLID)
   EndSelect
   Return 0
EndSub
Sub SubclassWindow(hwnd:uint, uMsg:uint, wParam:uint, lParam:pointer),uint
   Select uMsg
      Case WM_DRAWITEM
         SetType lParam, DRAWITEMSTRUCT
         ry = #lParam.RcItem.Bottom
         FrameRect(#lParam.hDc, #lParam.rcItem, GetStockObject(BLACK_BRUSH))
         IF (#lParam.itemState & ODS_SELECTED)
         '   FillRect(#lParam.hDc, #lParam.rcItem, hBrush2)
         '   DrawEdge(#lParam.hDC, #lParam.rcItem, EDGE_SUNKEN, BF_RECT)
         '   SetBkMode(#lParam.hDC, @TRANSPARENT)
         '   SetTextColor(#lParam.hDC, rgb(0, 0, 0))
            DrawTextA(#lParam.hDC, "   Ouch!    ", -1, #lParam.RcItem, DT_SINGLELINE | DT_CENTER | DT_VCENTER)
         Else
         '   FillRect(#lParam.hDc, #lParam.rcItem, hBrush1)
         '   DrawEdge(#lParam.hDC, #lParam.rcItem, Edge_Raised, BF_RECT)
         '   SetBkMode(#lParam.hDC, @TRANSPARENT)
         '   SetTextColor(#lParam.hDC, rgb(255, 255, 255))
            DrawTextA(#lParam.hDC, "  Click me  ", -1, #lParam.RcItem, DT_SINGLELINE | DT_CENTER | DT_VCENTER)
         EndIf
         IF (#lParam.itemState & ODS_FOCUS)
            ' dotted rect
            DrawFocusRect(#lParam.hDC, #lParam.rcItem)
         EndIf
         IF #lParam.CtlID = ID_Button2
            DrawIconEx(#lParam.hDC, 3,3, icon, 32,32, 0, 0, DI_Normal)
         Endif
         Return 0
   EndSelect
   Return CallWindowProcA(winoriginal, hwnd, uMsg, wParam, lParam)
EndSub

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

That's a good example but I have problems with it:

The CreateWindowExA command creates a child window, which means it would be a child window of .urldlg
(Browser_Test2 example), which is in turn a child window of .win

Simply want to create a button and load a ".ico" image onto that button in the .urldlg window.

I cannot use the rgn_button_test example because it's limited to bitmaps not icon files which are a differnet format.

I will keep trying but if anyone has managed to do this please let me know.

Any news of when IWB3 will be available?

Thanks,
Andy.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Managed a workaround!

Dropped the button idea and just used this:

image1 = loadimage("C:\image2.ico",@IMGSCALABLE)
SHOWIMAGE w, image1, @IMGSCALABLE,28,80,20,20

See attached screen shot.

Thanks,
Andy.
:)


Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Quote from: andy1966 on May 24, 2012, 03:48:39 AM
That's a good example but I have problems with it:

The CreateWindowExA command creates a child window, which means it would be a child window of .urldlg
(Browser_Test2 example), which is in turn a child window of .win
I don't know why CreateWindowExA would be a problem.  That's the EXACT command that IWB uses to create all controls in a WINDOW.
I was under the impression you were WANTING it on a button.
QuoteMy idea is to have the icon for the site you are currently visiting to be loaded onto a small button just to the left of the URL address - just like IE, Firefox etc.
It was my mistake, I just misunderstood. I guess I was merging this with your right-click button need from before.

The main thing is you got it to do what you want.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library