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

Tagged as

Go to top

Caps Lock Status Tray Application

, 18 Jul 2010
Rate this:
Please Sign up or sign in to vote.
See the state of caps lock, num lock, scroll lock in the Windows tray

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

Share

About the Author

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


Comments and Discussions

 
GeneralIssues PinmemberKarpov 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: Issues Pinmemberron wilson29-Dec-10 15:05 
GeneralRe: Issues PinmemberKarpov Andrey29-Dec-10 19:52 
GeneralTip/Trick... PinmvpDave Kreskowiak17-Jul-10 18:21 
GeneralRe: Tip/Trick... Pinmemberron wilson18-Jul-10 2:41 
GeneralRe: Tip/Trick... PinmvpDave Kreskowiak18-Jul-10 9:06 
GeneralRe: Tip/Trick... Pinmemberron wilson18-Jul-10 9:30 

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.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 18 Jul 2010
Article Copyright 2010 by ron wilson
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid