The Coolest Parts of Windows API
Posted
by Andreas Rejbrand
on Stack Overflow
See other posts from Stack Overflow
or by Andreas Rejbrand
Published on 2010-04-05T18:54:33Z
Indexed on
2010/04/05
19:03 UTC
Read the original article
Hit count: 411
I have noticed that there are quite a few community wikis about "Tips & Tricks" or "Hidden Features" in programming languages and APIs here at Stack Overflow. But I could not find any about my own personal favourites: Win32 API and Delphi. Therefore I start my "own" CW about Win32 API.
There are (at least) two kinds of Win API users: those that have been brought up using Windows API in C/C++, and those that have been brought up using some level of abstraction above the Windows API. I belong to the latter category, being brought up using Delphi's VCL. But over the last five years, I have become increasingly interested in the underlaying API of the Windows operating system, and today I work a lot with it.
Depending on which category a programmer belongs to, he (or possibly she) will think that different things are "cool" in the Windows API. For instance, whereas a VCL-brought up developer might think it it very cool to
var
errIcon: HICON;
begin
errIcon := LoadIcon(0, IDI_ERROR);
DrawIcon(Canvas.Handle, 10, 10, errIcon),
a programmer brought up using Windows API in C will not be as impressed.
But no matter how you are "brought up": what are the coolest "tricks" in Windows API?
I start by listing a few of my own favourites, some of which are more "cool" than "useful", though:
LoadIcon
andMessageBeep
can load/play system default icons and sounds.- Open the CD tray:
mciSendString('Set cdaudio door open wait', nil, 0, 0);
- Fade out the screen (Windows Vista and later) and turn of the monitor:
SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
GetWindowDC(GetDesktopWindow)
returns the DC of the desktop.
© Stack Overflow or respective owner