How to create controls that have a 3D border at run time by using MFC in Visual C++

Article translations Article translations
Article ID: 132243 - View products that this article applies to.
This article was previously published under Q132243
This article has been archived. It is offered "as is" and will no longer be updated.
Note Microsoft Visual C++ .NET (2002) supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code.

Note Microsoft Visual C++ 2005 supports both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model.
Expand all | Collapse all

SUMMARY

Controls placed in a dialog box under Windows 95 have a 3D border. If you want to create a control at run time that has a 3D border, specify the WS_EX_CLIENTEDGE extended style.

MORE INFORMATION

The new extended-window style WS_EX_CLIENTEDGE specifies that a window is to have a 3D border. All controls created by the dialog manager are created with that style automatically added. To create a control at run time that has a 3D border, you have to add that style yourself.

Because WS_EX_CLIENTEDGE is an extended style, you cannot use the Create() member function to create a control. You must call CreateEx(), and pass the appropriate Windows class name as well. For example, to create an edit control at run time, you could use this code:
   m_Edit.Create(WS_CHILD | WS_BORDER | WS_VISIBLE,
                 CRect(10,10,100,100),pParent,nID);
				
Here m_Edit is a CEdit object, pParent is a pointer to a parent window, and nID is an ID of an edit control. To add a 3D border, create control by using this code:
   m_Edit.CreateEx(WS_EX_CLIENTEDGE,"EDIT","",
                   WS_CHILD | WS_BORDER | WS_VISIBLE,
                   10,10,100,100,pParent->GetSafeHwnd(),(HMENU)nID);
				
Note While Visual C++ versions 2.2 and above define WS_EX_CLIENTEDGE in WINUSER.H, Visual C++ version 2.1 does not. Therefore, if you're using version 2.1, you must include the following definition in your code:
   #define WS_EX_CLIENTEDGE        0x00000200L
				
If you're using Visual C++ versions 2.2 and above, the WS_EX_CLIENTEDGE constant is automatically defined when you include AFXWIN.. Therefore, no additional work is necessary.

Keep in mind that the WS_EX_CLIENTEDGE style applies to any window, not just controls. In Visual C++ versions 2.2 and above, MFC automatically adds WS_EX_CLIENTEDGE for frames and views but not for CWnd-based windows or controls.

To create other standard controls, you have to specify their pre-defined Windows class name: BUTTON, COMBOBOX, LISTBOX, SCROLLBAR, or STATIC.

REFERENCES

For more information about Create and CreateEx, please see the Class Library Reference in Books Online.

For more information about the new Windows styles, see the Win32 Software Development Kit (SDK) documentation.

Properties

Article ID: 132243 - Last Review: February 28, 2014 - Revision: 5.1
APPLIES TO
  • Microsoft Foundation Class Library 4.2, when used with:
    • Microsoft Visual C++ 2.1
    • Microsoft Visual C++ 2.2
    • Microsoft Visual C++ 4.0 Standard Edition
    • Microsoft Visual C++ 5.0 Enterprise Edition
    • Microsoft Visual C++ 6.0 Enterprise Edition
    • Microsoft Visual C++ 5.0 Professional Edition
    • Microsoft Visual C++ 6.0 Professional Edition
    • Microsoft Visual C++, 32-bit Learning Edition 6.0
    • Microsoft Visual C++ .NET 2002 Standard Edition
    • Microsoft Visual C++ .NET 2003 Standard Edition
    • Microsoft Visual C++ 2005 Express Edition
Keywords: 
kbnosurvey kbarchive kbhowto kbuidesign kbctrl KB132243

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com