PDA

View Full Version : Windows Programming, Anyone?


Bond
05-27-2003, 08:54 AM
For those of you looking to jump into some Windows programming, here's a quick example to get you started. Not only is it very short, but it also does something extremely useful! It will close any running instances of Internet Explorer on your computer. I wrote this YEARS ago and have had a shortcut in my QuickLaunch toolbar since, making it convenient to launch it whenever my boss strolls by.


#define WIN32_LEAN_AND_MEAN
#include <windows.h>

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR pszCmdLine, int iCmdShow)
{
// Enumerate all open windows, looking for IE instances...
EnumWindows(EnumWindowsProc, NULL);

return 0;
}

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
// Is this an Internet Explorer window?
TCHAR szClass[80];
GetClassName(hwnd, szClass, sizeof(szClass) / sizeof(TCHAR));

if (lstrcmp(szClass, "IEFrame") == 0)
{
// Yep. Close it...
PostMessage(hwnd, WM_CLOSE, 0, 0);
}

// Keep enumerating...
return TRUE;
}