MFC常用函數(shù)與指令
這是之前的視頻——快速掌握MFC編程要領(lǐng)(https://www.bilibili.com/video/BV1BC4y1H7Ru)里的TXT文件,很多朋友來找,這里統(tǒng)一發(fā)一下。
VC+編寫可視化程序的方法:API、MFC
API工程的建立
MFC工程的建立
鼠標(biāo)事件 主要介紹LButtonDown
鍵盤事件 主要介紹KeyDown
提示框 AfxMessageBox MessageBox
常用控件
按鈕
CButton
SetWindowText("XXX")
CFont m_editFont; //用來修改字體的變量
m_editFont.CreatePointFont(180, _T("華文行楷"));
m_anniu.SetFont(&m_editFont); //修改按鈕字體大小
EnableWindow(0)
編輯框
CString方法
UpdateData(0);
CEdit方法
float/int方法
TCHAR ch[10];
GetDlgItem(IDC_yiyuan_a)->GetWindowText(ch,10);
m_yiyuan_a=atof(ch);
靜態(tài)文本(標(biāo)簽)
OnCtlColor
if(pWnd->GetDlgCtrlID()==IDC_XXX)
{
pDC->SetTextColor(RGB(0,0,255));//設(shè)置文本顏色
pDC->SetBkColor(RGB(255,0,0));//設(shè)置文本背景色
pDC->SetBkMode(TRANSPARENT);//設(shè)置背景透明
pDC->SelectObject(&m_editFont);
hbr = ::CreateSolidBrush(RGB(255,0,0));//設(shè)置背景畫刷
}
組框
單選框
自動(dòng)與否
SetCheck(1)
int類型的用法
GetCheckedRadioButton(IDC_XXX,IDC_YYY);
if(get==IDC_XXX)
復(fù)選框
bool型的用法
if(m_chk1.GetCheck())
SetCheck(0)
列表框
AddString
組合框
SetCurSel(0)
定時(shí)器
SetTimer(0,1000,NULL);
OnTimer
if(nIDEvent==XXX)
Invalidate(0);
UpdateWindow();
(*this).KillTimer(0);
圖像(圖片框)
位圖
Cstatic
CBitmap bitmap;
bitmap.LoadBitmap(IDB_XXX);
m_XXX.SetBitmap(bitmap);
bitmap.Detach();
類的使用
多窗口
模態(tài)窗口
pd.DoModal();
ModifyStyleEx(0,WS_EX_APPWINDOW);
圖標(biāo)問題
非模態(tài)窗口
chuangkou *pd=new chuangkou();??
(*pd).Create(IDD_DIALOG);
(*pd).ShowWindow(SW_SHOWNORMAL);
//(*pd).DestroyWindow();//子窗口會銷毀
菜單問題
CMenu iM;
iM.LoadMenu(IDR_MENU1);
SetMenu(&iM);