Click here to Skip to main content
Click here to Skip to main content

Caps Lock Status Tray Application

By , 18 Jul 2010
 

Introduction

This application displays the current state of the CAPS lock, NUM lock, and SCROLL lock in a single Windows tray icon.

Background

Recently I bought a wireless keyboard that lacks any LED indication for the state of the CAPS lock and NUM lock. This is infuriatingly inconvenient, so I whipped up this little application using the Win32++ framework by David Nash.

Using the Code

The included solution and project are for Visual Studio 2008. The source should work in any development environment for Windows.

The Win32++ framework is refreshingly simple compared to MFC and a delight to work with. This application is actually a modified sample from among the dozens of working samples that come with Win32++. (I actually found it refreshing that all the samples 'just worked' right out of the zip file - with project and solution files for a handful of development environments - a rare gem in the open source world.)

The only thing I had to figure out for myself was how to get the main form to start up in the hidden state and show the tray icon without any user interaction. The trick is to set the creation style to WS_ICONIC and the extended style to something that doesn't minimize to the task bar, like WS_EX_TOOLWINDOW.

void CView::PreCreate( CREATESTRUCT& cs )
{
	// This function will be called automatically by Create. It provides an
	// opportunity to set various window parameters prior to window creation.
	// You are not required to set these parameters, any parameters which
	// aren't specified are set to reasonable defaults.

	// Set some optional parameters for the window
	cs.dwExStyle = WS_EX_TOOLWINDOW;       // Extended style
	cs.style = WS_ICONIC;                  // Start up minimized
	cs.hMenu =  LoadMenu( GetApp()->GetResourceHandle(), 
			MAKEINTRESOURCE( IDM_MINIMIZED ) );
}

Points of Interest

Feel free to improve the icons; I am not an artist. Enjoy!

History

  • July 2010 - Initial submission

License

This article, along with any associated source code and files, is licensed under The MIT License

About the Author

ron wilson
Software Developer (Senior) Harris Corporation
United States United States
Member
I'm your huckleberry.
 
Check out more beards here.


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.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralIssuesmemberKarpov Andrey27 Dec '10 - 20:30 
I've tested the PVS-Studio 4.0 analyzer with some of the projects from Codeproject. While analyzing this project I've found some mistakes and decided to mention it. Hope it will come in handy.
 
The general-purpose analyzer generated these warnings (see detailed descriptions at the links below):
 
V519 The 'cx' object is assigned values twice successively. Perhaps this is a mistake. capstray wincore.h 256
V519 The 'cx' object is assigned values twice successively. Perhaps this is a mistake. capstray wincore.h 257
 
class CSize : public SIZE
{
  ...
  CSize(POINT pt) { cx = pt.x;  cx = pt.y; }
  CSize(DWORD dw)
  { cx = (short)LOWORD(dw); cx = (short)HIWORD(dw); }
  ...
}
 
Both V519 warning messages apply to double use of 'cx' because of misprints. The correct version is:
 
CSize(POINT pt) { cx = pt.x;  cy = pt.y; }
CSize(DWORD dw)
  { cx = (short)LOWORD(dw); cy = (short)HIWORD(dw); }
 
-----
 
V527 It is odd that the L'\0' value is assigned to 'wchar_t' type pointer. Probably meant: *m_OldStatus [ i ] = L'\0'. capstray frame.h 1386
 
LPCTSTR m_OldStatus[3];
...
inline CFrame::CFrame() ...
{
  ...
  for (int i = 0 ; i < 3 ; ++i)
    m_OldStatus[i] = _T('\0');
 
  ...
}
 
The analyzer produced false alarm. The pointers were meant to be nullified in the constructor. But '0' represented as "_T('\0')" is misleading. The clearer representation is:
 
for (int i = 0 ; i < 3 ; ++i)
  m_OldStatus[i] = NULL;

GeneralRe: Issuesmemberron wilson29 Dec '10 - 15:05 
thanks for the feedback. both of these findings are part of the win32xx library. the first is fixed in recent versions and the second is a false positive. it is arguable that assigning to _T('\0') is clearer than NULL because the object is a string pointer, but to each his own.
GeneralRe: IssuesmemberKarpov Andrey29 Dec '10 - 19:52 
Yes, this is fixed in recent version. But I am found another suspicious piece of code in Win32++ library. Smile | :)
GeneralTip/Trick...mvpDave Kreskowiak17 Jul '10 - 18:21 
This is a tip/trick, not an article.

A guide to posting questions on CodeProject[^]



Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007, 2008
But no longer in 2009...




GeneralRe: Tip/Trick...memberron wilson18 Jul '10 - 2:41 
i was not aware that you could post a zip of source code in a tip/trick. can that be done? in my opinion the purposes of this article are to provide a useful tool and demonstrate the simplicity of the Win32++ framework, which requires a full zip of source code, not snippets.
GeneralRe: Tip/Trick...mvpDave Kreskowiak18 Jul '10 - 9:06 
ron wilson wrote:
are to provide a useful tool and demonstrate the simplicity of the Win32++ framework

 
Which you've done ever so breifly. This isn't an article until you explore the library in FAR greater detail than you've done in this text. For example, the concepts behind the library, how it contrasts with MFC, more use cases and examples, maybe some side-by-side comparisons of equivilent code, ...

A guide to posting questions on CodeProject[^]



Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007, 2008
But no longer in 2009...




GeneralRe: Tip/Trick...memberron wilson18 Jul '10 - 9:30 
thank you for the valuable gift of constructive feedback. i'll work harder to prepare more detailed articles in the future.

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 18 Jul 2010
Article Copyright 2010 by ron wilson
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid