Oct 20th, 2000, 02:42 PM
Ok, all this app is supposed to do, at the moment, is load at the pos and size from which it was exited at. But for some reason, whenever you start it, its bigger. The top-right corner is in the right place, but the window itself is bigger for some reason. Then if you exit and start it again, itll be even bigger. Heres the code, if i didnt explain it right, let me know.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
HINSTANCE hAppInstance;
HWND hMainWindow;
int WindowX1;
int WindowX2;
int WindowY1;
int WindowY2;
void LoadVar();
void SaveVar();
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wc;
MSG Msg;
hAppInstance = hInstance;
LoadVar();
wc.cbClsExtra = NULL;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = NULL;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor((HINSTANCE)NULL, IDC_ARROW);
wc.hIcon = LoadIcon(hAppInstance, IDI_APPLICATION);
wc.hIconSm = LoadIcon(hAppInstance, IDI_APPLICATION);
wc.hInstance = hAppInstance;
wc.lpfnWndProc = MainWindowProc;
wc.lpszClassName = "MainWindowClass";
wc.lpszMenuName = NULL;
wc.style = NULL;
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Could not register 'MainWindowClass'.\nShuttin down...", "Error", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
hMainWindow = CreateWindowEx(NULL, "MainWindowClass", "HeroDev", WS_OVERLAPPEDWINDOW, WindowX1, WindowY1, WindowX2, WindowY2, NULL, NULL, hAppInstance, NULL);
if(!hMainWindow)
{
MessageBox(NULL, "Could not create window 'hMainWindow'.\nShutting down...", "Error", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
ShowWindow(hMainWindow, nShowCmd);
UpdateWindow(hMainWindow);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
SaveVar();
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
void LoadVar()
{
WindowX1 = GetPrivateProfileInt("Position", "X1", 200, "herodev.ini");
WindowY1 = GetPrivateProfileInt("Position", "Y1", 200, "herodev.ini");
WindowX2 = GetPrivateProfileInt("Position", "X2", 200, "herodev.ini");
WindowY2 = GetPrivateProfileInt("Position", "Y2", 200, "herodev.ini");
}
void SaveVar()
{
RECT MainWindow;
char x1[sizeof(WindowX1)];
char y1[sizeof(WindowY1)];
char x2[sizeof(WindowX2)];
char y2[sizeof(WindowY2)];
GetWindowRect(hMainWindow, &MainWindow);
sprintf(x1, "%d", MainWindow.left);
sprintf(y1, "%d", MainWindow.top);
sprintf(x2, "%d", MainWindow.right);
sprintf(y2, "%d", MainWindow.bottom);
WritePrivateProfileString("Position", "X1", x1, "herodev.ini");
WritePrivateProfileString("Position", "Y1", y1, "herodev.ini");
WritePrivateProfileString("Position", "X2", x2, "herodev.ini");
WritePrivateProfileString("Position", "Y2", y2, "herodev.ini");
}
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
HINSTANCE hAppInstance;
HWND hMainWindow;
int WindowX1;
int WindowX2;
int WindowY1;
int WindowY2;
void LoadVar();
void SaveVar();
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wc;
MSG Msg;
hAppInstance = hInstance;
LoadVar();
wc.cbClsExtra = NULL;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = NULL;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor((HINSTANCE)NULL, IDC_ARROW);
wc.hIcon = LoadIcon(hAppInstance, IDI_APPLICATION);
wc.hIconSm = LoadIcon(hAppInstance, IDI_APPLICATION);
wc.hInstance = hAppInstance;
wc.lpfnWndProc = MainWindowProc;
wc.lpszClassName = "MainWindowClass";
wc.lpszMenuName = NULL;
wc.style = NULL;
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Could not register 'MainWindowClass'.\nShuttin down...", "Error", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
hMainWindow = CreateWindowEx(NULL, "MainWindowClass", "HeroDev", WS_OVERLAPPEDWINDOW, WindowX1, WindowY1, WindowX2, WindowY2, NULL, NULL, hAppInstance, NULL);
if(!hMainWindow)
{
MessageBox(NULL, "Could not create window 'hMainWindow'.\nShutting down...", "Error", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
ShowWindow(hMainWindow, nShowCmd);
UpdateWindow(hMainWindow);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
SaveVar();
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
void LoadVar()
{
WindowX1 = GetPrivateProfileInt("Position", "X1", 200, "herodev.ini");
WindowY1 = GetPrivateProfileInt("Position", "Y1", 200, "herodev.ini");
WindowX2 = GetPrivateProfileInt("Position", "X2", 200, "herodev.ini");
WindowY2 = GetPrivateProfileInt("Position", "Y2", 200, "herodev.ini");
}
void SaveVar()
{
RECT MainWindow;
char x1[sizeof(WindowX1)];
char y1[sizeof(WindowY1)];
char x2[sizeof(WindowX2)];
char y2[sizeof(WindowY2)];
GetWindowRect(hMainWindow, &MainWindow);
sprintf(x1, "%d", MainWindow.left);
sprintf(y1, "%d", MainWindow.top);
sprintf(x2, "%d", MainWindow.right);
sprintf(y2, "%d", MainWindow.bottom);
WritePrivateProfileString("Position", "X1", x1, "herodev.ini");
WritePrivateProfileString("Position", "Y1", y1, "herodev.ini");
WritePrivateProfileString("Position", "X2", x2, "herodev.ini");
WritePrivateProfileString("Position", "Y2", y2, "herodev.ini");
}