#include "stdafx.h"

//#include <windows.h>

void
crop(char *str)
{
	int i;

	for (i = strlen(str) - 1; i >= 0; i++) {
		if (str[i] == ' ') str[i] = '\0';
		else break;
	}
}

//**************************************************************************
//*
//*	set_windows_pos_best
//*	ウィンドウを最適な位置に移動
//*
//**************************************************************************
void
set_windows_pos_best(HWND hwnd)
{
	POINT p;
	RECT r;
	int cx1, cy1, cx2, cy2;

	GetCursorPos(&p);
	GetWindowRect(hwnd, &r);

	cx1 = GetSystemMetrics(SM_CXSCREEN) / 2;
	cy1 = GetSystemMetrics(SM_CYSCREEN) / 2;
	cx2 = (r.right - r.left) / 2;
	cy2 = (r.bottom - r.top) / 2;

	p.x = (p.x - cx1) * (cx1 - cx2) / cx1 / 2 + cx1;
	p.y = (p.y - cy1) * (cy1 - cy2) / cy1 / 2 + cy1;
	p.x -= cx2;
	p.y -= cy2;

	SetWindowPos(hwnd, NULL, p.x, p.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}

//**************************************************************************
//*
//*	change_to_moduledir
//*	exeのあるディレクトリに移動
//*
//**************************************************************************
void
change_to_moduledir(void)
{

#ifdef _DEBUG
	char path[_MAX_PATH];
	char drive[_MAX_DRIVE];
	char dir[_MAX_DIR];

	GetModuleFileName(NULL, path, _MAX_PATH);
	_splitpath(path, drive, dir, NULL, NULL);
	wsprintf(path, "%s%s..", drive, dir);
	SetCurrentDirectory(path);
#else
	char path[_MAX_PATH];
	char drive[_MAX_DRIVE];
	char dir[_MAX_DIR];

	GetModuleFileName(NULL, path, _MAX_PATH);
	_splitpath(path, drive, dir, NULL, NULL);
	wsprintf(path, "%s%s", drive, dir);
	SetCurrentDirectory(path);
#endif
}
