Hi!
How to change the transparency of a window?
and
How to make a window stay allways on top?
thanx for any help.
Hi!
How to change the transparency of a window?
and
How to make a window stay allways on top?
thanx for any help.
Last edited by geek@02; 01-23-2007 at 07:47 AM.
GameJolt: https://gamejolt.com/@KasunL
Game Development Youtube: https://is.gd/XyhYoP
Amateur IT Blog: http://everything-geeky.blogspot.com/
(and, sorry for my amateur English)
Here's some code from Visual C++ 6.0 that works:
This removes the window border (makes it immovable) and expands to fill up the entire screen. Hope this might help you.Code:BOOL CFullScrDlgDlg::OnInitDialog() { CDialog::OnInitDialog(); //... int cx, cy; HDC dc = ::GetDC(NULL); cx = GetDeviceCaps(dc,HORZRES) + GetSystemMetrics(SM_CXBORDER); cy = GetDeviceCaps(dc,VERTRES) + GetSystemMetrics(SM_CYBORDER); ::ReleaseDC(0,dc); // Remove caption and border SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) & (~(WS_CAPTION | WS_BORDER))); // Put window on top and expand it to fill screen ::SetWindowPos(m_hWnd, HWND_TOPMOST, -(GetSystemMetrics(SM_CXBORDER)+1), -(GetSystemMetrics(SM_CYBORDER)+1), cx+1,cy+1, SWP_NOZORDER); //... return TRUE; }
simguy, That is certainly not what he's looking for.
To change the transparency of the window, it must have WS_EX_LAYERED extended style. You can add this style to to your CreateWindowEx's first parameter or you could do this:
Now you can change it's transparency using SetLayeredWindowAttributes:Code:SetWindowLong(hwnd,GWL_EXSTYLE,GetWindowLong(hwnd,GWL_EXSTYLE)|WS_EX_LAYERED);
150 is the transparency, which may be anything from 0 (totally transparent) to 255 (opaque).Code:SetLayeredWindowAttributes(hwnd,0,150,LWA_ALPHA);
There are multiple ways to make your window stay on top. You can use the window extended style WS_EX_TOPMOST or you can do it with:
Code:SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE);
"The Internet treats censorship as damage and routes around it." - John Gilmore
Thx max for the examples and thx anyways simguy for the post.
However, my compiler doesn't recognize SetLayeredWindowAttributes() function or WS_EX_LAYERED style - must be my rather old sdk (2003). Is there another way to do it by any chance?
GameJolt: https://gamejolt.com/@KasunL
Game Development Youtube: https://is.gd/XyhYoP
Amateur IT Blog: http://everything-geeky.blogspot.com/
(and, sorry for my amateur English)
You can replace WS_EX_LAYERED with 0x80000 and you can import SetLayeredWindowAttributes something like this:
And then you should be able to use SetLayeredWindowAttributes(). I am not sure if it works, I can't test it at the moment.Code://at the beginning of the file... typedef DWORD (WINAPI *PSLWA)(HWND, DWORD, BYTE, DWORD); PSLWA SetLayeredWindowAttributes; //in WinMain, before creating the window HMODULE hDLL = LoadLibrary ("user32"); SetLayeredWindowAttributes=(PSLWA)GetProcAddress(hDLL,"SetLayeredWindowAttributes");
"The Internet treats censorship as damage and routes around it." - John Gilmore
Your should update your psdk to a more recent version but that isn't the issue here. Note that SetLayeredWindowAttributes requires a minimum operating system of windows 2000 so, you must define _WIN32_WINNT to a suitable value in order for code which uses it to compile - see Using the Windows Headers for details.Originally Posted by geek@02
The approach described by maxorator gives an opportunity, with suitable checks, for the program using such code to sidestep the absence of SetLayeredWindowAttributes in user32.dll on pre-win2k systems.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.