Subject strip with SDK

zhaozj2021-02-16  49

VC learning: Subject with SDK [2004-6-12] Subject in Windows is a widely used control, and most of the Explorer model uses this control. However, there are very few relevant information to introduce it's full implementation, so I realize one, I hope to help SDK's enthusiasts.

In fact, the separator is also a very ordinary window, which also has its own window class, its own window process - just like all predefined controls. That is, to create a partition, you also need to perform the creation of the registration and window of the window class. The following sample code demonstrates how to register a window class:

WNDCLASS wc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH) COLOR_BTNSHADOW; // 1 wc.hCursor = LoadCursor (NULL, IDC_SIZEWE); // 2 wc.hIcon = NULL; wc.hInstance = Hinstance; wc.lpfnwndproc = (wndproc) procsplitter; // 3 wc.lpszclassName = "mysplitter"; // 4 wc.lpszMenuname = null; wc.style = 0; RegisterClass (& WC);

This code believes that everyone is already familiar, so I only briefly explain four points: 1, the background color of the separator, here I take the default dialog box background color; 2, the separator mouse pointer, here I take the level Adjust the size pointer;

After successfully registering the window class, you can create a separator. The following is my example interface, which consists of a tree view, a partition, a list view, and a status bar, all code below is based on this interface.

Before writing the window procedure of the separator, I will first process the WM_SIZE message of the dialog as a warm-up process. The code is as follows (you will find that I don't have any declarations for htree, hstatus, hsplitter, and hlist in the entire code. It is because of this simple example, I declare all these things for global variables):

case WM_SIZE: {HDWP hdwp; RECT rect, rectStatus, rectTree; hdwp = BeginDeferWindowPos (4); GetClientRect (hDlg, & rect); GetClientRect (hStatus, & rectStatus); GetWindowRect (hTree, & rectTree); DeferWindowPos (hdwp, hStatus, NULL, 0, rect.bottom - rectStatus.bottom, rect.right, rectStatus.bottom, SWP_NOZORDER); DeferWindowPos (hdwp, hTree, NULL, 0, 0, rectTree.right - rectTree.left, rect.bottom - rectStatus.bottom, SWP_NOMOVE | SWP_NOZORDER); DeferWindowPos (hdwp, hSplitter, NULL, rectTree.right - rectTree.left, 0, 2, rect.bottom - rectStatus.bottom, SWP_NOZORDER); DeferWindowPos (hdwp, hList, NULL, rectTree.right - rectTree.left 2, 0, Rect.right - RectTree.right RectTree.Left - 2, Rect.Bottom - RectStatus.bottom, SWP_NOZORDER; EnddeferWindowPos (HDWP);} Break; You have noticed that most of this code The space is all played with a rectangle. This is indeed because the process of adjusting the window size is a process of changing the location and size of each sub-window. This process is described by: 1. First, place the status bar at the bottom of the dialog; 2. Step 2, does not change the position and width of the tree view, reset it; 3, do not change the separator The position and width, reset it; 4, make the list view account for the remaining customer area.

If you understand the code above, then the separator window has no difficulty:

LRESULT CALLBACK Procsplitter (HWND HWND, UINT MSG, WPARAM WPARAM, LPARAM LPARAM) {Switch (MSG) {Case WM_LButtondown: setCapture (hwnd);

break; case WM_LBUTTONUP: ReleaseCapture (); break; case WM_MOUSEMOVE: {if ((wParam & MK_LBUTTON) == MK_LBUTTON && GetCapture () == hwnd) {HDWP hdwp; RECT rect, rectStatus, rectTree; hdwp = BeginDeferWindowPos (3) ; GetClientRect (GetParent (hwnd), & rect); GetClientRect (hStatus, & rectStatus); GetWindowRect (hTree, & rectTree); DeferWindowPos (hdwp, hTree, NULL, 0, 0, rectTree.right - rectTree.left (short) LOWORD ( lParam), rect.bottom - rectStatus.bottom, SWP_NOMOVE | SWP_NOZORDER); DeferWindowPos (hdwp, hSplitter, NULL, rectTree.right - rectTree.left (short) LOWORD (lParam), 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER) DeferWindowPOS (HDWP, HLIST, NULL, RectTree.right - RectTree.Light (Short) Loword (LPARAM) 2, 0, Rect.right - RectTree.right RectTree.Left - (Short) Loword (LPARAM) - 2 , rect.bottom - rectStatus.bottom, SWP_NOZORDER); EndDeferWindowPos (hdwp);}} break; default: return DefWindowProc (hwnd, Msg, wParam, lParam);} return 0;} SetCapture and the left mouse button, respectively ReleaseCapture Pressing and releases the mouse when it is released, this is the general requirement of the separator. The core part of this code is the event that the mouse movement is handled, that is, when the left mouse button is pressed and the separator captures the position and width of the three related windows. The specific rectangular operation is similar to the principle of code of the main window WM_SIZE, I will not say much.

The reason why I don't use MoveWindow's function is changed, that is, because these functions make the form's multiple redrawing, causing the entire form of flashing - and in fact I don't want the status bar to flash.

转载请注明原文地址:https://www.9cbs.com/read-20965.html

New Post(0)