Checking if a window is active

后端 未结 2 814
野性不改
野性不改 2021-01-25 11:55

I have a console application that uses GetAsyncKeyState();, but if the user is on looking at another window and pressed a button, GetAsyncKeyState(); p

相关标签:
2条回答
  • 2021-01-25 12:37

    This thing worked for me:

    HWND name;
    name=GetForegroundWindow();
    
    while(!_kbhit()){
       if(name==GetForegroundWindow())
          printf("Mine window is active\n");
       else
          printf("Mine window is not active\n");
    }
    
    0 讨论(0)
  • 2021-01-25 12:56

    To get the active Window you can call GetActiveWindow. GetFocus will return the handle of the window that has the input focus. This window can be a control as well. So you can check against your window handle and see if it has the focus.

    0 讨论(0)
提交回复
热议问题