C# ExtractIcon函数和ShellExecute函数问题(只回答一个也给分!)

yddawzy 2010-04-16 05:20:54
问题一:
[DllImport("shell32.dll", EntryPoint="ShellExecute")]
public static extern int ShellExecute (
int hwnd,
string lpOperation,
string lpFile,
string lpParameters,
string lpDirectory,
int nShowCmd
);
那个hwnd参数如何赋值呢? 有时候有的应用程序启动前会有个消息对话框,我赋值为0时,只显示对话框,主程序不显示!


问题二:
[DllImport("shell32.dll", EntryPoint="ExtractIcon")]
public static extern int ExtractIcon (
int hInst,
string lpszExeFileName,
int nIconIndex
);

那个hInst参数如何赋值呢? 我赋值为this.handle 但是不知道对不对。还有这个函数返回值是图标的句柄,如何得到句柄所指向的图标呢? 困惑中!。。。

谢谢各位高手了
再次感谢...

...全文
201 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgke 2010-04-19
  • 打赏
  • 举报
回复
给你个例子把

IntPtr icons = ExtractIcon(this.Handle, @"C:\WINDOWS\dialer.exe", 0);

Icon _Icon = Icon.FromHandle(icons);

this.Icon = _Icon;
wuyq11 2010-04-16
  • 打赏
  • 举报
回复
wuyq11 2010-04-16
  • 打赏
  • 举报
回复
[DllImport("shell32")]
private static extern int ExtractIcon(int hinst, string lpszExeFileName, int nIconIndex);
IntPtr hIcon=(IntPtr)ExtractIcon(this.Handle, FileName, nIconIndex);
int icons = ExtractIcon(0, Application.ExecutablePath, 0);
ChrisAK 2010-04-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zgke 的回复:]
1 指定父窗口句柄 C#可以使用 Control.Handle 或则Form.Handle获取
如果0 就是桌面

2 Icon a =Icon.FromHandle(hInst);
[/Quote]Icon的FromHandle函数的参数是HICON吧
这里的hInst指的是载入的映像的HINSTANCE.函数通过
它在内存映像中检索图标资源.一般是用LoadLibrary载
入dll/exe得到的.这俩不是同一个东西
zgke 2010-04-16
  • 打赏
  • 举报
回复
1 指定父窗口句柄 C#可以使用 Control.Handle 或则Form.Handle获取
如果0 就是桌面

2 Icon a =Icon.FromHandle(hInst);
平生我自如 2010-04-16
  • 打赏
  • 举报
回复
没有弄过阿! 祝你周末愉快

110,565

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧