Page 1 of 1

Window Icons

Posted: Fri Jun 04, 2004 3:31 pm
by neomancer
How do i get an ICON in the window? like they normally do? system control box (top left)

Re: Window Icons

Posted: Fri Jun 04, 2004 3:48 pm
by Manolo
neomancer wrote:How do i get an ICON in the window? like they normally do? system control box (top left)
This one template from Franco

Code: Select all

; (c) 2001 - Franco's template - absolutely freeware
; How to change an application icon on the fly 
Procedure ChangeAppIcon(Image$)  
hIco=LoadImage(0,Image$)  
SetClassLong_(WindowID(),#GCL_HICON,hIco)
EndProcedure 
;test
If OpenWindow(0, 200, 200, 320,240, #PB_Window_SystemMenu ,"Test Window")
ChangeAppIcon("yourico.ico") ; <- your icon name...   
Repeat    
EventID.l = WaitWindowEvent()  
Until EventID = #PB_EventCloseWindow
EndIf 
End
Manolo :wink:

Posted: Fri Jun 04, 2004 3:49 pm
by fweil
Was to slow !

I loose ...

Code: Select all

If OpenWindow(0, 100, 200, 195, 260, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")
  hIcon = LoadIcon_(0, #IDI_ASTERISK)
  Debug SetClassLong_(WindowID(), #GCL_HICON, hIcon)
  Repeat
    EventID.l = WaitWindowEvent()
    If EventID = #PB_Event_CloseWindow
      Quit = 1
    EndIf
  Until Quit = 1
EndIf
End

Posted: Fri Jun 04, 2004 6:40 pm
by Karbon
Yet another way :

Code: Select all

SendMessage_(WindowID(#Window), #WM_SETICON, 0, UseImage(#Icon))

Posted: Fri Jul 15, 2005 2:36 am
by Randy Walker
I've tried all 3 variations and they all work but, my icons come up corrupted in the title bar of all my windows.

Same icon works fine if I provide the path and let the editor/compiler install the icon for me. Do these methods of changing icons depend on a specific icon format? My current icon is 32x32 and I think 256 color.

Posted: Fri Jul 15, 2005 7:29 am
by Blade
Perhaps your icon is XP and your system is W2000 or less...

Posted: Fri Jul 15, 2005 8:38 am
by Fou-Lu
Now that you mention that, what's the difference between a XP icon and a win9x icon? I always thought that icons were just .bmp files with a different extension. :?

Posted: Fri Jul 15, 2005 1:24 pm
by Dare2
.ico files are bmp-ish but can hold more than one image, eg, 16x16, 32x32, 48x48 instances.

If your .ico holds sizes not compatible with the destination then I think it gets resized and that can cause poor results.

Software like iconedit allows you to edit/create icon files with instances that work best for each requirement.

Posted: Fri Jul 15, 2005 10:45 pm
by Randy Walker
My OS is XP Pro and XP Home and both have same symptoms. Both show icons fine if installed during compile. Both show distorted icons when I load and apply them manually. The icons I am using were created back in the Win95 era so I would expect them to be compatible.

I pulled down SNicon as suggested elseware, loaded my icon and saved it thinking maybe Snicon woulld fix any OS incompatibility. That made no difference. Tried both the SetClassLong and the SendMessage approaches and both render distorted icons. Icons appeareing when using Alt-Tab look fine no mattter what.

Posted: Fri Jul 15, 2005 11:19 pm
by netmaestro
You can choose an icon for your application on the compiler options menu.

Posted: Sat Jul 16, 2005 4:00 am
by Intrigued
Thanks for sharing the run-time way of showing a different icon for a given window. I was wondering if that was possible a few weeks ago.

Posted: Sat Jul 16, 2005 9:22 am
by Randy Walker
netmaestro wrote:You can choose an icon for your application on the compiler options menu.
I know that... and that gives me a perfect icon in my title bar... BUT when I change the icon using ether of the two methods:

SetClassLong_(WindowID(), #GCL_HICON, hIcon)

-or-

SendMessage_(WindowID(), #WM_SETICON, 1, hIcon)

The icon in the title bar is replaced and looks very distorted. My question is NOT "how to change the icon?" It is "Why does the icon get corrupted when my app loads it in manually?"

Posted: Sat Jul 16, 2005 11:19 am
by Num3
This works fine for me, without problems or distortions!

As long has i use 16 x 16 icons!