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.