Click here to Skip to main content
15,741,752 members
Articles / Desktop Programming / MFC
Posted 30 Apr 2002


24 bookmarked

OnTop Utility

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
11 Jun 2002CPOL
Utility to make selected windows remain on-top of others


Have you ever wanted to make an application float above others? No? Then this utility is not for you. For those of you that have, this utility will allow you to do just that.

On running the utility, an icon will appear in your taskbar. Clicking or right-clicking on it will produce a menu, similar to the following:

Sample Image - OnTop.jpg

This menu lists all of your visible top-level windows. Any windows that are already floating are shown ticked, while all others are shown un-ticked. Clicking on a window name will toggle its top-most state.

To exit the utility, click on Exit on the menu.

That's all there is to it - have fun!


Version 3.02 - 02 May 2002
Made sure menu closes when user clicks outside of it

Version 3.01 - 01 May 2002
First (public) version

Revision History

01 May 2002 - Originally Moved
12 Jun 2002 - Some Re-Formating


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior)
United Kingdom United Kingdom
Originally from an electronics background, I moved into software in 1996, partly as a result of being made redundant, and partly because I was very much enjoying the small amount of coding (in-at-the-deep-end-C) that I had been doing!

I swiftly moved from C to C++, and learned MFC, and then went on to real-time C on Unix. After this I moved to the company for which I currently work, which specialises in Configuration Management software, and currently program mainly in C/C++, for Windows. I have been gradually moving their legacy C code over to use C++ (with STL, MFC, ATL, and WTL). I have pulled in other technologies (Java, C#, VB, COM, SOAP) where appropriate, especially when integrating with third-party products.

In addition to that, I have overseen the technical side of the company website (ASP, VBScript, JavaScript, HTML, CSS), and have also worked closely with colleagues working on other products (Web-based, C#, ASP.NET, SQL, etc).

For developing, I mainly use Visual Studio 2010, along with an in-house-designed editor based on Andrei Stcherbatchenko's syntax parsing classes, and various (mostly freeware) tools. For website design, I use Dreaweaver CS3.

When not developing software, I enjoy listening to and playing music, playing electric and acoustic guitars and mandolin.

Comments and Discussions

GeneralOnTop closes by itself Pin
Doooodles25-Oct-05 18:06
Doooodles25-Oct-05 18:06 
GeneralOnTop Outlook Reminder Pin
Steve Zeile15-Aug-05 13:43
Steve Zeile15-Aug-05 13:43 
GeneralOnTop Utility - funny title Pin
Jim Crafton1-Apr-04 15:33
Jim Crafton1-Apr-04 15:33 
GeneralThanks! Pin
serup14-Jan-04 23:51
serup14-Jan-04 23:51 
GeneralRe: Thanks! Pin
Paul Vickery15-Jan-04 0:17
professionalPaul Vickery15-Jan-04 0:17 
GeneralIE Plugins. Pin
hien_ng807-Jan-03 16:44
hien_ng807-Jan-03 16:44 
Generaladding functions taskbar buttons Pin
Anthony Winters5-Jul-02 14:14
Anthony Winters5-Jul-02 14:14 
GeneralRe: adding functions taskbar buttons Pin
Paul Vickery8-Jul-02 0:22
professionalPaul Vickery8-Jul-02 0:22 
There are two ways to get, and change, the system menu for an app:

1. Use CWnd::GetSystemMenu(FALSE), and modify the returned menu;

2. Add an OnInitPopupMenu handler, and, if the bSysMenu param is TRUE, the CMenu* passed in will be the control menu, so you can modify it.

The second method is fine for greying items, but not good for adding or removing items as the changes persist until the control menu is reset back to the standard menu.

If you want to only show a modified menu some of the time, then use GetSystemMenu(FALSE), which will give you a copy of the current control menu, which you can then modify. When you want to revert back to the standard control menu call GetSystemMenu(TRUE).

If you want the new items on the menu all the time, (ie not just when minimised, and on the 'normal' sys menu, and caption right-click) then use GetSystemMenu(FALSE) to get the menu after creating your main window, and modify it, but don't forget that if anything calls GetSystemMenu(TRUE) you will lose your modifications.

If you want to only display a modified menu when you are minimised, then you could override OnSize, and if nType is SIZE_MINIMIZED you can use GetSystemMenu(FALSE) and modify the returned menu, else call GetSystemMenu(TRUE) to cause it to revert to the standard menu.

(Using these calls in OnInitMenuPopup or OnInitMenu gives strange results, as the control menu has already been 'grabbed' ready for display.)

You can use IsIconic() to determine if your app is minimised, but if you want to know whether the user has right-clicked on the taskbar icon you will have to do something like:
CPoint pt;
CRect rc;
if (! rc.PtInRect(pt))
	TRACE("User clicked on taskbar icon\n");
	TRACE("User clicked on caption or sys menu\n");
I hope this gives you enough ideas to continue!

"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
GeneralRe: adding functions taskbar buttons Pin
Anthony Winters8-Jul-02 6:32
Anthony Winters8-Jul-02 6:32 
GeneralRe: adding functions taskbar buttons Pin
Paul Vickery8-Jul-02 23:27
professionalPaul Vickery8-Jul-02 23:27 
GeneralRe: adding functions taskbar buttons Pin
Anthony Winters16-Jul-02 12:51
Anthony Winters16-Jul-02 12:51 
QuestionXP? Pin
Jason Troitsky (was Hattingh)14-Jun-02 2:22
Jason Troitsky (was Hattingh)14-Jun-02 2:22 
AnswerRe: XP? Pin
Paul Vickery25-Jun-02 23:48
professionalPaul Vickery25-Jun-02 23:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.