码迷,mamicode.com
首页 > 编程语言 > 详细

MFC修改控件颜色

时间:2015-03-18 14:08:46      阅读:373      评论:0      收藏:0      [点我收藏+]

标签:

1.
CClientDC dc(this);
RECT m_pRect;
GetDlgItem(IDC_SAMPLE)->GetWindowRect(&m_pRect);
ScreenToClient(&m_pRect);
CBrush NewBrush(RGB(0, 0, 255));
dc.FillRect(&m_pRect, &NewBrush); 


2. 改变CStatic字体
CClientDC hdc(this); 
CFont font; 
font.CreatePointFont(500, "楷体_GB2312",NULL); 
CStatic *m_pbtWnd = &m_button;
m_pbtWnd->SetFont(&font); 


3. 改变CButton字体
CFont *font;   
font = new CFont;   
f->CreateFont(30,0,0,0,
        FW_BOLD,
                  TRUE,
                  TRUE,
                     0,
          ANSI_CHARSET,
    OUT_DEFAULT_PRECIS,                                   
   CLIP_DEFAULT_PRECIS,
       DEFAULT_QUALITY,                                  
DEFAULT_PITCH|FF_SWISS,        
          _T("Arial"));                                   
GetDlgItem(IDC_BUTTON1)->SetFont(f); 


4. 窗口始终在最前面:
方法一:在对话框的属性中,在more   style中有一项是System   model,选上它,即可!
方法二:OnInitDialog里加入SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);


5. 限制CEdit只能输入小写字母
方法一:属性里设置下,LowerCase(输入大写后自动变小写)
方法二:新建个继承自CEdit的类。。然后重载OnChar函数.... (只能输入小写,输入其他不反应)
void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 

// TODO: Add your message handler code here and/or call default 
if (nChar < ‘a‘ || nChar > ‘z‘) 
return; 
CEdit::OnChar(nChar, nRepCnt, nFlags); 
}

6.MFC弹出非模态对话框
CTestDialog *pTestDlg = new CTestDialog(); 
pTestDlg->Create(IDD_DIALOG_TEST, this); 
pTestDlg->ShowWindow(SW_SHOW); 
///下面三行错误 
//CTestDialog dlg1; 
//dlg1.Create(IDD_DIALOG_TEST, NULL); 
//dlg1.ShowWindow(SW_SHOW); 
为什么前三行不能用后三行代替? 
用后三行,弹出的对话框闪了一下就消失了 
注意一下他们的生命周期


7.如何去掉框架的关闭按钮?
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
   return FALSE;
cs.style &= ~WS_SYSMENU;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return TRUE;
}


8.CStatic 显示图片:
   CPaintDC dc(this); 
   HBITMAP bmp; 
   bmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),"E://a.bmp", 
    IMAGE_BITMAP,0,0,    
    LR_CREATEDIBSECTION 
    | LR_DEFAULTSIZE 
    | LR_LOADFROMFILE 
    | LR_DEFAULTCOLOR); 
   ((CStatic *)GetDlgItem(IDC_STATIC1))->ModifyStyle(NULL,SS_BITMAP|SS_CENTERIMAGE,0); 
   ((CStatic *)GetDlgItem(IDC_STATIC1))->SetBitmap(bmp) ;


MFC修改控件颜色

标签:

原文地址:http://blog.csdn.net/jiangqin115/article/details/44408615

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!