LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
switch (iMessage) {
case WM_CREATE: {
TCHAR str[128];
TCHAR drive[_MAX_DRIVE];
TCHAR dir[MAX_PATH];
TCHAR path[256];
RECT rt;
GetModuleFileName(NULL,str,128);
_splitpath(str,drive,dir,NULL,NULL);
strcpy(path, drive);
strcat(path, dir);
strcat(path, "IniFile.ini");
rt.left=GetPrivateProfileInt("Position", "Left", 0, path);
rt.top=GetPrivateProfileInt("Position", "Top", 0, path);
rt.right=GetPrivateProfileInt("Position", "Right", 100, path);
rt.bottom=GetPrivateProfileInt("Position", "Bottom", 100, path);
MoveWindow(hWnd, rt.left, rt.top, rt.right-rt.left,
rt.bottom-rt.top, TRUE);
}
return 0;
case WM_DESTROY: {
TCHAR str[128];
TCHAR drive[_MAX_DRIVE];
TCHAR dir[MAX_PATH];
TCHAR path[256];
RECT rt;
TCHAR buf[10];
GetModuleFileName(NULL,str,128);
_splitpath(str,drive,dir,NULL,NULL);
strcpy(path, drive);
strcat(path, dir);
strcat(path, "IniFile.ini");
GetWindowRect(hWnd, &rt);
itoa(rt.left, buf, 10);
WritePrivateProfileString("Position", "Left", buf, path);
itoa(rt.top, buf, 10);
WritePrivateProfileString("Position", "Top", buf, path);
itoa(rt.right, buf, 10);
WritePrivateProfileString("Position", "Right", buf, path);
itoa(rt.bottom, buf, 10);
WritePrivateProfileString("Position", "Bottom", buf, path);
PostQuitMessage(0);
}
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}