Windows Client development-enable the client to remember the size and location of the last Shutdown (win32 application)

Source: Internet
Author: User

Windows Client development-enable the client to remember the size and location of the last Shutdown (win32 application)

Previously, I wrote a blog on how to store the windowplacement struct in MFC. We use the write-in registry.

In win32 application, you also try to write information to the registration area.

However, I am getting more and more confused, so I should write the. ini file, write and read the self-defined. ini file, instead of writing win. ini.

Reading and writing. ini files is an old problem.

But now we want to write a struct. How can we do this?
The data we read is also stored in a struct. How can this problem be solved?

Yes, windows provides us with APIs:
WritePrivateProfileStruct
GetPrivateProfileStruct

First, obtain the structure of windowplacement:

WINDOWPLACEMENT wp;GetWindowPlacement(this->GetHWND(), &wp);

Next, write the configuration file:

WritePrivateProfileStruct(L"Main", L"WP", &wp, sizeof(wp), L"D:\\123.ini");

Note that we can use the return value of the WritePrivateProfileStruct function to determine whether it is true or false.

After the write is successful, let's take a look at 123.ini

[Main]WP=2C0000000000000001000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0A02000062000000B60500007A030000C3

The next task is also very easy, that is, how to read the configuration file to the struct:

WINDOWPLACEMENT wp;GetPrivateProfileStruct(L"Main", L"WP", &wp, sizeof(wp), L"D:\\123.ini");SetWindowPlacement(this->GetHWND(), &wp);

In this way, the windows client will record the window size at the time of last exit.

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.