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显示控件

相关推荐
兵哥工控11 小时前
MFC用高精度计时器实现五段时序控制的改进
c++·mfc
许杰小刀3 天前
SourceGenerator之partial范式及测试
c++·mfc
weixin_446023563 天前
C语言开发Win32程序太麻烦?微软不支持有3个原因
c语言·微软·mfc·win32程序·开发难度
小黄人软件9 天前
MFC为什么不报空指针异常 2宏定义不改源码 用替换 用Log函数替换printf等 #define printf Log 优化版底层类Log显示
c++·mfc
dddddppppp12310 天前
mfc实现的贪吃蛇游戏
c++·游戏·mfc
XZHOUMIN10 天前
【生成pdf格式的报告】
c++·pdf·mfc
AIminminHu12 天前
OpenGL渲染与几何内核那点事-项目实践理论补充(一-1-(5)番外篇:给 CAD 加上“控制台”——让用户能实时“调参数、看性能”)
qt·mfc·cad
懒惰的bit12 天前
MFC常见消息映射(简洁版)
c++·mfc
火星机器人life17 天前
turtlebot3 Ubuntu 20.04 + ROS2 Foxy+Gazebo 11.15.1 环境下编译运行
数据库·ubuntu·mfc
Aevget19 天前
MFC扩展库BCGControlBar Pro v37.3新版亮点:Ribbon Bar等控件功能升级
c++·ribbon·mfc·界面控件·ui开发