How can I change the taskbar icon using XIconifyWindow? - x11

I am programming in Linux and am using X11 for my desktop. I would like to change the images of a minimized window in the task bar.
I am using Fluxbox.
I am currently using XIconifyWindow when the user clicks to minimize a window.
How can I control the little square icon in the taskbar when the user minimized it?
Thanks.
Thank you for your help. The code I'm using to minimize looks something like this:
void minWin(Window window, bool yes) const
{
if(yes)
{
XIconifyWindow(display, window, DefaultScreen(display));
}else{
XMapWindow(display, window);
}
}
So how would I put in some code to set the icon depending on some property?
Like
if myProp == "green" set green icon
else set red icon

use _NET_WM_ICON property of toplevel window

Related

Toggle window visibility on tray icon click using WinAPI

How can I bring a window to the top if not there, and close it otherwise, when the tray icon is clicked, using the Windows API? That is, very similar to what the taskbar icon does. By bring to the top I mean fully visible to the user.
I cannot find a way to tell whether the window is on top or not, because when the tray icon is clicked, the taskbar is always on top. I tried inspecting the Z-order of the windows but it looks inconsistent. For example, when the application window is on top and tray icon is clicked, I would expect a constant number of taskbar/tray windows to be brought to top, and the window immediately following them being the one that was on top. But that's not the case, it seems.
I could mostly implement it, the problem is that the toggle doesn't care whether the window is open and fully visible to the user (on top). When the tray icon is clicked and the window is currently closed, it is opened and brought to top correctly. When the window is open and on top, it is also closed correctly. However, when the window is open but not on top, it will be closed instead of being brought to foreground.
To expand upon what Hans Passant said:
"On top" is not important, since some windows can be always on top; it's whether the window is the foreground window or not that you're concerned with.
Use GetForegroundWindow() to see if your window is the foreground window and if not, SetForegroundWindow() to make it so.
Thanks to Mike Gelfand who solved the problem! The following function will return:
-1 when window is closed
0 when window is fully visible
1 or above when window is open but not fully visible
int GetMyWindowLevel(HWND myWindow) {
WINDOWINFO myWindowInfo;
myWindowInfo.cbSize = sizeof(myWindowInfo);
if (!GetWindowInfo(myWindow, &myWindowInfo))
return -1;
int myWindowLevel = -1;
HWND currentWindow = GetTopWindow(NULL);
for (; currentWindow != NULL;
currentWindow = GetNextWindow(currentWindow, GW_HWNDNEXT)) {
WINDOWINFO currentWindowInfo;
currentWindowInfo.cbSize = sizeof(currentWindowInfo);
if (!GetWindowInfo(currentWindow, &currentWindowInfo))
continue;
if ((currentWindowInfo.dwExStyle & WS_EX_TOPMOST) !=
(myWindowInfo.dwExStyle & WS_EX_TOPMOST) ||
(currentWindowInfo.dwStyle & WS_POPUP) != 0)
continue;
++myWindowLevel;
if (currentWindow == myWindow)
break;
}
return currentWindow == myWindow ? myWindowLevel : -1;
}

I want to show my window when the keyboard shortcut - show desktop has invoked,is there any function can get this?

I want to show my window when the keyboard shortcut - show desktop has invoked,is there any function can get this?
I display this window under a custom status bar item. So I want to do this.
I have solve this by myself,I think maybe you need this sometime,just set window self.window.collectionBehavior = NSWindowCollectionBehaviorStationary;
window will display all the time.

windows application showing behind the taskbar on vista

I have an MFC application. In my application if I run on Windows XP it's working fine. But if I run in Windows Vista the MFC dialog hides behind the taskbar.
bool bHide=true;
CRect rectWorkArea = CRect(0,0,0,0);
CRect rectTaskBar = CRect(0,0,0,0);
CWnd* pWnd = CWnd::FindWindow("Shell_TrayWnd", "");
pWnd->ShowWindow(SW_SHOW);
if( bHide )
{ // Code to Hide the System Task Bar
SystemParametersInfo(SPI_GETWORKAREA,0,(LPVOID)&rectWorkArea,0);
if( pWnd )
{
pWnd->GetWindowRect(rectTaskBar);
// rectWorkArea.bottom -= rectTaskBar.Height();
rectWorkArea.bottom += rectTaskBar.Height();//-----to hide taskbar
SystemParametersInfo(SPI_SETWORKAREA,0,(LPVOID)&rectWorkArea,0);
// pWnd->ShowWindow(SW_SHOW);
pWnd->ShowWindow(SW_HIDE); //--to hide taskbar
}
}
I used this code but it hides the taskbar. But I want to show the application above the task bar.
You don't own the taskbar, so you are not supposed to hide it. You have the option to auto-minimize it by the way. You have another option of using secondary monitor without taskbar there.
On the primary monitor your app is given work area, you are being able to locate (judging from the code snippet provided above). It is the best to position your window within this area without interfering with the taskbar, whether it is above or beyond.
If you still feel like making it more like a competition "who is on top" with the task bar, you might want to take a look at SetWindowPos API and window Z-Order.
finally i found the solution , what we want to do is we should add the below code in our oninitdialog,
SetWindowPos(&this->wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
the above line is enough to show the mfc dialog on above the taskbar . but sometimes the focus of the dialog get changed looks hanged(no response in dialog) the application.if it occurs put the below code.
SetWindowPos(&this->wndBottom,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

How can I force Aero to draw a borderless window as if it were active, even if it's not?

I'd like to have the same effect as the windows 7 taskbar.
I've looked in this question:
Keep Window Looking Active
It works great but only if the window has a non-client area.
My window is border-less and the content of it (just a black background) is rendered as it is inactive, no matter what I do.
I've set my window flags just as Windows 7 taskbar but it didn't help.
My only thought at the moment is to draw it with borders and just clip them, is there a better way to achieve what I want?
EDIT 1:
Clipping didn't work, after clipping the borders the window content was rendered as inactive window.
How the hell does windows 7 task-bar works then?
EDIT2:
Adding some photos to explain myself better, The following window content is a black background.
That's an inactive window (the content is rendered kinda dark):
That's an active window:
If the window has no client area the content is always rendered as inactive window however the windows Taskbar is always rendered as active window and it doesn't have any NC area (at least according to spy++). That's what I'm trying to mimic.
EDIT3:
Sharing my recent discoveries.
explorer.exe main window is frameless and has the following flags:
I dived into the explorer's process dwmapi.dll exported functions:
it uses DwmEnableBlurBehindWindow, just as I do.
I've checked the undocumented ordinal functions and none of them is related to rendering the aero glass as active.
Could it be the DWM rules don't apply to explorer?
Tricky one..
set the NCRenderingPolicy to Enabled with the "DwmSetWindowAttribute" API.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa969524(v=vs.85).aspx
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
[Flags]
public enum DwmWindowAttribute
{
NCRenderingEnabled = 1,
NCRenderingPolicy,
TransitionsForceDisabled,
AllowNCPaint,
CaptionButtonBounds,
NonClientRtlLayout,
ForceIconicRepresentation,
Flip3DPolicy,
ExtendedFrameBounds,
HasIconicBitmap,
DisallowPeek,
ExcludedFromPeek,
Last
}
[Flags]
public enum DwmNCRenderingPolicy
{
UseWindowStyle,
Disabled,
Enabled,
Last
}
public static bool SetNCRenderingActive(IntPtr Handle)
{
int renderPolicy = (int)DwmNCRenderingPolicy.Enabled;
return (DwmSetWindowAttribute(Handle, (int)DwmWindowAttribute.NCRenderingPolicy, ref renderPolicy, sizeof(int) ) == 0);
}

How to create full screen window with MFC?

I want to create full screen topmost (screen saver) window with MFC? How to create such full screen window in MFC? I tried to create win32 application and i am able to create fullscreen top most window but i want to create using MFC so later i can put different MFC controls on that window?
Please help me.
Thanks,
Jim.
I think removing the border from the dialog resource and showing the window as maximized (ShowWindow(SW_SHOWMAXIMIZED)) should do the job.
As for topmost use the System Modal style in the dialog resource.
I do it with a Dialog Box app. In the resource editor properties for the dialog resource, set Border=None and Title Bar=False to eliminate all border elements. In OnInitDialog, use the following to resize the dialog to the entire desktop:
CRect rcDesktop;
rcDesktop.left = GetSystemMetrics(SM_XVIRTUALSCREEN);
rcDesktop.right = rcDesktop.left + GetSystemMetrics(SM_CXVIRTUALSCREEN);
rcDesktop.top = GetSystemMetrics(SM_YVIRTUALSCREEN);
rcDesktop.bottom = rcDesktop.top + GetSystemMetrics(SM_CYVIRTUALSCREEN);
MoveWindow(rcDesktop, FALSE);
This code works on multiple monitors, unlike maximizing the window.
No need to worry about making the window topmost, Windows will display it on a dedicated desktop with no other windows present.
You should be able to adapt the example code here to do what you want:
MSDN: Initializing a dialog box

Resources