const IID g_clsid = {0x7e5fe3d9,0x985f,0x4908,0x91,0xf9,0xee,0x19,0xf9,0xfd,0x15,0x14}; const IID g_riid = {0x2246EA2D,0xCAEA,0x4444,0xA3,0xC4,0x6D,0xE8,0x27,0xE4,0x43,0x13}; /////////////////////////////////////////////////////////////////////////////////////////////////////// void toTop(HWND hDlg) { int i, idTop, idSelf; IAppVisibility* p; INPUT inp; if(0x0601 < _byteswap_ushort(GetVersion())) // ver > Win7 ? { CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); if(!CoCreateInstance(&g_clsid, 0, CLSCTX_INPROC_SERVER, &g_riid, (void**)&p)) { p->lpVtbl->IsLauncherVisible(p, &i); p->lpVtbl->Release(p); if(i) //are we in Metro? { inp.type = INPUT_KEYBOARD; inp.ki.wVk = VK_LWIN; inp.ki.wScan = MapVirtualKey(VK_LWIN, 0); inp.ki.time = 0; inp.ki.dwExtraInfo = 0; inp.ki.dwFlags = KEYEVENTF_EXTENDEDKEY; SendInput(1, &inp, sizeof(inp)); //Win key down inp.ki.dwFlags |= KEYEVENTF_KEYUP; SendInput(1, &inp, sizeof(inp)); //Win key up } } CoUninitialize(); } if(IsIconic(hDlg)) //are we in a tray? { ShowWindow(hDlg, SW_RESTORE); UpdateWindow(hDlg); } idTop = GetWindowThreadProcessId(GetForegroundWindow(), 0); idSelf = GetWindowThreadProcessId(hDlg, 0); if(idTop != idSelf) //are we on the top already? { AttachThreadInput(idTop, idSelf, 1); BringWindowToTop(hDlg); AttachThreadInput(idTop, idSelf, 0); } } |