How To Create A Windows Window

Table of contents:

How To Create A Windows Window
How To Create A Windows Window

Video: How To Create A Windows Window

Video: How To Create A Windows Window
Video: How to create a Windows 10 Installation USB 2024, May
Anonim

The principles of functioning of the user interface of operating systems of the Windows family are based on the concept of a window. The desktop, taskbar, lists, dialogs, buttons, menus are all windows. Therefore, in fact, in order to display any interface element, you need to create a windows window.

How to create a Windows window
How to create a Windows window

Necessary

  • - compiler;
  • - Windows Platform SDK.

Instructions

Step 1

Register the class of the window to be created, if needed. Make a call to the API functions RegisterClass, RegisterClassEx or use the appropriate functionality of the framework used.

The RegisterClass and RegisterClassEx functions accept pointers to structures of type WNDCLASS and WNDCLASSEX, respectively, as their only parameter. The return value of type ATOM can be used in place of the class name when creating a window. If the function call fails, the return value is 0.

Instantiate a structure of type WNDCLASS or WNDCLASSEX. Fill all necessary fields. In particular, the correct values must be placed in:

- cbSize - structure size in bytes;

- style - a set of styles for the window class;

- lpfnWndProc - pointer to a window procedure;

- hInstance is the handle of the module in which the window class is registered;

- lpszClassName is the symbolic name of the class.

The rest of the fields can be written with NULL values. Make a function call to register the window class. Check the returned result.

Step 2

Select an existing window class if necessary. You must know the symbolic name of the class (the one that is passed through the lpszClassName pointer when registering it) or the corresponding value of the ATOM type. The class can be local at the application level, global at the application level (registered with the CS_GLOBALCLASS flag), or system-wide. The last type includes classes of windows with the names: Button, ComboBox, Edit, ListBox, MDIClient, ScrollBar, Static. Classes such as RichEdit20W or SysListView32 are registered when the corresponding libraries are loaded.

Step 3

Create a Windows window. Use the API functions CreateWindow, CreateWindowEx, or the appropriate wrapper methods for class objects of the framework or library you are using. The prototype for the CreateWindowEx function looks like this:

HWND CreateWindowEx (DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);

The CreateWindow function differs from CreateWindowEx only in the absence of the dwExStyle parameter.

Call CreateWindow or CreateWindowEx. Pass in the lpClassName parameter the name or ATOM of the window class you defined in the first or second step. The parameters x, y, nWidth, nHeight can be the coordinates and sizes of the window being created. The parent window handle (if any) is passed through hWndParent.

Save and parse the value returned by CreateWindow or CreateWindowEx. On success, they will return a handle to the new window; on failure, NULL.

Recommended: