VC常用小技巧(二) ---单选按钮控件(Radio Button)的使用

一、对单选按钮进行分组: 
每组的第一个单选按钮设置属性:Group,Tabstop,Auto;其余按钮设置属性Tabstop,Auto。
如:
Radio1、Radio2、Radio3为一组,Radio4、Radio5为一组
设定Radio1属性:Group,Tabstop,Auto
设定Radio2属性:Tabstop,Auto
设定Radio3属性:Tabstop,Auto
设定Radio4属性:Group,Tabstop,Auto
设定Radio5属性:Tabstop,Auto
二、用ClassWizard为单选控件定义变量,每组只能定义一个。如:m_Radio1、m_Radio4。
三、用ClassWizard生成各单选按钮的单击消息函数,并加入内容:
void CWEditView::OnRadio1() 
{
m_Radio1 = 0; //第一个单选按钮被选中
}
void CWEditView::OnRadio2() 
{
m_Radio1 = 1; //第二个单选按钮被选中
}
void CWEditView::OnRadio3() 
{
m_Radio1 = 2; //第三个单选按钮被选中
}
void CWEditView::OnRadio4() 
{
m_Radio4 = 0; //第四个单选按钮被选中
}
void CWEditView::OnRadio5() 
{
m_Radio4 = 1; //第五个单选按钮被选中
}
当控件变量值为0时,它对应组的第一个单选按钮处于选中状态。
BOOL CDzyApp::InitInstance() 
...{ 
AfxEnableControlContainer(); 
…… 

// The one and only window has been initialized, so show and update it. 
m_pMainWnd->SetWindowPos(NULL,0,0,750,555,SWP_NOMOVE);//设置窗口的初始大小为750*555 
m_pMainWnd->ShowWindow(SW_SHOW); 
m_pMainWnd->UpdateWindow(); 

return TRUE; 
}

m_pMainWnd->CenterWindow( GetDesktopWindow() );
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { 
if (CFrameWnd::OnCreate(lpCreateStruct) == -1) 
return -1; 
…… 

// TODO: Delete these three lines if you don't want the toolbar to 
// be dockable 
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); 
EnableDocking(CBRS_ALIGN_ANY); 
DockControlBar(&m_wndToolBar); 

CenterWindow( GetDesktopWindow() ); //使窗口打开时处于屏幕正中

return 0; 
}

BOOL CTextEditorDoc::OnNewDocument() { 
if (!CDocument::OnNewDocument()) 
return FALSE; 
// TODO: add reinitialization code here 
// (SDI documents will reuse this document) 
SetTitle("未命名.txt"); //设置文档标题 
return TRUE; 
}
posted @ 2009-05-14 10:30  Jeno  阅读(1556)  评论(0编辑  收藏  举报