Newer
Older
PrismSoftware / ECTrainer2 / MyWinUtils.h
#pragma once

#include <Windows.h>
#include <tchar.h>
#include <string>
#include <vector>

#define SAFE_DELETE(x) if (x) { delete x; x = NULL; }
#define SAFE_DELETE_ARRAY(x) if (x) { delete [] x; x = NULL; }

namespace mwut {

	typedef std::vector<std::vector<std::string>> STR_TABLE;

	// スワップクラス
	template<class T>
	class SWAP {
	public:
		static void DO(T& a, T& b) {
			T tmp = a;
			a = b;
			b = tmp;
		}
	};

	// マルチバイト文字列をワイド文字列(UNICODE)に変換
	std::wstring Multi2Wide(std::string const& src);

	// 書式付きデバッグ出力
	int DebugPrintf(LPCTSTR format, ...);

	// テーブルを読み込み
	bool ReadTable(const std::string& filename, STR_TABLE& table, const char delimiter = ',');

	// マルチディスプレイの情報を取得
	// 要素0:メインウインドウ
	std::vector<RECT> GetDisplayInfo();

	// ディスプレイ情報取得コールバック
	BOOL CALLBACK MonitorEnumProc(
		HMONITOR hMon, HDC hdcMon, LPRECT lpMon, LPARAM dwData);

	// 安全なデリート
	void SafeDelete(void** ptr);

	// 高精度タイマークラス
	class HPTimer {
		LARGE_INTEGER _nFreq;	// 周波数
		LARGE_INTEGER _nBegin;	// 開始時間
		LARGE_INTEGER _nLast;	// 前回問い合わせ時間
		double Calc(LARGE_INTEGER before);

	public:
		HPTimer();
		double Elapse();	// 開始時からの経過時間(ms)
		double Interval();	// 前回からの経過時間(ms)
		void Reset();		// 開始時間リセット
		static void HPSleep(double delayms);	// 高精度Sleep
	};
}