473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to set opacity of a window?

Hi, I want to set opacity of a window.
Expand|Select|Wrap|Line Numbers
  1. public const int GWL_EXSTYLE = -20;
  2. public const int WS_EX_LAYERED = 0x80000;
  3. public const int LWA_ALPHA = 0x2;
  4. public const int LWA_COLORKEY = 0x1;
  5. static void Main(string[] args){
  6. IntPtr Handle = Process.GetCurrentProcess().MainWindowHandle;
  7. Console.WriteLine(SetWindowLong(Handle,GWL_EXSTYLE,(int)GetWindowLong(Handle, GWL_EXSTYLE) ^ WS_EX_LAYERED));
  8. Console.WriteLine(Marshal.GetLastWin32Error());
  9. Console.WriteLine(SetLayeredWindowAttributes(Handle,0,64,LWA_ALPHA));
  10. Console.WriteLine(Marshal.GetLastWin32Error());
  11. Console.ReadKey();
  12. }
  13.  
And this is output:
0 (SetWindowLong() failed)
1008 (ERROR_NO_TOKEN)
False (SetLayeredWindowAttributes() failed)
87 (ERROR_INVALID_PARAMETER)

I tried to find a solution, but I didn't find anything, please help me. (Of course I imported functions from user32.dll, and sorry if I made mistakes in text, I'm still learning English)
Oct 21 '10 #1
4 5127
Plater
7,872 Expert 4TB
Couln't you just use this line:
this.Opacity = .5;

That sets my window to 50% opacity
Oct 22 '10 #2
Sorry, I didn't formulate what I need. I want to set opacity of variable "Handle" into which I will insert window handle later. Now it's set to the current process for testing.
Oct 22 '10 #3
Plater
7,872 Expert 4TB
Ahhh, looking back at your code...
Do you even HAVE a handle to work with? It doesn't look like you have any forms open at the time of running the code?

EDIT:
I just ran it and the line: Process.GetCurrentProcess().MainWindowHandle;
always returned a zero, even when I had a main window.
I was successfull with this though:

Expand|Select|Wrap|Line Numbers
  1. IntPtr Handle = this.Handle;
  2. Int32 oldValue = GetWindowLong(Handle, GWL_EXSTYLE);
  3. Int32 AlsoOldValue = SetWindowLong(Handle, GWL_EXSTYLE, oldValue | WS_EX_LAYERED);
  4. bool result=SetLayeredWindowAttributes(Handle, 0, 255 / 2, LWA_ALPHA);
  5.  
It also worked when I used the Process object to get the MainWindowHandle of a different process and set THAT window's opacity
Oct 25 '10 #4
Thanks, it works! I will try to make fade-in and fade-out effect :).
Oct 26 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tom | last post by:
I have an MDI application where I allow the user to set the opacity of the main MDI form (thereby also setting the opacity for any child forms). This works great; however, I notice that if I set...
3
by: Wolfgang | last post by:
Is it possible in VB .NET to create a window that is always on top of all other windows, while at the same time being partially transparent? As example that this kind of thing is possible, the...
4
by: beaker | last post by:
Hello, Is there a way to alter the opacity of an MDI child window? I've tried setting the Opacity property, but it has no effect on the children (fine for the parent though). (I want to...
2
by: Peter Michaux | last post by:
Hi, I've been trying to get opacity reporting working in IE 5.5 but the Microsoft documentation does seem to work as I interpret it even though this documentation page seems have been written...
2
by: wreed06 | last post by:
Hello, I have 2 problems. In my webpage, I have a dropdown list with a button that takes the user to a popup window specific to the option. I am using Firefox 2.0.0.13. I have successfully...
1
by: soms2m | last post by:
HELLO ALL, I want to fill the parent window height with respect to the sub window height which is loading using ajax (mootools). For example if the parent window height is normal and the loading...
6
by: Prisoner at War | last post by:
Okay, no such thing, apparently, in the DOM.... How am I supposed to tell JavaScript "turn the whole page opaque"? Is there a "JavaScript/CSS dictionary" and a "JavaScript/CSS grammar" about??...
8
by: Sin Jeong-hun | last post by:
With Windows Forms application, just setting the opacity to 0.5 gave me a 50% opaque normal styled (with the title bar, familiar three buttons, borders and resizable) window. Did the same thing to...
1
by: marciojersey | last post by:
Hi everyone. I'm having a problem with form opacity in my c# application. I have a window with a vrml viewer com control and whenever the window goes into layered mode, the vrml viewer is rendered...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.