SampleIni
Visual C++ 2005 Express Edition
Windows Server 2003 SP1 Platform SDK
Windowsアプリケーション / 空のプロジェクト
SampleIni.c
// マルチバイト文字セット #include
#include
#define APPNAME "SampleIni" // グローバル変数 static HINSTANCE g_hInstance; static char g_acIniFile[_MAX_PATH]; // プロトタイプ宣言 LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void OnDestroy(HWND hWnd); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char acAppName[] = APPNAME; WNDCLASSEX wcex; HWND hWnd; MSG msg; char acDrive[_MAX_DRIVE]; char acDir[_MAX_DIR]; char acFname[_MAX_FNAME]; char acExt[_MAX_EXT]; int iX; int iY; g_hInstance = hInstance; _splitpath_s(__argv[0], acDrive, _MAX_DRIVE, acDir, _MAX_DIR, acFname, _MAX_FNAME, acExt, _MAX_EXT); _makepath_s(g_acIniFile, _MAX_PATH, acDrive, acDir, acFname, ".ini"); iX = GetPrivateProfileInt("General", "iX", 0, g_acIniFile); iY = GetPrivateProfileInt("General", "iY", 0, g_acIniFile); wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = 0; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = g_hInstance; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); wcex.lpszMenuName = NULL; wcex.lpszClassName = acAppName; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassEx(&wcex); hWnd = CreateWindow( acAppName, // ClassName acAppName, // WindowName WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX, iX, // x iY, // y 640, // Width 480, // Height NULL, // WndParent NULL, // Menu g_hInstance, NULL); // Param if (hWnd == NULL) { return 0; } ShowWindow(hWnd, nCmdShow); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: OnDestroy(hWnd); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } void OnDestroy(HWND hWnd) { RECT rect; char acBuf[16]; GetWindowRect(hWnd, &rect); sprintf_s(acBuf, sizeof(acBuf), "%d", rect.left); WritePrivateProfileString("General", "iX", acBuf, g_acIniFile); sprintf_s(acBuf, sizeof(acBuf), "%d", rect.top); WritePrivateProfileString("General", "iY", acBuf, g_acIniFile); }