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

相关推荐
aq55356007 天前
Laravel7.x十大革新特性详解
大数据·elasticsearch·mfc
aq55356007 天前
Laravel8.x新特性全解析
c++·elasticsearch·mfc
嵌入式老牛7 天前
OpenCV与MFC混合编程中的图像格式转换研究
人工智能·opencv·mfc
aq55356008 天前
开源吐槽大会:让技术痛点变笑点
c++·mfc
香蕉鼠片12 天前
MFC是什么
c++·mfc
兵哥工控14 天前
MFC中return和break用法示例
c++·mfc
飞鸟真人16 天前
MFC对话框中集成CEF组件 (chromium-146.0.7680.179)
mfc·cef·浏览器控件
道剑剑非道19 天前
【C++ 仿 MFC 反射系统】
开发语言·c++·mfc
jolimark19 天前
微软不支持C开发Win32原因剖析,及C语言在系统开发中的优势
c语言·微软·mfc·系统开发·win32
今天又在学代码写BUG口牙19 天前
MFC 定时器轮询实现按住按钮进度条增加(鼠标悬停/长按检测)
c++·mfc·定时器·鼠标·轮询·长按事件