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

相关推荐
阿昭L1 天前
MFC仿真
c++·mfc
怎么没有名字注册了啊1 天前
MFC_Install_Create
c++·mfc
Humbunklung2 天前
unordered_map使用MFC的CString作为键值遇到C2056和C2064错误
c++·stl·mfc
夜猫逐梦2 天前
【VC】 error MSB8041: 此项目需要 MFC 库
c++·mfc
一拳一个呆瓜4 天前
【MFC】对话框属性:Absolute Align(绝对对齐)
c++·mfc
深耕AI5 天前
MFC 图形设备接口详解:小白从入门到掌握
c++·mfc
ChindongX5 天前
CMap常用函数
mfc
一拳一个呆瓜5 天前
【MFC】对话框属性:X Pos(X位置),Y Pos(Y位置)
c++·mfc
一拳一个呆瓜5 天前
【MFC】对话框属性:Center(居中)
c++·mfc
一拳一个呆瓜6 天前
【MFC】对话框:位置属性(居中、绝对对齐、X位置Y位置)应用示例
c++·mfc