slloyd has asked for the wisdom of the Perl Monks concerning the following question:
Feel free to play around with it and add to it. I look forward to seeing your permutations
#!perl #windemo.pl #Created by Steve Lloyd, http://www.basgetti.com #Feel free to modify and use this code as you wish. use strict; use Win32::GUI; use Win32::API; my $MainWidth=400; #Width of Window my $MainHeight=400; #Height of Window my @styleStrings=( "WS_SYSMENU WS_MINIMIZE WS_MINIMIZEBOX WS_MAXIMIZE WS_MAXIMIZEBOX" +, # Normal Window "WS_SYSMENU WS_MINIMIZE WS_MINIMIZEBOX WS_MAXIMIZE WS_MAXIMIZEBOX +WS_VSCROLL", # Normal Window with vertical scroll "WS_SYSMENU", # Only System Menu and Close "WS_SYSMENU WS_MINIMIZE WS_MINIMIZEBOX", #System Menu, Close, a +nd Minimize "borderless rounded", #Borderless Window (no Menu) with a round +ed edge "borderless WS_BORDER", #Borderless Window (no Menu) with a sma +ll sharp edge ); my $index=shift || 0; #pass first argument to set what style of win +dow to show my $alpha=shift; #pass second argument to set transparency perc +ent (0-100) if(!defined $styleStrings[$index]){$index=0;} my $styleString=$styleStrings[$index]; my $MainWindow = new Win32::GUI::Window( -name => "MainWindow", -text => 'WinDemo.pl', -width => $MainWidth, -height => $MainHeight, -pos => [300, 100 ], -style => &setWindowStyle($styleString), -topmost=> 1, ); $MainWindow->AddButton( -text => "Close", -name => "MyButton", -pos => [10, 10 ], -size => [100,20], -tip => "Close this window", ); $MainWindow->AddTextfield( -text => $styleString, -name => "MyStyle", -pos => [10, 110 ], -size => [360,30], -readonly => 1, ); if(length($alpha)){&makeTransparent($MainWindow,$alpha);} $MainWindow->Show(); my $dialog=Win32::GUI::Dialog(); sub MyButton_Click{ return -1; } sub setWindowStyle{ my $str=shift; my %Style=( WS_BORDER => 0x800000, WS_CAPTION => 0xC00000, WS_CHILD => 0x40000000, WS_CLIPCHILDREN => 0x2000000, WS_CLIPSIBLINGS => 0x4000000, WS_DISABLED => 0x8000000, WS_DLGFRAME => 0x400000, WS_GROUP => 0x20000, WS_HSCROLL => 0x100000, WS_MAXIMIZE => 0x1000000, WS_MAXIMIZEBOX => 0x10000, WS_MINIMIZE => 0x20000000, WS_MINIMIZEBOX => 0x20000, WS_OVERLAPPED => 0x0, WS_POPUP => 0x80000000, WS_SYSMENU => 0x80000, WS_TABSTOP => 0x10000, WS_THICKFRAME => 0x40000, WS_VISIBLE => 0x10000000, WS_VSCROLL => 0x200000, ); $Style{WS_CHILDWINDOW} = $Style{WS_CHILD}; $Style{WS_ICONIC} = $Style{WS_MINIMIZE}; $Style{WS_OVERLAPPEDWINDOW} = $Style{WS_OVERLAPPED} || $Style{WS_C +APTION} || $Style{WS_SYSMENU} || $Style{WS_THICKFRAME} || $Style{WS_M +INIMIZEBOX} || $Style{WS_MAXIMIZEBOX}; $Style{WS_POPUPWINDOW} = $Style{WS_POPUP} || $Style{WS_BORDER} || +$Style{WS_SYSMENU}; $Style{WS_SIZEBOX} = $Style{WS_THICKFRAME}; $Style{WS_TILED} = $Style{WS_OVERLAPPED}; $Style{WS_TILEDWINDOW} = $Style{WS_OVERLAPPEDWINDOW}; #uppercase the string coming in my $ustr=uc($str); #if the string matches a value in the hash, return the hash value if(defined $Style{$ustr}){return $Style{$ustr};} #split the string up and do a little fuzzy logic to determine what + they want my @parts=split(/[\ \t\;\:\,]+/,$str); my $rval; foreach my $part (@parts){ if($part=~/^borderless$/is){$part="WS_POPUP";} elsif($part=~/vscroll/is){$part="WS_VSCROLL";} elsif($part=~/hscroll/is){$part="WS_HSCROLL";} elsif($part=~/rounded/is){$part="WS_THICKFRAME";} my $upart=uc($part); if(defined $Style{$upart}){ $rval=($rval | $Style{$upart}); } } return $rval; } sub makeTransparent{ #usage my $ck=makeTransparent($MainWindow,35); my $Window=shift || return 0; my $pcnt=shift || return 0; #Get handle of object passed in my $topHwnd=$Window->{-handle}; #Convert percent value to alpha value my $alpha=int(($pcnt/100)*255); #Set some varialves my $WS_EX_LAYERED = hex(80000); my $GWL_STYLE = (-16); my $GWL_EXSTYLE = (-20); my $LWA_COLORKEY = 1; my $LWA_ALPHA = 2; my $GetWindowLong = new Win32::API("user32","GetWindowLong",['N',' +I'],'N') || return $^E; my $SetWindowLong = new Win32::API("user32","SetWindowLong",['N',' +I','N'],'N') || return $^E; my $SetLayeredWindowAttributes = new Win32::API("user32","SetLayer +edWindowAttributes",['N','N','C','N'],'N') || return $^E; my $ck = $SetWindowLong->Call($topHwnd, $GWL_EXSTYLE, ($GetWindowL +ong->Call($topHwnd, $GWL_EXSTYLE) | $WS_EX_LAYERED)); my $alphaValue=chr($alpha); #0 to 255, where 0=transparent an +d 255=opaque $ck = $SetLayeredWindowAttributes->Call($topHwnd, 0, $alphaValue, +$LWA_ALPHA); return $ck; } exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32::GUI Window Styles and Transparency
by BrowserUk (Patriarch) on Jun 15, 2005 at 06:48 UTC | |
by slloyd (Hermit) on Jun 15, 2005 at 14:41 UTC | |
|
Re: Win32::GUI Window Styles and Transparency
by Anonymous Monk on Jun 15, 2005 at 11:35 UTC |