Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.beta > #124

switching windows by titlebar text/name

From John Doe <jdoe@usenetlove.invalid>
Newsgroups comp.lang.beta
Subject switching windows by titlebar text/name
Date 2014-02-21 01:09 +0000
Organization A noiseless patient Spider
Message-ID <le690o$9rb$1@dont-email.me> (permalink)

Show all headers | View raw


[For the record]

I meant to implement this but then got wrapped up in adapting my 
macro recorder to Age of Empires. Found on the web, it makes a lot 
of sense. Activating another process's window just requires pressing 
the alt key first. That disarms Windows' lockout of 
SetForegroundWindow(). I implemented it briefly and it did work. The 
last part releases the alt key. But do not check whether releasing 
the key is okay (releasing a key doesn't hurt anything, just do it). 
Also... MFC includes a function to check whether the window is 
iconic. Check that first and you will also successfully pull up 
minimized windows from the taskbar. I did use the code below 
"keybd_event", but it probably works with SendInput() as well.

void SetForegroundWindowInternal(HWND hWnd)
{
  if(!::IsWindow(hWnd)) return;
  BYTE keyState[256]={0};
  //to unlock SetForegroundWindow we need to imitate Alt pressing
  if(::GetKeyboardState((LPBYTE)&keyState))
  {
    if(!(keyState[VK_MENU]&0x80))
    {
      ::keybd_event(VK_MENU,0,KEYEVENTF_EXTENDEDKEY|0,0);
    }
  }
  ::SetForegroundWindow(hWnd);
  if(::GetKeyboardState((LPBYTE)&keyState))
  {
    if(!(keyState[VK_MENU]&0x80))
    {
      ::keybd_event
(VK_MENU,0,KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP,0);
    }
  }
}

Back to comp.lang.beta | Previous | NextNext in thread | Find similar


Thread

switching windows by titlebar text/name John Doe <jdoe@usenetlove.invalid> - 2014-02-21 01:09 +0000
  Re: switching windows by titlebar text/name John Doe <jdoe@usenetlove.invalid> - 2014-02-24 05:32 +0000
  Re: switching windows by titlebar text/name John Doe <jdoe@usenetlove.invalid> - 2014-03-04 17:18 +0000
  Re: switching windows by titlebar text/name John Doe <jdoe@usenetlove.invalid> - 2014-03-08 01:40 +0000

csiph-web