1. mfc读取数据保存数据到文件
关于CFile的文件路径,分两种方式,一种是绝对路径,一种是相对路径。
绝对路径就是”D:\\a\\xx.txt"的形式,你可以直接指定,也可以用CFileDialog弹出对话框由用户界面指定;
相对路径分默认路径和工作路径获取两种。你可以用".\\aa\\xx.txt"指定默认目录子目录或者省略前面的.\\也是可以的;工作路径获取比较靠谱(因为默认路径可能会造成不确定性,在程序运行过程中可能会被其它原因改变),工作路径要在程序运行入口的时候通过GetCurrentDirectory函数获取并保存起来,方便随时使用,这个是一个例如"d:\\yourProject\\"的字符串形式,每次拼接子目录和文件名即可,示例代码如下:
???????char?pBuf[MAX_PATH];?????????????????//存放路径的变量
???????GetCurrentDirectory(MAX_PATH,pBuf);??//获取程序的当前目录
???????strcat(pBuf,"\\");
???????CString?strtemp=pBuf;
2. mfc保存数据为excel
直接调用shellexecute()函数即可,将第二个参数设置为open,第三个参数设置为文件路径
3. mfc获取文件
解决办法1、通过一定的途径获取到mfc140u.dll文件,例如网上寻找并下载。
2、将mfc140u.dll文件复制到“C:\Windows\System32”这个目录下。
3、点击“开始菜单”,选择“运行”按钮,输入:regsvr32 mfc140u.dll,点击确定。
4、此时弹出安装完成mfc140u.dll文件的提示,点击确定。
4. mfc读取文件内容
方法如下:
一、通过查阅msdn,可以知道GetSystemTimes函数可以获取系统的时间,可以获得系统(自开机以来)处于Kernel状态下面的CPU时间,以及系统处于User状态下的时间,以及Idle的时间.我们只用Kernel时间和User时间, 不用Idle时间。
二、通过计算公式来计算
(总的时间-空闲时间)/总的时间=占用cpu的时间就是使用率 。
三、简单写个demo测试下,代码如下
#include <stdio.h>
#include <Windows.h>
#include <time.h>
#include <tchar.h>
__int64 DiffFileTime(FILETIME time1, FILETIME time2)
{
__int64 a = time1.dwHighDateTime << 32 | time1.dwLowDateTime;
__int64 b = time2.dwHighDateTime << 32 | time2.dwLowDateTime;
return b - a;
}
int main(int argc, char* argv[])
{
double cpuuse;
int idle, kernel, user;
FILETIME idleTime1, idleTime2;
FILETIME kernelTime1, kernelTime2;
FILETIME userTime1, userTime2;
do
{
GetSystemTimes(&idleTime1, &kernelTime1, &userTime1);
Sleep(1000);
GetSystemTimes(&idleTime2, &kernelTime2, &userTime2);
idle = (int)DiffFileTime(idleTime1, idleTime2);
kernel = (int)DiffFileTime(kernelTime1, kernelTime2);
user = (int)DiffFileTime(userTime1, userTime2);
if (kernel + user == 0)
cpuuse = 0.0;
else
cpuuse = abs((kernel + user - idle) * 100 / (kernel + user));//(总的时间-空闲时间)/总的时间=占用cpu的时间就是使用率
printf("cpu useage: %01f!\n", cpuuse);
} while (1);
return 0;
}
四、运行程序,对比任务管理器的cpu使用率,发现是一样的,可以参考以上代码把这功能代码封装成一个功能函数,方便调用。
五、接下来,进一步对代码进行优化,将获取cpu的封装成一个通用的接口,优化后代码如下:
#include <stdio.h>
#include <Windows.h>
#include <time.h>
#include <tchar.h>
__int64 DiffFileTime(FILETIME time1, FILETIME time2)
{
__int64 a = time1.dwHighDateTime << 32 | time1.dwLowDateTime;
__int64 b = time2.dwHighDateTime << 32 | time2.dwLowDateTime;
return b - a;
}
double GetCpuUsage()
{
double cpuuse;
int idle, kernel, user;
FILETIME idleTime1, idleTime2;
FILETIME kernelTime1, kernelTime2;
FILETIME userTime1, userTime2;
GetSystemTimes(&idleTime1, &kernelTime1, &userTime1);
Sleep(1000);
GetSystemTimes(&idleTime2, &kernelTime2, &userTime2);
idle = (int)DiffFileTime(idleTime1, idleTime2);
kernel = (int)DiffFileTime(kernelTime1, kernelTime2);
user = (int)DiffFileTime(userTime1, userTime2);
if (kernel + user == 0)
cpuuse = 0.0;
else
cpuuse = abs((kernel + user - idle) * 100 / (kernel + user));//(总的时间-空闲时间)/总的时间=占用cpu的时间就是使用率
return cpuuse;
}
int main(int argc, char* argv[])
{
double cpuusage = 0;
do
{
cpuusage = GetCpuUsage();
printf("cpu useage: %01f!\n", cpuuse);
} while (1);
return 0;
}
5. mfc如何保存文件
扫描文件一般会有两步,第一步预扫,完成后会显示整个文件的全部,选定要扫描的部分后,再按扫描键,扫描仪会对选定的部分进行扫描,在设定的界面上有扫描后文件存放的文件夹的,选定保存文件夹就可以保存了
6. mfc文件的读取和保存
先创建一个user.txt文档;
然后在需要保存数据的地方打开user。txt文档,进行写操作,最后关闭。
//对文件进行写操作
CFile mFile(_T("user.txt "), CFile::modeWrite|CFile::modeCreate);
mFile.Write(sRead,2);
mFile.Flush();
mFile.Close();
7. mfc数据库文件怎么使用
你可以使用Edit控件,设置为多行,不可编辑。
如果还想还一些,那么就改写Edit。
8. mfc读取数据生成图形
注意OnInitDialog和OnPaint里添加的代码。
我把透明色设置为RGB(1, 1, 1)了,图片里原有的RGB(1, 1, 1) 我给调成 RGB(0, 0, 0) 了。
9. mfc 读取文件
你可以先把所有文件读到数组里面,再将数组分成两半,进行加密,然后将结果写回去。一个文件多个线程可以同时读,但不可以同时读写的。
- 相关评论
- 我要评论
-