Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Cool API Function

 [1/10] from: tbrownell::l3technology::com at: 31-Jan-2003 4:34


Hello all, long time no post. I've been toying with a alpha transparency for an actual view window in Win2000, XP. This would allow funky shaped GUIs with the alpha color being an hole to the window beneath. It utilizes the SetLayeredWindowAttributes call in the user32.dll But I can't get it to work. Here's a link regarding the API call http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI /WindowsUserInterface/Windowing/Windows/WindowReference/WindowFunctions/SetL ayeredWindowAttributes.asp Theoretically, the following code should launch a copy of Notepad, and make it 50% transparent? rebol [] call "notepad" wait 1 ;Give Notepad a chance to load win-user: load/library %user32.dll find-window-by-class: make routine! [ ClassName [string!] WindowName [integer!] return: [integer!] ] win-user "FindWindowA" wahwnd: find-window-by-class "Notepad" 0 a: %/c/windows/system32/user32.dll b: load/library a c: "SetLayeredWindowAttributes" r: make routine! [ hwnd [integer!] crKey [integer!] bAlpha [integer!] dwFlags [integer!] ] b c note-hwnd: find-window-by-class "Notepad" 0 view layout [btn "test" [r note-hwnd 0 128 0] btn "quit" [quit] ] halt ;----End--- But alas, it doesn't work. Anyone have any ideas? Terry Brownell

 [2/10] from: jurgens:akcorp at: 31-Jan-2003 18:32


Well, I am not sure if everything else is correct about your code sample but it appears you are missing a necessary step: To have a dialog box come up as a translucent window, first create the dialog as usual. Then, on WM_INITDIALOG <http://msdn.microsoft.com/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/DialogBoxes/DialogBoxReference/DialogBoxMessages/WM_INITDIALOG.asp>, set the layered bit of the window's extended style and call SetLayeredWindowAttributes <http://msdn.microsoft.com/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Windows/WindowReference/WindowFunctions/SetLayeredWindowAttributes.asp> with the desired alpha value. The code might look like this: // Set WS_EX_LAYERED on this window SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED); // Make this window 70% alpha SetLayeredWindowAttributes(hwnd, 0, (255 * 70) / 100, LWA_ALPHA); (you can get to this doc by clicking the using layered windows link on the API page you provided a link to (and then click the same link on that page again to get to the above doc) HTH, Burt Terry Brownell wrote:

 [3/10] from: tbrownell::yahoo::com at: 2-Feb-2003 15:22

Cool API Function (Carl?)


The Windows SetLayeredWindowsAttributes API call would be an important addition to any /view GUI builder. Imagine funky /view skins like media player, winamp etc. All this is possible but.. I can't get my head around this... I'm not all that familiar with c structs etc. and trying to convert VB or C++ API sample code to Rebol is a bit confusing at times. Burt wrote; Well, I am not sure if everything else is correct about your code sample but it appears you are missing a necessary step: To have a dialog box come up as a translucent window, first create the dialog as usual. Then, on WM_INITDIALOG <http://msdn.microsoft.com/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/DialogBoxes/DialogBoxReference/DialogBoxMessages/WM_INITDIALOG.asp>, set the layered bit of the window's extended style and call SetLayeredWindowAttributes <http://msdn.microsoft.com/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Windows/WindowReference/WindowFunctions/SetLayeredWindowAttributes.asp> with the desired alpha value. The code might look like this: // Set WS_EX_LAYERED on this window SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED); // Make this window 70% alpha SetLayeredWindowAttributes(hwnd, 0, (255 * 70) / 100, LWA_ALPHA); (you can get to this doc by clicking the using layered windows link on the API page you provided a link to (and then click the same link on that page again to get to the above doc) HTH, Burt Terry Brownell wrote:

 [4/10] from: tbrownell::yahoo::com at: 3-Feb-2003 15:34

Cool API Function... Almost there.


Well, I've almost got it, the notepad window is popping up, but it's transparency is seriously messed up (on WinXP anyways) Any thoughts? Try this... rebol [] call "notepad" ;Path to Notepad. wait 1 ;Give Notepad a chance to load ;Load the library win-user: load/library %user32.dll ;Find the Windows by class name function find-window-by-class: make routine! [ ClassName [string!] WindowName [integer!] return: [integer!] ] win-user "FindWindowA" ;Set it to the varialbe hwnd: find-window-by-class "notepad" 0 GWL_EXSTYLE: -20 LWA_COLORKEY: 0 LWA_ALPHA: 128 WS_EX_LAYERED: 128 GetWinLongR: make routine![ hWnd [integer!] nIndex [integer!] return: [integer!] ]win-user "GetWindowLongA" setWinLongR: make routine![ hwnd [integer!] nIndex [integer!] return: [integer!] ]win-user "SetWindowLongA" SetAttributes: make routine! [ hwnd [integer!] crKey [integer!] bAlpha [integer!] dwFlags [integer!] ] win-user "SetLayeredWindowAttributes" SetWinLongR hwnd GWL_EXSTYLE 0 GetWinLongR hwnd GWL_EXSTYLE SetAttributes hwnd 95 128 0

 [5/10] from: tbrownell::yahoo::com at: 3-Feb-2003 16:06

P.S.


And how do you convert this...? LWA_COLORKEY = &H1 LWA_ALPHA = &H2

 [6/10] from: jurgens::akcorp::net at: 3-Feb-2003 16:40

Re: P.S. [was cool API function]


Try these: GWL_EXSTYLE: -20 LWA_COLORKEY: 1 LWA_ALPHA: 2 WS_EX_LAYERED: 524288 HTH, Burt Terry Brownell wrote:

 [7/10] from: amicom:sonic at: 4-Feb-2003 6:57

Re: Cool API Function... Almost there.


I suspect the API calls are different between Win98SE and XP. On Win98SE, I get the following:
>> call "c:\windows\notepad"
== 0
>> wait 1 >> win-user: load/library %user32.dll >> >> >> ;Find the Windows by class name function >> find-window-by-class: make routine! [
[ ClassName [string!] [ WindowName [integer!] [ return: [integer!] [ ] win-user "FindWindowA"
>> >> >> ;Set it to the varialbe >> hwnd: find-window-by-class "notepad" 0
== 4088
>> >> >> GWL_EXSTYLE: -20
== -20
>> LWA_COLORKEY: 0
== 0
>> LWA_ALPHA: 128
== 128
>> WS_EX_LAYERED: 128
== 128
>> >> >> >> GetWinLongR: make routine![
[ hWnd [integer!] [ nIndex [integer!] [ return: [integer!] [ ]win-user "GetWindowLongA"
>> >> >> setWinLongR: make routine![
[ hwnd [integer!] [ nIndex [integer!] [ return: [integer!] [ ]win-user "SetWindowLongA"
>> >> >> SetAttributes: make routine! [
[ hwnd [integer!] [ crKey [integer!] [ bAlpha [integer!] [ dwFlags [integer!] [ ] win-user "SetLayeredWindowAttributes" ** Access Error: Cannot open SetLayeredWindowAttributes ** Near: SetAttributes: make routine! [ hwnd [integer!] crKey [integer!] bAlpha [integer!] dwFlags [integer!] ] win-user
>> >> >> SetWinLongR hwnd GWL_EXSTYLE 0 GetWinLongR hwnd GWL_EXSTYLE
== 272
>> >> >> SetAttributes hwnd 95 128 0
** Script Error: SetAttributes has no value ** Near: SetAttributes hwnd 95 128 0

 [8/10] from: bry:itnisk at: 4-Feb-2003 17:52


>I suspect the API calls are different between Win98SE and XP. On
Win98SE,
>I get the following: >> call "c:\windows\notepad"
well at any rate the probable location of notepad is different. This is determinable by the system variable %windir%.

 [9/10] from: tbrownell:l3technology at: 3-Feb-2003 21:14


I only works with 2000 and XP. (That is, if it DID work ;) TBrownell

 [10/10] from: jurgens:akcorp at: 4-Feb-2003 11:45


That API call does not exist on Win98. The transparency functions only exist in Windows 2000 and XP. Best regards, Burt Jurgens [jurgens--akcorp--net] Bohdan or Rosemary Lechnowsky wrote: