简体   繁体   中英

How to Add a editbox and a button in mfc sdi main window?

I am making a Messanger application in MFC . So , I am using a MFC SDI .

As my requirement, I have to add two editbox and one button for signIn in the main window of application. I can do this by dialog box easily but I have to add these in view of main window. I read about doc/view architecture , but still facing the same problem.

I am new to UI and MFC both. Please help me out in adding these elements in the view of main window.

Derive your view from CFormView . This hosts controls defined in a dialog resource, so you can just draw the dialog in the normal dialog editor, then tell your CFormView-derived view to use that, and it'll handle all the usual dialog-like things for you.

Oh, and just like when those controls are a normal dialog, you can also associate the controls with variables if you want.

If you really want to, you can write code to directly create and position your controls in a class derived directly from CView instead. As a general rule, I'd prefer to use a CFormView though--it's intended for this specific purpose, so unless you have a reason to do otherwise, it's probably better to use what it provides than duplicate roughly the same functionality yourself.

Assuming you use the AppWizard for your initial application creation, you can select the base class in the last frame:

在此处输入图片说明

Once you've selected that and create the application, if you look in the resource view, you'll find two dialog templates: one is for the About box, the other for your View.

Have a look at the CFormView class. It's a view class that uses a dialog resource. So, you can use the resource editor to drop controls like buttons and edit boxes on top of a view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM