The previous two Demo pictures help you choose whether to continue reading the article.
If you choose to continue reading, don't worry. The next step is the text.
PART 1: Demo Function
Heheh, that is, creating windows and associated subwindows in the pure win32 API mode, prepare for the gadgets in the plan, and there must be a slightly complicated configuration interface in the plan, the Configuration window is displayed and hidden in subwindows.
PART 2: technical difficulties
This part does not exist. It is the basic knowledge of win32. The creation of the main window is basically the same as that of the subwindow. It defines the properties and association methods of the window object, that is, the properties are WNDCLASS, the association method is the callback function of message processing. The key to moving the subwindow following the left mouse button is to understand the message mechanism of win32 and quickly search for MSDN.
PART 3: Knowledge Accumulation
Using win32 APIs instead of MFC, you can better understand the underlying mechanism of windows. Multiple windows are still processed by a single thread, after the window is created, the system cyclically obtains the message from the message queue and sends the message to the corresponding window for processing after parsing. This is actually the callback function corresponding to the window for processing after parsing the message owner window, blocking anywhere in the process will cause the window to fail to respond.
It is easier to check whether the mouse is pressed when you move the mouse. In MSDN, check WM_MOUSEMOVE. the left mouse button is passed in the window. it was originally intended to use GetKeyStat to obtain the virtual key status of the keyboard and mouse.
PART 4: Finding bugs
Please be careful. If you do not understand the error details during win32 programming, call GetLastError to obtain the error message, error code + error reporting function to ask du Niang. Du Niang will be enthusiastic about help.
In this case, NULL is returned when CreateWindow is called to create a subwindow. GetLastError Returns Error Code 1047. no hInstance Member of the initial WNDCLASS object; 2. the registered class name is garbled. follow the CreateWindow class name parameter to solve the bug.
PART 5: Main Ideas
1. Generate the main window, which is basically the standard windows creation window.
2. Create a subwindow. There is no obvious difference between creating a subwindow and the main window. register the WNDCLASS class and CreateWindow are associated with the newly registered class and parent window handle.
3. the subwindow message processing method processes the offset of the subwindow relative to the main window in the subwindow association method. GetWindowRect is used to obtain the offset of the parent window and the subwindow relative to the upper left corner of the screen respectively, then the offset of the Child Window relative to the upper left corner of the parent window is calculated. In the WM_MOUSEMOVE message, determine whether the left mouse button is pressed. If the mouse is located on the Child Window and the left mouse button is pressed to move the mouse, the system obtains the mouse offset and calls MoveWindow to move the Child Window to create a child window following the mouse.
Point free download link: http://download.csdn.net/detail/hd770c/6830919