![]() hInstance is the instance handle, described previously.This example does not use a menu, so the value is NULL. For an application window, the next parameter defines the menu for the window.For a top-level window, set this to NULL. Set the parent if you are creating a child window. The next parameter sets a parent window or owner window for the new window.For position and size, the constant CW_USEDEFAULT means to use default values.This set of flags is the most common style for a top-level application window. Together these flags give the window a title bar, a border, a system menu, and Minimize and Maximize buttons. ![]() The constant WS_OVERLAPPEDWINDOW is actually several flags combined with a bitwise OR. The window style is a set of flags that define some of the look and feel of a window.If the window has a title bar, the text is displayed in the title bar. The window text is used in different ways by different types of windows.This defines the type of window you are creating. CLASS_NAME is the name of the window class.Set this parameter to zero for the default behaviors. The first parameter lets you specify some optional behaviors for the window (for example, transparent windows).You can read detailed parameter descriptions in the documentation for the CreateWindowEx function, but here is a quick summary: L"Learn to Program Windows", // Window textĬW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, To create a new instance of a window, call the CreateWindowEx function: HWND hwnd = CreateWindowEx( This function registers the window class with the operating system. Next, pass the address of the WNDCLASS structure to the RegisterClass function. The WNDCLASS documentation describes the structure in detail. You can set them to zero, as shown in this example, or fill them in. The WNDCLASS structure has other members not shown here. For example, the window class for the button control is named "Button". If you use any of those controls, you must pick class names that do not conflict with the control class names. However, the standard Windows controls also have classes. lpszClassName is a string that identifies the window class.Ĭlass names are local to the current process, so the name only needs to be unique within the process.Get this value from the hInstance parameter of wWinMain. hInstance is the handle to the application instance.For now, just treat this as a forward reference. We'll examine the window procedure in detail later. lpfnWndProc is a pointer to an application-defined function called the window procedure or "window proc." The window procedure defines most of the behavior of the window.You must set the following structure members: To register a new window class, start by filling in a WNDCLASS structure: // Register the window class.Ĭonst wchar_t CLASS_NAME = L"Sample Window Class" Window classes are registered with the system at run time. Rather, it is a data structure used internally by the operating system. It is important to understand that a window class is not a "class" in the C++ sense. Data that is unique for each window is called instance data.Įvery window must be associated with a window class, even if your program only ever creates one instance of that class. Of course, buttons are not completely identical each button displays its own text string and has its own screen coordinates. For example, in a group of buttons, each button has a similar behavior when the user clicks the button. A window class defines a set of behaviors that several windows might have in common.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |