Create a control container

xiaoxiao2021-03-06  14

Sometimes we need to have a container, put some controls such as button editing box, etc., you only have to move this container, follow the controls in the container, followed by the container, the control inside the container is also followed. Hide. The implementation method is to give a container class by the CDialog class, put the control into the window. The specific implementation method is as follows: First create a new Workspace, then create a dialog, IDD_DIALOG_PANEL To delete it OK and the Cancel button, get a blank dialog, which is the container to be used for a while, you can join various containers as needed, remember to set the Style tag to Child, Border settings To none. Then run the ClassWizard, you will automatically prompt you to create a category corresponding to the dialog resource. Should be named Panel to inherit from CDIALOG. Add: cdialog * m_ppanel; CRECT M_RECTPANEL; M_RECTPANEL is mainly used to determine the location of m_panel. Add: #include "panel.h" in TestPanle.cpp Add: CRECT RECTMAINTOLEFTTOP; // Main window relative to the location of the upper left corner of the screen GetWindowRect (& RectMAINTOLEFTTOP);

int nCaption = :: GetSystemMetrics (SM_CYCAPTION); int nXEdge // height of the title bar = :: GetSystemMetrics (SM_CXEDGE); // lateral margins int nYEdge = :: GetSystemMetrics (SM_CYEDGE); // longitudinal margins CRect rectPanelToLefttop; / / Container relative to location getDLGITEM (IDC_STATIC_POSITION) -> getWindowRect (& RectPanelTolefttop) relative to the position of the upper left corner of the screen;

/ / Calculate the main window Effective area (your blue dashed box you can see from the resource editor) relative to the position of the upper left corner of the screen RectMAINTOLEFTTOP NCAPTION NYEDGEFTTOP.TOP NCAPTION NYEDGE; RectMAINTOLEFTTOP.LEFT = RectMAINTOLEFTTOP.LEFT 2 * nXEdge; // calculate container relative to the top left corner of the effective area of ​​the main window position m_rectPanel.top = rectPanelToLefttop.top-rectMainToLefttop.top; m_rectPanel.left = rectPanelToLefttop.left-rectMainToLefttop.left; m_rectPanel.bottom = rectPanelToLefttop.bottom-rectMainToLefttop .top; m_rectpanel.right = RectPanelTolefttop.right-RectMAINTOLEFTTOP.LEFT;

// Dynamically create containers and their content, and display it in the specified location m_ppanel = new panel; m_ppanel-> create (IDd_dialog_panel, this); m_ppanel-> showwindow (sw_show); m_ppanel-> movewindow (m_rectpanel);

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

New Post(0)