C# SendMessage(...) question

N

Nidhi

Hi,

I am trying to write code to retrieve the small icon for an
application in C#. I am using SendMessage with WM_GETICON for this
purpose but the return value I get is 0. I don't understand this. Is
that expected? What am I doing wrong?
Any help would be appreciated. Here is the snippet of code that I am
using -

[DllImport("user32")] public static extern int SendMessage(int
hwnd,int msg,int wparam,int lparam);

Process p = Process.GetProcessById(a.getPID()); //the requisite process and
//the value returned is valid
IntPtr hwnd = p.MainWindowHandle;
int icn = SendMessage((int)hwnd,127,0,0); //I realize WM_GETICON = 127

Thanks!
Nidhi
 
M

MagicAxe via DotNetMonster.com

Just try this :

int WM_GETICON = 0x7F;
int WM_SETICON = 0x80;
int ICON_SMALL = 0; //(16x16)
int ICON_BIG = 1; //(32x32)

IntPtr handle = pro.MainWindowHandle;
int IconHandle = SendMessage(handle.ToInt32(),WM_GETICON,ICON_SMALL -or- ICON_BIG,0);
Icon icn = Icon.FromHandle(new IntPtr(IconHandle));

Note : I can't retrieve the most icon's handle.

- Good Kiss from Switzerland -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top