Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. widows api setwindowpos with SWP_HIDEWINDOW not always works

widows api setwindowpos with SWP_HIDEWINDOW not always works

Scheduled Pinned Locked Moved Managed C++/CLI
c++jsonquestion
1 Posts 1 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    viewlucc
    wrote on last edited by
    #1

    int cpp_ptysetpg(unsigned long iProc) { HANDLE stdFds[3]; HWND hWnd; DWORD wndPId; int vRlt = 0; WINDOWINFO vInfo; hWnd = GetTopWindow(NULL); unsigned long vProc = GetCurrentProcessId(); iProc = vProc; assert(vProc == iProc); while (hWnd != NULL) { GetWindowThreadProcessId(hWnd, &wndPId); if (iProc == wndPId) break; hWnd = GetNextWindow(hWnd, GW_HWNDNEXT); } vRlt = SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 1, 1, SWP_NOACTIVATE| SWP_HIDEWINDOW); ShowWindow(hWnd, SW_HIDE); /* save the current standard handles */ stdFds[0] = GetStdHandle(STD_INPUT_HANDLE); stdFds[1] = GetStdHandle(STD_OUTPUT_HANDLE); stdFds[2] = GetStdHandle(STD_ERROR_HANDLE); FreeConsole(); if (AllocConsole()) SetConsoleCtrlHandler((PHANDLER_ROUTINE)myhdlr, TRUE); /* restore the standard handles */ SetStdHandle(STD_INPUT_HANDLE, stdFds[0]); SetStdHandle(STD_OUTPUT_HANDLE, stdFds[1]); SetStdHandle(STD_ERROR_HANDLE, stdFds[2]); hWnd = GetTopWindow(NULL); while (hWnd != NULL) { GetWindowThreadProcessId(hWnd, &wndPId); if (iProc == wndPId) break; hWnd = GetNextWindow(hWnd, GW_HWNDNEXT); } int test = 0; if (test) SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 1, 1, SWP_NOACTIVATE | SWP_HIDEWINDOW); else { vRlt = SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 1, 1, SWP_NOACTIVATE); assert(vRlt != 0); vRlt = SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 1, 1, SWP_HIDEWINDOW);//second call not always work assert(vRlt != 0); } vRlt = GetWindowInfo(hWnd, &vInfo); assert(vRlt != 0); if (vInfo.dwStyle&WS_VISIBLE) { assert(0); ShowWindow(hWnd, SW_HIDE); } vRlt = GetWindowInfo(hWnd, &vInfo); assert(vRlt != 0); if (vInfo.dwStyle&WS_VISIBLE) assert(0); return (0); } The second call (inside if(test) xx; else{ }) of SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 1, 1, SWP_NOACTIVATE) and SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 1, 1, SWP_HIDEWINDOW) does not always work. At least 1 of 10 times running of this function the window is still visible. However it always works with

    SWP_NOACTIVATE|SWP_HIDEWINDOW

    . Why?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups