473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Calling Pick Icon dialog from C#

Can anybody tell me how I can call the Pick Icon Dialog from C#? I
couldn't find any example.
Thanks.
Nov 16 '05 #1
4 4607
kurotsuke wrote:
Can anybody tell me how I can call the Pick Icon Dialog from C#? I
couldn't find any example.
Thanks.


[DllImport("shell32.dll", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.Winapi)]
private static extern int PickIconDlg(IntPtr hwndOwner,
System.Text.StringBuilder lpstrFile, int nMaxFile, ref int lpdwIconIndex);

private void button1_Click(object sender, System.EventArgs e)
{
string iconfile;
int iconindex = 0;
int retval;
System.Text.StringBuilder sb;

iconfile = Environment.GetFolderPath(Environment.SpecialFolde r.System);
iconfile = iconfile + @"\shell32.dll";
sb = new System.Text.StringBuilder(iconfile, 500);
retval = PickIconDlg(this.Handle, sb, sb.Length, ref iconindex);
iconfile = sb.ToString();
}

Cheers

Arne Janning
Nov 16 '05 #2
On Thu, 03 Jun 2004 01:10:38 +0200, Arne Janning
<sp*****************@msn.com> wrote:
kurotsuke wrote:
Can anybody tell me how I can call the Pick Icon Dialog from C#? I
couldn't find any example.
Thanks.


[DllImport("shell32.dll", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.Winapi)]
private static extern int PickIconDlg(IntPtr hwndOwner,
System.Text.StringBuilder lpstrFile, int nMaxFile, ref int lpdwIconIndex);

private void button1_Click(object sender, System.EventArgs e)
{
string iconfile;
int iconindex = 0;
int retval;
System.Text.StringBuilder sb;

iconfile = Environment.GetFolderPath(Environment.SpecialFolde r.System);
iconfile = iconfile + @"\shell32.dll";
sb = new System.Text.StringBuilder(iconfile, 500);
retval = PickIconDlg(this.Handle, sb, sb.Length, ref iconindex);
iconfile = sb.ToString();
}

Cheers

Arne Janning


Thanks. Can you give me an hint on using the ExtractIcon to extract
the retrieve icon? How can I draw it on a PictureBox. Thanks again.
Andrea
Nov 16 '05 #3
kurotsuke wrote:
Thanks. Can you give me an hint on using the ExtractIcon to extract
the retrieve icon? How can I draw it on a PictureBox. Thanks again.
Andrea


[DllImport("shell32.dll", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.Winapi)]
private static extern int PickIconDlg(IntPtr hwndOwner,
System.Text.StringBuilder lpstrFile, int nMaxFile, ref int lpdwIconIndex);

[DllImport("shell32.dll", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.Winapi)]
public static extern IntPtr ExtractIcon(IntPtr hInstance, string
strFileName, uint uiIconIndex);

private void button1_Click(object sender, System.EventArgs e)
{
string iconfile;
int iconindex = 2;
int retval;
System.Text.StringBuilder sb;

iconfile = Environment.GetFolderPath(Environment.SpecialFolde r.System);
iconfile = iconfile + @"\shell32.dll";
sb = new System.Text.StringBuilder(iconfile, 500);
retval = PickIconDlg(this.Handle, sb, sb.Capacity, ref iconindex);
iconfile = sb.ToString();
Graphics g = pictureBox1.CreateGraphics();
g.DrawIconUnstretched(extractIcon(iconfile, iconindex), new
Rectangle(0, 0, 50, 50));
}

public static Icon extractIcon(string strPath, int nIndex)
{
Icon icon = null;
IntPtr hIcon = ExtractIcon(IntPtr.Zero, strPath, (uint)nIndex);
if (IntPtr.Zero != hIcon)
{
icon = Icon.FromHandle(hIcon);
}
return icon;
}

Cheers

Arne Janning
Nov 16 '05 #4
On Thu, 03 Jun 2004 23:07:24 +0200, Arne Janning
<sp*****************@msn.com> wrote:
[DllImport("shell32.dll", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.Winapi)]
private static extern int PickIconDlg(IntPtr hwndOwner,
System.Text.StringBuilder lpstrFile, int nMaxFile, ref int lpdwIconIndex);

[DllImport("shell32.dll", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.Winapi)]
public static extern IntPtr ExtractIcon(IntPtr hInstance, string
strFileName, uint uiIconIndex);

private void button1_Click(object sender, System.EventArgs e)
{
string iconfile;
int iconindex = 2;
int retval;
System.Text.StringBuilder sb;

iconfile = Environment.GetFolderPath(Environment.SpecialFolde r.System);
iconfile = iconfile + @"\shell32.dll";
sb = new System.Text.StringBuilder(iconfile, 500);
retval = PickIconDlg(this.Handle, sb, sb.Capacity, ref iconindex);
iconfile = sb.ToString();
Graphics g = pictureBox1.CreateGraphics();
g.DrawIconUnstretched(extractIcon(iconfile, iconindex), new
Rectangle(0, 0, 50, 50));
}

public static Icon extractIcon(string strPath, int nIndex)
{
Icon icon = null;
IntPtr hIcon = ExtractIcon(IntPtr.Zero, strPath, (uint)nIndex);
if (IntPtr.Zero != hIcon)
{
icon = Icon.FromHandle(hIcon);
}
return icon;
}

Cheers

Arne Janning


Thanks again for your help. I'm exepriencing a problem though. I
noticed that the returned iconfile is
@"C:\windows\system32\shell32.dl" (with only one 'L' instead of two).
That causes an error?
Why do I have to use the StringBuilder structure to call the API?
Couldn't I just use the string?
Since sb is modified by the API shouldn't I pass it by reference?
One final question? After extracting the icon, shouldn't I call
DestoryIcon?

Thanks again for your help and patience.
Andrea
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Raghul | last post by:
Hi friends, I am creating a jabber client and a separate class for dialog is created,So when the roster name is clicked this dialog open and can continue chat.What I need is I am calling the same...
2
by: Roger | last post by:
form A has a command button that opens form B in dialog mode DoCmd.openForm "frmProductPrice", acNormal, , , acFormEdit, acDialog, productId form B is a tabular form with 3 'required' fields ...
14
by: ericellsworth | last post by:
Hi, I'm trying to use a class to pass variables back and forth from a form opened in dialog mode. I have created a class which invokes a form in its show method, like so: Public Sub Show() '...
8
by: deko | last post by:
What is the best way to get a Common Dialog in Access 2000 Standard Edition? Microsoft suggests this: Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _ "GetOpenFileNameA"...
0
by: Vladimir Perkic | last post by:
Hi! Does anybody know how can I create dialogbox which can be moved. Im using CreateDialog function. Also, System icon menu and "Close" button don't respond to mouse actions. Style I defined in...
0
by: Ghazanfar Ali | last post by:
Hi All: I am developing Dialog based application. I have placed Microsoft WebBrowser control(IE control) on main Dialog of application. On the IE control, i have drawn an image on the IE control...
4
by: Jerry Camel | last post by:
I'm using a DHTML dialog to present a pick-list to a user. I've got the dialog working using some client side vbscript with a call to window.ShowModalDialog. I can see that the result is being...
3
by: Marcpp | last post by:
I call a dialog from a principal program but cannot return the value of the variables (text box's). Here is a example... from ui import Agenda from dialog1 import dialogo1 from PyQt4...
2
by: =?Utf-8?B?U29tZXNo?= | last post by:
Hi Friends, I would like to show the Open With dialog of windows (the one which is shown when windows couldn't find the application to open the file) to the user on some specific event. Can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.