3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

openframeoworks098+VS2015で疑似フルスクリーン

Last updated at Posted at 2017-05-02

oopenframeowirks0.9.8使ってて、
・win環境だとフルスクリーンにすると変なティアリングとか入てどうもコマ落ちしてる感じがする時がある。
・vs2015でフルスクリーン時にアプリが落ちるとvsごと再起動しなくちゃいけないのでかったるい。
・プライマリ以外のモニターでフルスクリーンにしにくい。
辺りの問題を回避できそうな方法を見つけたのでメモ。

void Brunch::toggleWindowModeAsFullscreen()
{
	HMONITOR hMonitor;
	MONITORINFOEX  MonitorInfoEx;
	HDC glDc = wglGetCurrentDC();
	HWND hWnd = WindowFromDC(glDc);

	POINT pos = { ofGetWindowPositionX(), ofGetWindowPositionY() };

	hMonitor = MonitorFromPoint(pos, MONITOR_DEFAULTTONEAREST);
	// get
	MonitorInfoEx.cbSize = sizeof(MonitorInfoEx);
	GetMonitorInfo(hMonitor, &MonitorInfoEx);

	// Show
	cout << "WindowPos " << pos.x << ", " << pos.y << endl;
	cout << "Monitor.bottom = " << MonitorInfoEx.rcMonitor.bottom << endl;
	cout << "Monitor.left = " << MonitorInfoEx.rcMonitor.left << endl;
	cout << "Monitor.right = " << MonitorInfoEx.rcMonitor.right << endl;
	cout << "Monitor.top =  " << MonitorInfoEx.rcMonitor.top << endl;

	int scrW = MonitorInfoEx.rcMonitor.right - MonitorInfoEx.rcMonitor.left;
	int scrH = MonitorInfoEx.rcMonitor.bottom - MonitorInfoEx.rcMonitor.top;
	int monitorOriginX = MonitorInfoEx.rcMonitor.left;
	int monitorOriginY = MonitorInfoEx.rcMonitor.top;

	if (MonitorInfoEx.dwFlags == MONITORINFOF_PRIMARY)
	{
		puts("This is Primary Monitor");
	}
	else
	{
		puts("This is not Primary Monitor");
	}

	if (scrW == ofGetWidth() && scrH == ofGetHeight())
	{
		DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
		if (dwStyle & WS_CAPTION) {
			dwStyle &= ~WS_CAPTION;
		}
		else {
			dwStyle |= WS_CAPTION;
		}
		SetWindowLong(hWnd, GWL_STYLE, dwStyle);
		SetWindowPos(hWnd, HWND_TOP, monitorOriginX + 30, monitorOriginY + 30, scrW*.7, scrH*.7, SWP_SHOWWINDOW);
	}
	else
	{
		SetWindowLong(hWnd, GWL_STYLE, WS_POPUP);
		SetWindowPos(hWnd, HWND_TOP, monitorOriginX, monitorOriginY, scrW, scrH, SWP_SHOWWINDOW);
	}
}

上の関数を作って実行すれば任意のモニターで疑似フルスクリーンになる。はず。
大きさとか後から再調整できないなくなるので、変えたい場合はSetWindowPosを適当な値を入れてもう一回呼ぶこと。とりあえずうごいてるようなので深追いはしない。

というか、of依存してるのofGetWindowPosition~だけなので、
ほぼof関係なかった。。。

追記
サンプルの動作をトグルっぽくなるようにした。

動作確認環境は
windows10
openframeworks 0.9.8
VisualStudio2015

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?