在Developer Studio中选取File菜单中的New命令,在出现的New对话框中选择 创建MFC AppWizard(exe)框架应用程序,并输入项目名为EllipseWnd。设定应 用程序类型为基于对话框(Dialog based),其它选项按缺省值创建项目源文件。2. 使用资源编辑器从主对话框(ID为IDD_ELLIPSEWND_DIALOG)删除其中的所有控 制,并从其属性对话框(Dialog Properties)中设定其风格为Popup、无标题条和 边框。3. 在EllipseWndDlg.h源文件中给主对话框类CEllipseWndDlg增加一个CRgn类保护 型数据成员m_rgnWnd,它将定义窗口的区域。4. 在EllipseWndDlg.cpp源文件中修改主对话框类CEllipseWndDlg的OnInitDialog() 函数,增加m_rgnWnd的创建,并将其定义为窗口区域。粗体语句为新增部分。BOOL CEllipseWndDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // 设置窗口标题为“椭圆窗口”,虽然对话框没有标题条, // 但在任务条的按钮中仍需要标题 SetWindowText(_T("椭圆窗口")); // 取得屏幕宽、高 int cxScreen = ::GetSystemMetrics(SM_CXSCREEN); int cyScreen = ::GetSystemMetrics(SM_CYSCREEN); // 设置椭圆X、Y方向的半径 int nEllipseWidth = cxScreen/8; int nEllipseHeight = cyScreen/8; // 将窗口大小设为宽nEllipseWidth,高nEllipseHeight // 并移至左上角 MoveWindow(0, 0, nEllipseWidth, nEllipseHeight); // 创建椭圆区域m_rgnWnd m_rgnWnd.CreateEllipticRgn(0, 0, nEllipseWidth, nEllipseHeight); // 将m_rgnWnd设置为窗口区域 SetWindowRgn((HRGN)m_rgnWnd, TRUE); return TRUE; // return TRUE unless you set the focus to a control }
类似http://blog.csdn.net/vcleaner/gallery/image/33025.aspx
创建MFC AppWizard(exe)框架应用程序,并输入项目名为EllipseWnd。设定应
用程序类型为基于对话框(Dialog based),其它选项按缺省值创建项目源文件。2. 使用资源编辑器从主对话框(ID为IDD_ELLIPSEWND_DIALOG)删除其中的所有控
制,并从其属性对话框(Dialog Properties)中设定其风格为Popup、无标题条和
边框。3. 在EllipseWndDlg.h源文件中给主对话框类CEllipseWndDlg增加一个CRgn类保护
型数据成员m_rgnWnd,它将定义窗口的区域。4. 在EllipseWndDlg.cpp源文件中修改主对话框类CEllipseWndDlg的OnInitDialog()
函数,增加m_rgnWnd的创建,并将其定义为窗口区域。粗体语句为新增部分。BOOL CEllipseWndDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX,
strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// 设置窗口标题为“椭圆窗口”,虽然对话框没有标题条,
// 但在任务条的按钮中仍需要标题
SetWindowText(_T("椭圆窗口"));
// 取得屏幕宽、高
int cxScreen = ::GetSystemMetrics(SM_CXSCREEN);
int cyScreen = ::GetSystemMetrics(SM_CYSCREEN);
// 设置椭圆X、Y方向的半径
int nEllipseWidth = cxScreen/8;
int nEllipseHeight = cyScreen/8;
// 将窗口大小设为宽nEllipseWidth,高nEllipseHeight
// 并移至左上角
MoveWindow(0, 0, nEllipseWidth, nEllipseHeight);
// 创建椭圆区域m_rgnWnd
m_rgnWnd.CreateEllipticRgn(0, 0, nEllipseWidth, nEllipseHeight);
// 将m_rgnWnd设置为窗口区域
SetWindowRgn((HRGN)m_rgnWnd, TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void SDISetRgn(CFrameWnd* pMainWnd)
{
if(!pMainWnd)
return; CView* pView = pMainWnd->GetActiveView();
if(!pView)
return; CRect rc, rcClient, rcWindow;
pView->GetClientRect(&rc);
pView->ClientToScreen(&rc);
pMainWnd->ScreenToClient(&rc); pMainWnd->GetClientRect(&rcClient);
pMainWnd->ClientToScreen(&rcClient);
pMainWnd->GetWindowRect(&rcWindow); CPoint pt;
pt.x = rcClient.left - rcWindow.left;
pt.y = rcClient.top - rcWindow.top; rc.OffsetRect(pt); CRgn rgnWnd;
rgnWnd.CreateEllipticRgnIndirect(&rc);
pMainWnd->SetWindowRgn(rgnWnd, TRUE);
rgnWnd.Detach();
}在 InitInstance() 中,在 m_pMainWnd->ShowWindow(SW_SHOW); 之前调用它: SDISetRgn((CFrameWnd*)m_pMainWnd);即可。
你会看到一次闪烁,但解决 SDI 程序的闪烁是另外一个问题。
我找到一点点有用的东东,共享!