MFC 关闭窗口时候保存窗口位置
来源:互联网 发布:大宗商品数据 编辑:程序博客网 时间:2024/06/05 04:33
CWinApp::WriteProfileInt
Call this member function to write the specified value into the specified section of the application's registry or .INI file.
Copy
BOOL WriteProfileInt( LPCTSTR lpszSection, LPCTSTR lpszEntry, int nValue );
CWinApp提供了一组用于读写应用程序配置的方法!
CWinApp::GetProfileIntCWinApp::WriteProfileStringCWinApp::SetRegistryKey
还有上面的WriteProfileInt
Call this member function to write the specified value into the specified section of the application's registry or .INI file.
这句话告诉我们可以保存到注册表或者系统的INI文件当中
1:保存到注册表:
关于CWinApp::SetRegistryKey方法
如果在Inistance当中执行了 SetRegisterKey()方法
那么在调用 WriteProfileInt的时候,写入的数据将会保存到注册表当中
如果没有执行SetRegisterKey()方法,则写入的数据将会保存到INI文件当中
LPCTSTR m_pszProfileName; 应用程序的.INI文件名,一般和执行文件名相同。LPCTSTR m_pszRegistryKey; 用于确定保存应用程序主要设置的完整注册表键
UINT GetProfileInt( LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault ); 从应用程序的配置文件(.INI)的一个配置项中获取一个整数CString GetProfileString(LPCTSTR szSection, LPCTSTR szEntry, LPCTSTR szDefault = NULL ); 从应用程序的配置文件(.INI)的一个配置项中获取一个字符串BOOL WriteProfileInt(LPCTSTR szSection, LPCTSTR szEntry, int nValue ); 将一个整数写到应用程序的配置文件(.INI)文件的配置项中BOOL WriteProfileString(LPCTSTR szSect, LPCTSTR szEntry, LPCTSTR lpszValue ); 将一个字符串写到应用程序的配置文件(.INI)文件的配置项中void SetRegistryKey( LPCTSTR lpszRegistryKey ); 使应用程序的配置保存在注册表中,而不保存于(.INI)文件中
用法:
//窗口摧毁时候保存窗口的位置void CNotePadDlg::OnDestroy(){CDialog::OnDestroy();CRect rect;GetWindowRect(rect);theApp.WriteProfileInt("SETTING","left",rect.left);theApp.WriteProfileInt("SETTING","right",rect.right);theApp.WriteProfileInt("SETTING","top",rect.top);theApp.WriteProfileInt("SETTING","bottom",rect.bottom);}
//初始化窗口的位置,上次关闭时候所在的位置void CNotePadDlg::InitRect(){int nLeft = theApp.GetProfileInt("SETTING","left",-1);if(nLeft < 0)return;int nRight = theApp.GetProfileInt("SETTING","right",-1);if(nRight < 0)return;int nTop = theApp.GetProfileInt("SETTING","top",-1);if(nTop < 0)return;int nBottom = theApp.GetProfileInt("SETTING","bottom",-1);if(nBottom < 0)return;MoveWindow(nLeft,nTop,nRight-nLeft,nBottom - nTop);}
记得在InitDialog中加入InitRect()函数的调用
BOOL CNotePadDlg::OnInitDialog(){CDialog::OnInitDialog();InitRect();LoadFont();m_hAccel = ::LoadAccelerators(AfxGetInstanceHandle(),(LPCTSTR)IDR_ACCELERATOR1);// Set the icon for this dialog. The framework does this automatically// when the application's main window is not a dialogSetIcon(m_hIcon, TRUE);// Set big iconSetIcon(m_hIcon, FALSE);// Set small icon// TODO: Add extra initialization herereturn TRUE; // return TRUE unless you set the focus to a control}
运行程序,出现窗口,把窗口拖到指定位置关闭,下次启动会出现在指定
0 0
- MFC 关闭窗口时候保存窗口位置
- MFC 调整窗口位置
- MFC关闭窗口
- MFC 窗口关闭过程
- MFC关闭窗口事件
- 关闭窗口的时候提示
- MFC窗口位置管理分析
- MFC窗口位置管理分析
- mfc 改变窗口位置大小
- 【交互】MFC窗口位置分析
- MFC窗口不能正常关闭
- MFC窗口的关闭过程
- MFC屏蔽回车关闭窗口
- MFC 窗口关闭消息函数
- mfc 彻底关闭窗口进程
- MFC回车后关闭窗口
- MFC关闭窗口实现隐藏
- MFC保存窗口为图片
- 最牛B的编码套路
- Android的闪光灯
- iOS上应用如何兼容32位系统和64位系统
- mybatis 分页查询 limit
- 淘宝的jvm监控(TProfile)
- MFC 关闭窗口时候保存窗口位置
- Yii2.0 数据库查询
- 静态查找表与计算平均查找长度
- MySQL UUID函数的详解
- SQL未赋值变量参与计算,结果为空
- 基于NAND Flash的转译层的设计
- Android组件及UI框架大全
- cocos2dx 3.2 利用clippingNode把图片裁剪成圆形,接口可直接使用
- 在网页中通过userAgent获取手机获取手机操作系统类型