Use cDialogbar to achieve floating strips of similar toolbars

xiaoxiao2021-03-06  91

If you want to achieve the floating and positioning of the toolbar, you can easily place any controls, please continue to watch this article!

Then use cdialogbar to have the same convenient and fast as CDIALOG.

Step 1: Add a cdialogbar derived class

Add a dialog box in the resource, then use the class wizard to add classes, can't find CDIALOGBAR as base class, you can use CDIALOG as the base class, and then replace the "cdialog" to "cdialogbar", replace completion . Compile, ^ _ ^ There is a mistake! ! Please see step 2.

Step 2: Solve compilation errors and improve this class

In fact, the error is that there is a problem when the function calls the base class,: cdialogbar (/ * cdlgbar :: IDD, pparent * /) is like this comment, add a function like OnInitDialog, there is no OnInitDialog in CDialogbar Message, at least I don't know, because initialization is called after creating, so we rewrite Virtual Bool Create (CWND * PParentWnd, Uint NidTemplate, Uint NStyle, Uint Nid); this function. Note that the parameters of the Create function added to the wizard are not right, see it. Here is the implementation of code (very simple)

Bool CDLGXXX :: Create (cwnd * pparentwnd, uint nidTemplate, uint nstyle, uint NID)

{

// Todo: Add Your Specialized Code Here and / or Call The Base Class

Bool Bres = CDialogbar :: Create (PparentWnd, NidTemplate, NStyle, NID);

INITDIALOGBAR (); // You can add a member function in the class.

Return Bres;

}

Bool cdlgxxx :: initdialogbar ()

{

Updatedata (false); // This must be, this will have the same data exchange with CDIALOG.

Return True;

}

Step 3: Create and use

IF (! m_barattribrib.create (this, IDD_DLG_COM_ATTRIB, CBRS_RIGHT | CBRS_GRIPPER, XXX))

{

Trace0 ("Failed to Create Dialogbar / N");

Return -1;

}

m_barattrib.SetWindowText (Part Properties);

XXX is a resource ID handmade directly in the resource .H file, it will not, it will not be taught here.

.

The display and hidden code of the toolbar is as follows, you will slowly understand it:

ShowControlbar (& M_BARATTRIB, (M_barattrib.getStyle () & WS_Visible) == 0, FALSE);

After the above code is implemented, DODATAEXCHANGE can also be used, and add controls to the control, which is the same as CDIALOG.

But there is another thing to pay attention to the addition of the control class object, I tried it seems that you can't, the window handle seems

Always 0, cannot be used. Or use getDLGITEM (IDC_Driver_list) to get the control pointer.

Other experience

Use DODATAEXChange to control the customized input format to control the example of a text box here.

After adding variables to text controls, you will appear below DODATAEXCHANGE.

DDX_TEXT (PDX, IDC_COM_VAR, M_STRVAR); // System generated

DDV_MAXCHARS (PDX, M_STRVAR, VAR_MAX_LEN); / / DDV_FileNameString (PDX, M_Strvar) generated after the length control; // See the implementation of custom manual addition

Void CXXX :: DDV_FileNameString (CDataExchange * PDX, CString M_StrFileName)

{

CString strerror = _t ("

/ //: *? / "<> |");

IF (m_strfilename.spanexcluding (strerror)! = m_strfilename)

{

:: AfxMessageBox (_t ("The file name cannot contain" STRERROR "character");

PDX-> Fail (); // The key is that this sentence will throw the following statement below after this sentence will not be executed.

}

}

There are still a few points of attention.

1. Only the updataData () will only be called if pdx-> fail () is executed in the middle of the way, returning false.

2. DDX_TEXT (PDX, IDC_COM_VAR, M_STVAR); // System generated

DDV_MAXCHARS (PDX, M_STRVAR, VAR_MAX_LEN); // Generate after the length control

DDV_FileNameString (PDX, M_Strvar); // Custom Manual Addition Implementation See

As mentioned above is the control of the content of a control, they must be placed on one, and DDX_text is in the first sentence, so that the contents of the control can be placed correctly, the control will be set to focus. And select all the contents.

Ok, write so much first.

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

New Post(0)