The information in this article applies to:
SYMPTOMSThe code to get to the window class name via the CBT_CREATEWND structure in a CBT callback function may look like the following:
However, this code may or may not output the correct class name,
depending on what the call to CreateWindow() (for the window about to
be created) looks like.
The CBT_CREATEWND structure contains information passed to a WH_CBT
hook callback function before a window is created in the system. The
lpszClass field of this CBT_CREATEWND structure may return an invalid
class name, particularly for windows created internally by the system.
RESOLUTIONWindows provides the GetClassName() function to allow applications to retrieve a window's class name. This function takes the handle to the window as a parameter, as well as a buffer to receive the null-terminated class name string. This function is a more reliable and a more recommended means to obtain window class name information than the CBT callback function's CBT_CREATEWND structure. STATUSThis behavior is by design. MORE INFORMATION
Whenever a window is about to be created, Windows checks to see if a
WH_CBT hook is installed anywhere in the system. If it finds one, it
calls the CBTProc() callback function with hook code set to
HCBT_CREATEWND, and with the lParam parameter containing a long
pointer to a CBT_CREATEWND structure.
with the CREATESTRUCT structure defined in the same file as:
When Windows internally creates windows (such as predefined controls
in a dialog box, for example), it uses atoms for lpszClass instead of
the actual string to minimize overhead. This makes it a little less
straightforward (sometimes impossible) to get to the actual class name
directly from the lpszClass field of the CREATESTRUCT structure.
To cite one particular example, when an application is minimized in Windows, Windows calls CreateWindow() for the icon title, specifying a class name of
where MAKEINTATOM() is defined in WINDOWS.H as:
Given this, to get to the actual class name, GetAtomName() must be
called in this manner:
This outputs a class name of #32772 for the IconTitleClass.
For predefined controls, such as "static", "button", and so forth, in a dialog box, the Dialog Manager calls CreateWindow() on each control, similarly using atoms for lpszClass. The Dialog Manager, however, creates these atoms in a local atom table in USER's default data segment (DS), thus making it impossible for other applications to get to these class names. [Note the difference between local and global atom tables, where global atom tables are stored in a shared DS, and are therefore accessible to all applications, while local atom tables are stored in USER's default DS. DDE uses global atom tables so that Excel, for example, can use GlobalAddAtom() to add a string to the atom table, and another program could use GlobalGetAtomName() to obtain the character string for that atom.] More information on atoms can be found by searching on the following word in the Microsoft Knowledge Base: atomsMore Information can also be found in the Windows version 3.1 online Help file under the heading Function Groups, under the Atom Functions subheading. Additional query words:
Keywords : kbHook kbNTOS kbWinOS2000 kbSDKWin32 kbGrpUser kbWinOS kbWndw kbWndwClass |
Last Reviewed: February 3, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |