Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Unfocusable windows on Win32

by bbfu (Curate)
on Jul 03, 2004 at 07:57 UTC ( #371558=snippet: print w/ replies, xml ) Need Help??

Description:

This function will allow you to make a window unfocusable. An unfocusable window can be interacted with, but not focused. Also, it doesn't appear in the Alt-Tab window list, nor does it appear in the Taskbar.

I use this on my Gaim Buddy List so that it doesn't get in the way when I'm Alt-Tabbing around.

use Win32::API;
use Win32::GuiTest 'FindWindowLike';

use constant SW_SHOW          => 0x5;
use constant SW_HIDE          => 0x0;
use constant GWL_EXSTYLE      => -20;
use constant WS_EX_NOACTIVATE => 0x8000000;

sub unfocusable_window {
  my $win = shift;
  my ($hwnd) = FindWindowLike(undef, $win)
    or die "Couldn't find window $win\n";

  my $style = GetWindowLong($hwnd, GWL_EXSTYLE);
  $style |= WS_EX_NOACTIVATE;

  ShowWindow($hwnd, SW_HIDE);
  SetWindowLong($hwnd, GWL_EXSTYLE, $style);
  ShowWindow($hwnd, SW_SHOW);
}

sub focusable_window {
  my $win = shift;
  my ($hwnd) = FindWindowLike(undef, $win)
    or die "Couldn't find window $win\n";

  my $style = GetWindowLong($hwnd, GWL_EXSTYLE);
  $style &= ~WS_EX_NOACTIVATE;

  ShowWindow($hwnd, SW_HIDE);
  SetWindowLong($hwnd, GWL_EXSTYLE, $style);
  ShowWindow($hwnd, SW_SHOW);
}
Comment on Unfocusable windows on Win32
Download Code

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://371558]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2014-07-31 01:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (244 votes), past polls