Native Code

Cool stuff for propeller-heads like us : here are some code fragments and tips, based on some of the most frequently-asked questions on the Microsoft public newsgroups. Just scroll to the section you're interested in, then click the question to access the individual tip page. Some code-based tips are downloadable and the source code files are in ZIP format for speed. Go to the Utilities page to get a suitable unzipper program.

Processes Threads and Files
How do I process through all of a directory tree, including the subdirectories ?
How do I extract the version of an EXE, DLL etc ?
How do I ensure that only one instance of my program runs ?
What are the pros and cons of the different Inter-Process Communications methods ?
Given a PID, how do I find the name of the process executable ?
How do I delete a directory tree that isn't empty ?
How do I get started working with threads ?
I start another app and try to wait synchronously on its process handle, but both processes hang. Why?
How do I get the name of the EXE associated with a given window?
How do I run another program from my program ?
I can't make CreateProcess launch my process or handle its parameters. Why ?
How do I determine the full path to my own executable file at run-time ?
How do I start another process and wait for it to complete before continuing ?

Interacting with the Shell
How do I put an icon in the system tray (a.k.a the notification area) ?
How do I find the default web browser application name ?
How do I stop my application appearing on the taskbar ?
Why doesn't my context menu dismiss properly when I click elsewhere ?
How do I start, detect and stop screen savers ?
How do I get the handle of the taskbar ?
How do I get back the OLD SetForegroundWindow behaviour ?
My app leaves a phantom gray button on the taskbar when it exits. Why?
SHFileOperation gives file system error 1026. Why ?
My app sometimes crashes when the user clicks on a tree control. Why ?
How do I hide the contents of the desktop ?
How do I programmatically dismiss a menu ?
How do I find out which edge the Windows Taskbar is on ?
How do I open SHBrowseForFolder at a pre-determined location ?
How do I add a manifest to a VC6 application?

Dialogs and Controls
Why don't all my controls appear in the VC6 ClassWizard?
How do I draw a bitmap in the background of a dialog ?
Why doesn't my combo box dropdown appear when I click the down arrow ?
How do I create one of those neat-o expanding dialogs ?
How do I change the colour or background of static text items on a dialog ?
My dialog closes when the user hits the Enter/Return or Esc key. Why ?
How do I change the background colour of an edit field on a dialog ?
How do I create controls on the fly ?
My application sometimes hangs when I hit an accelerator key. Why ?
How do I put a clickable URL in a dialog ?
How do I change the font(s) in an MFC application dialog ?
Why do my tree control icons lose transparency?

Microsoft Foundation Classes
I've added a menu to my dialog. Why don't the UPDATE_COMMAND_UI handlers get called ?
How do I make an invisible MFC dialog-based application ?
How do I change the displayed icon of my MFC app on the fly ?
I've disabled a menu item on my MFC program using EnableMenuItem, but it won't go gray. Why ?
What's the best way to send myself a message in MFC ?
How do I Create >16 Colour Toolbars?
Why does the MFC CString::Tokenize method ignore blank fields?

Users Groups and the Registry
How do I put new entries in the registry ?
How do I grab the users password under NT ?
How do I determine if a given user is in a given group ?

Compiler/Dev Environment Issues
I keep getting "undeclared identifier" compilation failures, even though I've included all necessary headers as far as I can see. Why ?
My app works in debug build, but crashes in release. What's the difference between the two ?
Why won't the compiler let me use a class member function as a callback ?
What do I need to compile a 16 bit DOS or Windows 3.x program ?
Why does Visual Studio 2010 give me error RC1106 ?

Miscellaneous Win32
Why doesn't my system wide hook capture all processes ?
How do I let the user drag a window which has no titlebar ?
Is there a way to direct stdout to my application window ?
How do I make a window "Topmost" ?
How do I find out which version of NT (server/workstation) I'm running on ?
How do I find the default web browser application name ?
How do I find the current IP address(es) of my machine ?
I've created a 16x16 icon for my app. Why does Windows insist on squishing up the 32x32 version ?
How do I allow the user to cancel a time-consuming operation ?
How do I stop the user resizing my window ?
How do I programmatically dismiss a menu ?
How do I constrain window resizing to always be square ?
How do I find out the drive letters in use on a given system ?
When I use a big (> 1MB) automatic-declared array my app crashes. Why ?
How do I determine that another machine is present on the network?
How do I make accurate timings under Win32?
How do I grab events for all applications? An example system-wide hook.
How do I enumerate the drives on my hosting machine ?
How do I determine if the user can see my window ?
Why does QueryPerformanceFrequency fail with error 998 ?

General Programming
How can I get debug information from my program in the field ?
What is "Hungarian" notation ?  
I want to be a superstar Win32 programmer, Bob. Which books should I read ?

The source code available on these pages is supplied free of charge for illustrative purposes only, and is not supported in any way whatsoever. The author accepts no responsibility for any consequences, direct or indirect, of its use.