icons and sizing

Nox ferocia
10-20-2004, 05:49 PM
I've created an icon which contains several sizes/color depths, and as per standard they are in order from smallest/least, to largest/greatest

using vb6 I wanted to dynamically assign the form icon based on the user enviroment setting

(ex. normal(96dpi) which yields 16x16 icons and large(120dpi) which yields 24x24 icons)

currently if I set the form icon it only uses the first entry which makes it blurry if too big, or poorly stretched if too small

I tried using
frmMe.Icon = setResPicture(101, 1)
with the icon added in the .res file as id 101 but this only selects the first resolution

the question is
A: must I add each resolution seperately?
B: how do I detect the users current dpi to choose the correct resolution(since it doesn't seem to detect this automatically)

PS
I also was wondering how I might provide the user with a button to set my application as the default for files of the type it uses, and set a custom icon for those... but this may be the wrong forum for that question

anon
10-20-2004, 06:36 PM
using vb6 I wanted to dynamically assign the form icon based on the user enviroment setting
In regard to your question:
"must I add each resolution seperately?" - you don't have to, it's up to you

To detect for a resolution change the windows message you are looking for is WM_DISPLAYCHANGE. Here's some subclassing code:
http://www.devx.com/vb2themax/Tip/18412

The Screen object also has this info. You could put a detect routine in your form load or have it run as a loop in a timer:
http://216.239.57.104/search?q=cache:6zx0nVPCKqAJ:www.vb-helper.com/howto_screen_resolution.html+vb+get+screen+resolution&hl=en

There's also the GetSystemMetrics with the SM_CYSCREEN parameter.

As regards using different icons in VB, here's some reading:
"Working with Icons in VB"
http://www.windowsdevcenter.com/pub/a/windows/2004/08/17/VB_icons.html

You can also use the SendMessage API to change your form's icon at runtime:

Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Public Declare Function DestroyIcon Lib "user32" _
(ByVal hIcon As Long) As Long

Declare Function LoadImage Lib "user32" Alias "LoadImageA" _
(ByVal hInst As Long, ByVal lpsz As String, _
ByVal un1 As Long, ByVal n1 As Long, _
ByVal n2 As Long, ByVal un2 As Long) As Long

Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long

Public Const WM_SETICON = &H80
Public Const ICON_SMALL = 0
Public Const IMAGE_ICON = 1
Public Const LR_LOADFROMFILE = &H10

Private Sub Form_Open(Cancel As Integer)
SendMessage Me.hwnd, WM_SETICON, ICON_SMALL, _
LoadImage(0, "C:\TEST.ICO", IMAGE_ICON, 0, 0, LR_LOADFROMFILE)
End Sub

Private Sub Form_Close()
Dim hIcon As Long
hIcon = SendMessage(hwnd, WM_SETICON, ICON_SMALL, 0)
If hIcon <> 0 Then DestroyIcon hIcon
End Sub

from this Russian page:
http://am.rusimport.ru/MSAccess/topic.aspx?ID=224

Which is similiar to the code in this Microsoft article:
"How to Associate a Custom Icon with a Form"
http://support.microsoft.com/?kbid=304264

...or you can use an external dll to store your icon resources and load them at runtime.
Using resources located in an external dll file (http://www.thevbzone.com/l_res.htm#USING RESOURCES LOCATED IN AN EXTERNAL DLL FILE)
In the above link note the use of "Private Const ICON_BIG = 1"

A little extra info (tips):

tip1
When storing icons in the Imagelist control (so they become part of the frx file and are compiled with your exe): "Always use the 'custom' setting for the imagelist size. I once used the predefined 16x16 size and it was messing my icons up, but when I removed them all and set it to a custom they came out much better."
http://vbcity.com/forums/topic.asp?tid=9295&#RID29271

tip2
In regard to getting at (loading) different sizes of icons the second parameter of LoadPicture determines the icon size loaded (vbLPSmall, vbLPLarge, vbLPSmallShell, vbLPLargeShell):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/vbfctloadpicture.asp

tip3
Visible Cues from a Minimized Form
Suppose you want a form to perform a task while minimized, then notify the user without a message box and while remaining minimized. You can send a message via a changing icon on the minimized form in the taskbar.
Create a form containing a timer and an image list. Set the timer's Interval property to 2000, then use the ImageList control's Custom property to add three images. Finally, add this code to the Timer event:

Private Sub Timer1_Timer()
Static iImage As Integer
iImage = iImage + 1
If iImage > 3 Then iImage = 1
Me.Icon = ImageList1.ListImages(iImage).Picture
End Sub

(from angelfire site with popup - sorry):
http://www.angelfire.com/ar2/visualbasic/

In regard to your last question
how I might provide the user with a button to set my application as the default for files of the type it uses:
"Creating and associating my own file type"
http://www.xtremevbtalk.com/t181802.html

Nox ferocia
10-20-2004, 08:44 PM
much thanks, plenty of info to go through

It looks like "getSystemMetrics" is just what I was looking for, only with the SM_CYSIZE to choose the properly sized icon based on user dpi (which affects title bar height)

the other link for filetype association was also just what what was needed thank you =)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum