Shoutbox

lpClassName - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: lpClassName (/showthread.php?tid=74487)

lpClassName by saralk on 05-18-2007 at 12:24 PM

How do you find out the ClassName of an application?


RE: lpClassName by Matti on 05-18-2007 at 04:27 PM

You might want to take a look at this page in the MSDN library.

quote:
Parameters
    hWnd
        [in] Handle to the window and, indirectly, the class to which the window belongs.
    lpClassName
        [out] Pointer to the buffer that is to receive the class name string.
    nMaxCount
        [in] Specifies the length, in TCHAR, of the buffer pointed to by the lpClassName parameter. The class name string is truncated if it is longer than the buffer and is always null-terminated.
That means:
  • hWnd - The handle of the window, I guess you know how to retrieve that.
  • lpClassName - A buffer, so that means a DataBloc created by Interop.Allocate.
  • nMaxCount - Seems like the Win32 API even lets you choose how big you want to make your DataBloc. This is the length of the buffer you created for retrieving the class name.
According to this information, I guess you have to make something like this:

WARNING: UNTESTED CODE. Mattike was too bored to actually test this, since he would have no idea what to test it on.
code:
var hWnd = ChatWnd.Handle; //A handle of a window to get the class name from? I guess you know what to do with this.
var bufferClass = Interop.Allocate((255+1)*2); //Should be big enough I guess?
Interop.Call("user32", "GetClassName", hWnd, bufferClass, bufferClass.Size); //I think it's quite self-explaining...
Why don't you try it, and tell us if it worked? :P
RE: lpClassName by CookieRevised on 05-18-2007 at 04:45 PM

quote:
Originally posted by saralk
How do you find out the ClassName of an application?
It depends on what you mean by 'application'...

An application can contain many windows, and each window can have its own classname.

Also classnames are rarely unique. Many windows have the same classname (just pointing it out as this is sometimes a mistake made when searching for windows with Windows APIs like FindWindow)...

quote:
Originally posted by Mattike
[*]nMaxCount - Seems like the Win32 API even lets you choose how big you want to make your DataBloc.
Not really, a classname has a maximum length of 256 characters, incl. null character (iirc). This means your buffer must always be at least 256 characters big.

Also the Windows API GetClassName comes in two modes, ascii and wide. So you need to specify this too (best to use the wide/unicode version): Interop.Call("user32", "GetClassNameW", ...
RE: lpClassName by saralk on 05-18-2007 at 05:06 PM

ok, i'll tell you what I want to do and maybe you can help me more :)

I want to get the tooltip of a program that has been minimized to the tray (the bit next to the clock)


RE: lpClassName by Matti on 05-19-2007 at 01:18 PM

Well, you can use Shell_NotifyIconW to create a tray icon and it uses a NOTIFYICONDATA structure for the information, but I can't seem to find a function to retrieve such structure from a tray icon...