点击快捷方式,不又一次启动程序而是让程序窗体又一次显示的解决方式


如题:

在代码的入口处加入:


int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{

	if (try_show_first_windows(NULL, "魔方服务控制台"))
	{
		return 0;
	}

try_show_first_windows的实现为:


BOOL try_show_first_windows(LPCSTR cls, LPCSTR wnd_cap)
{
	HWND hTheWest = FindWindowA(cls, wnd_cap);
	if (hTheWest)
	{
		CWindow cds;
		cds.Attach(hTheWest);
		cds.ShowWindow(SW_RESTORE);
		cds.SetWindowPos(HWND_TOP, NULL, NULL, NULL, NULL, SWP_NOSIZE | SWP_NOREPOSITION);
		cds.CenterWindow(hTheWest);
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}


原文地址:https://www.cnblogs.com/lytwajue/p/6863539.html