|
Registering Window Classes
A window class is supported by a window procedure. You can register a window
class by using either the RegisterClassA or RegisterClassW function. If you register the window class by using RegisterClassA, the application tells the system that the windows of the created class
expect messages with text or character parameters to use the ANSI character set; if
you register it by using RegisterClassW, the application requests that the system pass text parameters of messages as
Unicode. The IsWindowUnicode function enables applications to query the nature of each window.
The following example shows how to register an ANSI window class and a Unicode
window class and how to write the window procedures for both cases. For the
purposes of this example, all functions and structures are shown with the
specific A or W data types. Using the techniques explained in Using Generic Data Types, you could alternatively write this example by using generic data types, so
that it could be compiled as either ANSI or Unicode, depending on whether
UNICODE is defined.
/* Register an ANSI window class. */
WNDCLASSA AnsiWndCls;
AnsiWndCls.style = CS_DBLCLKS | CS_PARENTDC;
AnsiWndCls.lpfnWndProc = (WNDPROC)AnsiWndProc;
AnsiWndCls.cbClsExtra = 0;
AnsiWndCls.cbWndExtra = 0;
AnsiWndCls.hInstance = hmodUser;
AnsiWndCls.hIcon = NULL;
AnsiWndCls.hCursor = LoadCursor(NULL, (LPTSTR)IDC_IBEAM);
AnsiWndCls.hbrBackground = NULL;
AnsiWndCls.lpszMenuName = NULL;
AnsiWndCls.lpszClassName = "TestAnsi";
RegisterClassA(&AnsiWndCls);
/* Register a Unicode window class. */
WNDCLASSW UnicodeWndCls;
UnicodeWndCls.style = CS_DBLCLKS | CS_PARENTDC;
UnicodeWndCls.lpfnWndProc = (WNDPROC)UniWndProc;
UnicodeWndCls.cbClsExtra = 0;
UnicodeWndCls.cbWndExtra = 0;
UnicodeWndCls.hInstance = hmodUser;
UnicodeWndCls.hIcon = NULL;
UnicodeWndCls.hCursor = LoadCursor(NULL,(LPTSTR)IDC_IBEAM);
UnicodeWndCls.hbrBackground = NULL;
UnicodeWndCls.lpszMenuName = NULL;
UnicodeWndCls.lpszClassName = L"TestUnicode";
RegisterClassW(&UnicodeWndCls);
The following example shows the difference between handling the WM_CHAR
message in an ANSI window procedure and a Unicode window procedure.
/* ANSI Window Procedure */
LONG AnsiWndProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
/* Dispatch the messages that can be received. */
switch (message) {
case WM_CHAR:
/*
* wParam - the value of the key
* lParam - (not used in this example)
*/
if (lstrcmpA("Q", (LPCSTR) wParam)) {
/*.
/*.
/*.
}
else {
./*
/*.
/*.
}
break;
./*
./* process other messages */
./*
}
}
/* Unicode Window Procedure */
LONG UniWndProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
/* Dispatch the messages that can be received. */
switch (message) {
case WM_CHAR:
/*
* wParam - the value of the key
* lParam - (not used in this example)
*/
if (lstrcmpW(L"Q", (LPCWSTR) wParam)) {
/*.
/*.
/*.
}
else {
/*.
/* .
/* .
}
break;
/* .
/* process other messages */
/* .
}
}
All text in messages received by AnsiWndProc will be composed of ANSI
characters, and all text in messages received by UniWndProc will be composed of Unicode
characters.
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|