icons and sizing

Nox ferocia
10-20-2004, 04: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)

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

10-20-2004, 05: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:

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:

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"

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, _
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:

Which is similiar to the code in this Microsoft article:
"How to Associate a Custom Icon with a Form"

...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):

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."

In regard to getting at (loading) different sizes of icons the second parameter of LoadPicture determines the icon size loaded (vbLPSmall, vbLPLarge, vbLPSmallShell, vbLPLargeShell):

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):

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"

Nox ferocia
10-20-2004, 07: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