Click here to Skip to main content
Licence CPOL
First Posted 11 Jun 2002
Views 129,514
Bookmarked 48 times

Taskbar Sorter Utility

By | 11 Jun 2002 | Article
Utility to change order of icons in taskbar

Introduction

This utility allows you to change the order of items on your taskbar, by dragging them into position in a list.

Taskbar Sorter

The list shows all of your visible top-level windows. To move a window you simply drag the window's title into the order you wish the windows to appear, and click the Sort button.

To exit the utility, click on the Close button.

How it works

The application enumerates windows which are top-level (ie have no owner), and do not explicitly prevent themselves appearing in the taskbar. It adds each of the windows' titles to a drag list box (CDragListBox), along with the icon for the app. The user can then re-order the windows. When the user clicks the Sort button, each window is hidden using ShowWindow(SW_HIDE) and then re-shown (ShowWindow(SW_SHOW)) in the order of the list - top to bottom. This has the effect of the window being removed from the taskbar and then being re-added at the right-hand side.

Known limitations

Unfortunately there doesn't appear to be any way of interrogating the taskbar to determine, firstly which windows appear there, and secondly in what order they currently appear. This means that each time the utility is run the user needs to re-order each window from scratch.

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

License

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

About the Author

Paul Vickery

Software Developer (Senior)

United Kingdom United Kingdom

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 3 PinmemberSercanOzdemir8:02 7 Dec '11  
GeneralMy vote of 5 PinmemberPepsibot5:40 9 Sep '10  
GeneralDont work with "Group similar taskbar buttons" enabled. [modified] PinmemberAlejandro Pardo9:05 30 Dec '08  
AnswerRe: Dont work with "Group similar taskbar buttons" enabled. PinmemberPaul S. Vickery0:56 6 Jan '09  
GeneralRe: Dont work with "Group similar taskbar buttons" enabled. PinmemberAlejandro Pardo1:34 6 Jan '09  
Question.Net Code Pinmemberplury5:16 19 Feb '07  
GeneralDrag and Drop buttons on Taskbar and save order PinmemberThe Code Machine21:14 27 Jan '06  
GeneralRe: Drag and Drop buttons on Taskbar and save order PinmemberSa6ry7:06 3 Apr '06  
GeneralSave the Order PinmemberHerrDamit3:35 8 Aug '04  
GeneralRe: Save the Order Pinmemberkpatel1088:19 29 Oct '04  
GeneralRe: Save the Order PinmemberDTY8:45 15 Aug '05  
Hi, all:
 
First it is a good and very useful tool that will rescue to my "memory leak" especially when I have so many windows opened.
 
I have found the same need to save the order especially when I open new windows and would like to add them to the sorting list. If I close the sorter and reopen it, the new windows are added to the list but the order is changed based on the current z-ordering.
 
I have made a bit enhancement to the program to keep the original list (not to save it to a file anyway)intact but keep refreshing itself with newly added windows (appending them to the end of the list) when the "sort" button is clicked.
 
The code is working but I did not polish it. So it could cause some leak, etc.
 
The code is as follows.
 
In TaskbarSortDlg.cpp, function void CTaskbarSortDlg::OnOK()
 
=======================
void CTaskbarSortDlg::OnOK()
{
 
TRACE0("==== Fill list again\n");
 
int n;
 

 
// get each of the windows in the list, and hide, then re-show them
// that should leave them in the correct order in the taskbar
 
// GetCount(): CListBox function
 
int nNumItems = m_listWindows.GetCount();
 
TRACE1("==== nNumItems = %d\n", nNumItems);
 
HWND *ha;
char **la;
 
ha = new HWND[nNumItems];
la = new char*[nNumItems];
 
char *lpsz;
 

// copy list
for (n = 0; n < nNumItems; n++)
{
 
// save HWND
ha[n] = (HWND)m_listWindows.GetItemData(n);
 
// save titles
lpsz = new char[(m_listWindows.GetTextLen(n))];
m_listWindows.GetText(n, lpsz);
 
la[n] = lpsz;
 
TRACE1("==== lpsz = %s\n", lpsz);
 
}
 
// clean up
for (n = 0; n < nNumItems; n++)
{
TRACE1("====== delete %d\n", n);
int ret = m_listWindows.DeleteString(0);
// the index will change after the delete; so always delete the first one
//int ret = m_listWindows.DeleteString(n);
TRACE1("====== ret = %d\n", ret);
}
 
int nNumItems2 = m_listWindows.GetCount();
 

TRACE1("==== after clean up = %d\n", nNumItems2);
 
// refresh
 
FillList();
 
nNumItems2 = m_listWindows.GetCount();
 
TRACE1("==== after clean up = %d\n", nNumItems2);
 
// resort
 
int copy = 0;
 
for (n = 0; n < nNumItems; n++)
{
int m = m_listWindows.FindStringExact(-1, la[n]);
 
TRACE1("==== n = %d\n", n);
TRACE1("==== m = %d\n", m);
TRACE1("==== la[n] = %s\n", la[n]);
TRACE1("==== ha[n] = %d\n", ha[n]);
 
// if find same one, delete it and add to the end
// if not found then ignore it
// this way the final list would be new items + existing old items
 
if(m != LB_ERR && (HWND)m_listWindows.GetItemData(m) == ha[n])
{
int ret = m_listWindows.DeleteString(m);
// delete from list
TRACE1("==== ret = %d\n", ret);
 
int temp = m_listWindows.GetCount();
TRACE1("==== temp = %d\n", temp);
 

// add to end of list
m_listWindows.AddString(la[n]);
 
temp = m_listWindows.GetCount();
 
TRACE1("==== temp = %d\n", temp);
// should -1 because deleted first
m_listWindows.SetItemData(temp-1,(DWORD)ha[n]);
 
lpsz = new char[(m_listWindows.GetTextLen(temp-1))];
m_listWindows.GetText(temp-1, lpsz);
 
TRACE1("==== copied lpsz = %s\n", lpsz);
TRACE1("==== copied hwnd = %d\n", m_listWindows.GetItemData(temp-1));

//delete lpsz;
 
copy++;
}
else
{
TRACE0("=== New");
}
 
}
 
// move the new items to the end
 
int nNumItems1 = m_listWindows.GetCount();
 
TRACE1("==== nNumItems1 = %d\n", nNumItems1);
 
int diff = nNumItems1 - copy;
 
TRACE1("==== diff = %d\n", diff);
 
for (n = 0; n < diff; n++)
{
 
lpsz = new char[(m_listWindows.GetTextLen(0))];
m_listWindows.GetText(0, lpsz);
 
TRACE1("==== new lpsz = %s\n", lpsz);
 
m_listWindows.AddString(lpsz);
 
DWORD nhwnd = m_listWindows.GetItemData(0);
 
TRACE1("==== new hwnd = %d\n", nhwnd);
 
int temp = m_listWindows.GetCount();

TRACE1("==== temp = %d\n", temp);
 
// need to remember to -1 from count
m_listWindows.SetItemData(temp -1,(DWORD) nhwnd);
 
m_listWindows.DeleteString(0);
 
}
 

nNumItems = m_listWindows.GetCount();
 
TRACE1("==== nNumItems = %d\n", nNumItems);
 
for (n = 0; n < nNumItems; n++)
{
HWND hwnd = (HWND)m_listWindows.GetItemData(n);
TRACE1("==== hwnd = %d\n", hwnd);
::ShowWindow(hwnd, SW_HIDE);
::ShowWindow(hwnd, SW_SHOW);
}
// now hide and show self
ShowWindow(SW_HIDE);
ShowWindow(SW_SHOW);
SetForegroundWindow();
 

// don't close the dialog
//CDialog::OnOK();
}
 
==============================================
Thanks to Paul's good work and hope this helps, too.
 
David
 

 

 

GeneralRe: Save the Order PinmemberDTY6:08 22 Jun '06  
GeneralWindows XP Pinmemberwayside6:43 28 Jul '04  
GeneralIcon Color Improvement PinmemberAtlantys19:27 16 Jun '02  
GeneralJames would be tickled by this PinmemberNish - Native CPian19:05 12 Jun '02  
GeneralRe: James would be tickled by this PinmemberPaul S. Vickery22:31 12 Jun '02  
GeneralRe: James would be tickled by this PinmemberNish - Native CPian23:46 12 Jun '02  
GeneralPC Mag has similar utility PinmemberAnonymous14:31 12 Jun '02  
GeneralRe: PC Mag has similar utility PinmemberPaul S. Vickery22:34 12 Jun '02  
GeneralRe: PC Mag has similar utility Pinmembervikrant kpr3:56 13 Jul '07  
GeneralRe: PC Mag has similar utility PinmemberPhilippe Lhoste0:42 24 Jun '02  
GeneralRe: PC Mag has similar utility PinmemberSynetech16:34 12 Aug '06  
GeneralCool PinmemberRama Krishna3:24 12 Jun '02  
GeneralRe: Cool PinmemberAtlantys20:21 12 Jun '02  
GeneralRe: Cool PinmemberPaul S. Vickery22:37 12 Jun '02  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 12 Jun 2002
Article Copyright 2002 by Paul Vickery
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid