MFC saves window position when window is closed

Source: Internet
Author: User

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 provides a set of methods for reading and writing application configurations!
Cwinapp::getprofileint cwinapp::writeprofilestring Cwinapp::setregistrykey
and the writeprofileint above.
Call this member function to write the specified value into the specified section of the application ' s registry or. INI file.
This tells us that we can save it to the registry or to the INI file of the system.
1: Save to Registry:
About the Cwinapp::setregistrykey method
If the Setregisterkey () method is executed in the Inistance
Then when calling Writeprofileint, the data written will be saved to the registry
If the Setregisterkey () method is not executed, the data being written is saved to the INI file
LPCTSTR M_pszprofilename; Application's. INI file name, typically the same as the execution file name. LPCTSTR M_pszregistrykey; The complete registry key to determine the primary settings for the Save application
UINT Getprofileint (LPCTSTR lpszsection, LPCTSTR lpszentry, int ndefault); From the application's configuration file (. INI), get an integer CString getprofilestring (lpctstr szsection, LPCTSTR szentry, lpctstr szdefault = NULL) in a configuration item; From the application's configuration file (. INI) gets a string of bool Writeprofileint (LPCTSTR szsection, LPCTSTR szentry, int nvalue) in a configuration item; Writes an integer to the application's configuration file (. INI) file in the configuration item bool WriteProfileString (LPCTSTR szsect, LPCTSTR szentry, LPCTSTR lpszvalue); Writes a string to the application's configuration file (. INI) file in the configuration entry in void Setregistrykey (LPCTSTR lpszregistrykey); The configuration of the application is saved in the registry, not saved in the (. INI) file
Usage:
Window is destroyed when the window's position is saved 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);}
The position of the initialization window, where it was last closed, 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);}


Remember to add a call to the Initrect () function in InitDialog
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 was not a Dialogseticon (M_hicon, TRUE);//Se T Big Iconseticon (M_hicon, FALSE);//Set small icon//todo:add extra initialization herereturn TRUE;  Return TRUE  Unless you set the focus to a control}
Run the program, the window appears, drag the window to the specified location to close, the next boot will appear in the specified

MFC saves window position when window is closed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.