SDK implements partitionables

zhaozj2021-02-16  53

The separator in Windows is a widely used control, and most of the Explorer models use 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 = loadingcursor (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 very familiar, so I only briefly explain four points: 1, the background color of the partition, here I take the default dialog box background color; 2, partition strip Mouse pointer, here I take the level of adjustment size pointer; 3, this is the window process of the separator, all the secrets are in this callback function; 4, the partition of the window class name, you can just take a one you like name. 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, because I declare all these things in order 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.Left - 2, Rect.Bottom - RectStatus.Bottom, SWP_NOZORDER; EnddeferWindowPos (HDWP);} Break; You have already noticed that most of this code is It is playing games with rectangles. 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.

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

New Post(0)