这是我写的一个椭圆形按钮,资源是有一个按钮的普通对话框。 希望对你有帮助。class CRoundDlg : public CDialog { // Construction public: CRoundDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data //{{AFX_DATA(CRoundDlg) enum { IDD = IDD_ROUND_DIALOG }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CRoundDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL// Implementation protected: HICON m_hIcon; // Generated message map functions //{{AFX_MSG(CRoundDlg) virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CRoundDlg::CRoundDlg(CWnd* pParent /*=NULL*/) : CDialog(CRoundDlg::IDD, pParent) { //{{AFX_DATA_INIT(CRoundDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }void CRoundDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CRoundDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP }BEGIN_MESSAGE_MAP(CRoundDlg, CDialog) //{{AFX_MSG_MAP(CRoundDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP END_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////// // CRoundDlg message handlersBOOL CRoundDlg::OnInitDialog() { CDialog::OnInitDialog(); CRect rcDialog; GetClientRect(&rcDialog); CRgn rgn; rgn.CreateEllipticRgn(0,0,rcDialog.Width(),rcDialog.Height()); SetWindowRgn((HRGN)rgn,TRUE);
return TRUE; // return TRUE unless you set the focus to a control }void CRoundDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } }// If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework.void CRoundDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } }// The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CRoundDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; }
这是一个不规则窗体的实例,希望能对你有所帮助
http://www.vckbase.com/document/viewdoc.asp?id=541
希望对你有帮助。class CRoundDlg : public CDialog
{
// Construction
public:
CRoundDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
//{{AFX_DATA(CRoundDlg)
enum { IDD = IDD_ROUND_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CRoundDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected:
HICON m_hIcon; // Generated message map functions
//{{AFX_MSG(CRoundDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CRoundDlg::CRoundDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRoundDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRoundDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}void CRoundDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRoundDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CRoundDlg, CDialog)
//{{AFX_MSG_MAP(CRoundDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CRoundDlg message handlersBOOL CRoundDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CRect rcDialog;
GetClientRect(&rcDialog);
CRgn rgn;
rgn.CreateEllipticRgn(0,0,rcDialog.Width(),rcDialog.Height());
SetWindowRgn((HRGN)rgn,TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}void CRoundDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.void CRoundDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CRoundDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
然后TextOut()你要的字
GetPath取得相关点路径,
然后根据取得的点路径CreatePolygonRgn创建区域
最后SetWindowRgn设置窗体的样子,就是只是字的笔画了.
记得EndPath
http://expert.csdn.net/Expert/topic/2673/2673176.xml?temp=.8355982