MFC常用操作

1,获取STATIC控件的值

CString str;

m_STATIC2.GetWindowText(str);//获取STATIC控件的值

MessageBox(str);

2.设置EDIT控件的值

m_EDIT2.SetWindowText(str);//设置EDIT控件的值

GetDlgItem(IDC_EDIT1)->SetWindowText("Leave");//设置EDIT控件的值

3.移动控件

m_EDIT2.SetWindowPos(&CWnd::wndTop, rect.left, rect.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);//移动控件

4.禁用控件

m_STATIC2.EnableWindow(FALSE);//禁用控件

5.获取控件句柄

CWnd* pWnd = GetDlgItem(IDC_STATIC2); // 获取控件句柄

6.获取控件的位置

CRect rect;

pWnd->GetWindowRect(&rect); // 获取控件的位置

ScreenToClient(&rect); // 将控件位置转换为相对于父窗口的坐标

6.INT转CString

CString strValue;

strValue.Format(_T("%d"), x);//INT转CString,%d转整数,%.3f转小数,.3控制精度

int number = atoi(str); // 将CString转换为int

7.写入记事本//#include <IO.h>

CStdioFile file;

if (file.Open(_T("D:\\CAMTOOL\\TMZS_ZB.txt"), CFile::modeWrite | CFile::modeCreate))//写入记事本

{

file.WriteString(_T(strValue));

file.Close();

}

8.读取记事本//#include <IO.h>

CStdioFile file;

if (file.Open(_T("D:\\CAMTOOL\\example.txt"), CFile::modeRead))

{

CString str;

while (file.ReadString(str))

{

// 处理读取到的字符串

//TRACE(_T("%s\n"), str);

int number = atoi(str); // 将CString转换为int

aaa = tag_t(number);

}

file.Close();

}

9.判断文件是否存在

if ((PathFileExists("D:\\CAMTOOL\\example.txt")))//判断文件是否存在,#include <IO.h>

{

//uc1601("存在", 1);

}

10.删除文件

CFile::Remove(_T("D:\\CAMTOOL\\example.txt"));//删除文件,#include "afxdialogex.h"

11.显示隐藏控件

m_myControl.ShowWindow(SW_HIDE); // 使用ShowWindow隐藏控件

m_myControl.ShowWindow(SW_SHOW); // 使用ShowWindow显示控件

相关推荐
dengzhenyue5 天前
MFC 学习笔记
笔记·学习·mfc
兵哥工控9 天前
mfc 线程启动、挂起、恢复、停止实例
c++·mfc·线程
爱看书的小沐9 天前
【小沐学CAD】基于OCCT读取和显示STEP模型文件(QT、MFC、glfw)
qt·mfc·opengl·stp·step·opencascade·occt
CAACoder14 天前
CATIA/3DE CAA二次开发-ListCtrl-2
mfc·catia·caa·clistctrl
CAACoder14 天前
CATIA/3DE CAA二次开发-播放gif的控件
mfc·catia·caa·gif播放控件
此刻觐神16 天前
Windows学习笔记-18(MFC项目-制作快捷方式管理工具)
windows·笔记·学习·mfc
xEurCjvwu16 天前
CNN-LSTM多变量回归预测(Matlab) 基于卷积-长短期记忆网络(CNN-LSTM)的...
mfc
此刻觐神19 天前
Windows学习笔记-13(MFC状态栏Status Bar)
笔记·学习·mfc
MSTcheng.23 天前
CANN ops-math算子的跨平台适配与硬件抽象层设计
c++·mfc
平安的平安24 天前
面向大模型算子开发的高效编程范式PyPTO深度解析
c++·mfc