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

相关推荐
何以解忧,唯有..1 小时前
Go 语言数据类型详解:从基础到复合类型
开发语言·golang·mfc
tiandyoin1 天前
MFC奇怪问题--连续窗口ID,关闭其中一个才能打开另一个
dialog·mfc·vc++·ws_child·mdi
兵哥工控6 天前
高精度微秒延时函数实现顺控工控项目实例
c++·mfc·硬件高精度计时器
兵哥工控7 天前
MFC开关量输出发脉冲实例
c++·mfc·开关量发脉冲
ZK_H9 天前
MFC学习——简易计算器以及跨应用通信
学习·5g·mfc
ZK_H10 天前
MFC程序开发自学笔记其一——windows应用程序与c++基础
c++·笔记·mfc
还在点灯@15 天前
基于visual studio的MFC上位机实现界面切换
c++·visualstudio·mfc
徐安安_ye118 天前
FlashAttention与文本生成:让AI妙笔生花
c++·人工智能·mfc
兵哥工控19 天前
MFC 动态数组CArray类使用说明实例
c++·mfc
ytttr87320 天前
OPC UA 协议栈 C 语言实现
c语言·开发语言·mfc