windows application showing behind the taskbar on vista - windows

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);

Related

How to create a usual non-resizible window with thick border (MFC or WinAPI)

I want to create a window with the following properties:
Thick border ("double border" as described in MSDN)
Not resizable
Icon in the title
Close button in the title
It sounds so simple and we can find this kind of windows everywhere in Windows. But as soon as I disable ability to resize my window I also lose the thick border. Here is the illustration of my problem:
The height of my test window's caption bar is slightly less than that of a Shell property dialog, but I would like it to be the same height.
I have tried to use WinSpy and copy all styles from Explorer's window to mine, but this did not help.
I don't know what's going on under the hood, but I found two solutions:
Switch to the newer Platform Toolset (which means drop support of Windows XP)
Disable resizing by writing custom WM_NCHITTEST handler
The second option is quite simple and I do not want drop Windows XP support for a silly reason. Job is done:
LRESULT CListEditorDlg::OnNcHitTest(CPoint point)
{
LRESULT retVal = CDialog::OnNcHitTest(point);
switch (retVal)
{
case HTBOTTOM:
case HTBOTTOMLEFT:
case HTBOTTOMRIGHT:
case HTLEFT:
case HTRIGHT:
case HTTOP:
case HTTOPLEFT:
case HTTOPRIGHT:
retVal = HTBORDER;
}
return retVal;
}

How do I position a notification (tray) icon context menu on Windows XP?

I'm using C++ and Win32.
I want my context menu and settings dialog to show up near the tray icon. I think I need the icon's coordinates to do that.
Shell_NotifyIconGetRect wasn't available until Windows 7.
WM_CONTEXTMENU is available starting in Win2k, but only provides coordinates in wParam as of Vista (and when specifying NOTIFYICON_VERSION_4).
The correct way of solving this is to either use the mouse message coordinates, or GetMessagePos for other messages.
Retrieving the click coordinates with GetCursorPos works well:
// Inside WndProc's switch(message)...
case WM_APP_NOTIFYCALLBACK:
switch (LOWORD(lParam))
{
case WM_CONTEXTMENU: // XP and later
{
POINT pt = {};
if( GetCursorPos(&pt) )
ShowContextMenu(hWnd, pt, iStatus);
}
break;
// ...
}
// ...
To display the menu, all you need is the coords passed to you by WM_CONTEXTMENU or WM_RBUTTONUP (These are of course not normal messages, but something generated by the tray and you therefore don't have to deal with mouse vs keyboard)
Shell_NotifyIconGetRect is used if you want to display a toast (custom window) near the tray. On < 7 you can emulate it with findwindow by looking for the TrayNotifyWnd class with Shell_TrayWnd as the parent

win32 DialogBox app: how to make the dialog box hidden on startup?

I have a win32 app which uses DialogBox() to display its main window.
I now want to start this app up with the dialog box invisible, and later set it visible with
SetWindowPos(hDlg, HWND_TOPMOST, ...
Unfortunately
http://msdn.microsoft.com/en-us/library/ms645452(VS.85).aspx
The function displays the dialog box (regardless of whether the template specifies the WS_VISIBLE style)
... it seems that there's no way of doing this using DialogBox().
I could add a call to
SetWindowPos(hDlg, HWND_NOTOPMOST...
in my dialog procedure in the WM_INITDIALOG handler.
... but I'm concerned that under heavy system loading the dialog box will briefly appear then disappear, giving an ugly flicker effect.
Is there a way of creating my dialog box via DialogBox() without showing it?
ShowWindow(Hwnd, SW_HIDE);
i think it will work.
http://www.winprog.org/tutorial/modeless_dialogs.html
I had some success with this technique
void CMyDlg::OnWindowPosChanging(WINDOWPOS* lpWndPos)
{
// hide dialog
lpWndPos->flags &= ~SWP_SHOWWINDOW;
CDialog::OnWindowPosChanging(lpWndPos);
}
from here

Detect application windows

I use CBT Windows Hook to detect window creation/deletion/min-max/move-size events.
I works well, but I need to filter whose events coming from normal widgets. Practically I need to being notified by CBT hook only for those windows that the user consider windows.
The problem that I'm facing make me mad, since I continuosly get spurious events even if I filter window as follow:
BOOL FilterWindowHandle(HWND hwnd)
{
// Filtered window having WS_CHILDWINDOW style
if ((GetWindowLongPtr(hwnd, GWL_STYLE) & WS_CHILDWINDOW) != 0)
return (TRUE);
// Filtered window not having WS_CAPTION style
if ((GetWindowLongPtr(hwnd, GWL_STYLE) & WS_CAPTION) == 0)
return (TRUE);
// Not filtered
return (FALSE);
}
Those spurious events comes from shadow effects, menus and everything displayed on screen.
Is there a robust method to filter real windows from its children?
I avoid the test of WS_BORDER or similar, since some applications could create their main window without border... or am I wrong?
A good fit for "things the user considers windows" is the set of windows displayed in the Alt-Tab list (or on the Taskbar).
This OldNewThing article explains the rules (although the rules are not fixed or guaranteed to remain the same):
Which windows appear in the Alt+Tab list?
The general rule is:
For each visible window, walk up its
owner chain until you find the root
owner. Then walk back down the visible
last active popup chain until you find
a visible window. If you're back to
where you're started, then put the
window in the Alt+Tab list.
This can be overridden with explicit window styles:
A window with the WS_EX_TOOLWINDOW
extended style is treated as if it
weren't visible, even if it is. A
window with the WS_EX_APPWINDOW
extended style is treated as if it has
no owner, even if it does.
See the full OldNewThing post which those two quotes come from for more detail.
A useful criteria that I've used in the past is to test whether the window is a top-level window, i.e. its parent is NULL.

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