Visual Studio Magazine Online, 2007-2010   Hide

Discarding More Dependencies, December 22, 2010
The next step on the path to independence forever from the Common Dialog OCX. This installment focuses on the File-Open dialog, which is probably the most common reason for becoming hooked on that particular dependency..
See also: Dialogs.
Discarding Dependencies, December 14, 2010
Another gentle reminder that including dependencies on objects outside your control, when some pretty straight-forward API calls would provide the same (or better!) functionality, isn't a very wise way to go. This piece begins to look at replacing the Common Dialogs OCX with straight-up drop-in ready Classic VB code. Here, we look at calling the ChooseFont API, building on the foundation built by Bruce McKinney long ago.
See also: Dialogs.
Honoring Hidden Fonts, October 14, 2010
Windows 7 offers users the ability to hide fonts they don't want to see anymore. In fact, it ships with dozens of hidden fonts, most set to that mode because they're inappropriate for your locale. But the only way to offer users a choice of desirable fonts is to use the system ChooseFont dialog, either via the API or common dialog OCX. This article shows you how to filter the list of fonts, returned by any of the font enumeration callbacks, to remove hidden fonts from the list.
See also: FontFilter.
Stuffing the Console Keyboard Buffer, August 26, 2010
Here we bring an ancient DOS concept, stuffing the keyboard buffer, forward a couple of generations so that you can use it with your Win32 console applications. This is probably the only way, never mind the most efficient, to transmit commands back to the command processor after your console application process exits.
See also: Console, KeyStuff.
Creating Admin Tools in a Least Privileged World, July 27, 2010
This one takes a look at how you can access process properties that normally only a debugger would need to. Well, the "new normal" at any rate. Used to be you could query process times, and things like that, without any sort of special privilege. Now, even running under admin credentials don't unlock that door for you anymore. Use the method presented here to elevate your process privilege to that of a debugger, assuming the user actually is an administrator.
See also: Uptime.
VB Community Transition, July 16, 2010
Microsoft must really hate its customers. What better proof need anyone offer, than the closure of their newsgroups and the attempted forced "transitioning" of customers to web forums?! <shudder> This column points out that Microsoft, contrary to what they may think, does not yet own usenet. The newsgroups you've long grown accustomed to using are still out there. And there are numerous free ways of continuing to access them, even if your ISP doesn't offer news servers. Hopefully, the microsoft.public hierarchy will live on for many years to come, but there's always comp.lang.basic.visual.misc if that doesn't work out. Cheers!
Measuring Optimizations for Classic VB, May 18, 2010
Discusses my favorite way to quickly measure one tweak versus another, using a drop-in ready stopwatch class. This technique makes use of the multimedia timer chip, actually reprogramming it to 1 millisecond resolution, to insure a highly accurate average measuremen. Yes, average. In a pre-emptive multitasking environment, there's no such thing as "real time." You need to time many invocations, and take the average to get a real sense of efficiency.
See also: StopWatch.
Honoring Startup Requests, May 4, 2010
Provides a drop-in ready class that exposes all the values offered by the GetStartupInfo API call in such a way that your Classic VB apps can immediately put them to use. For example, what WindowState did the user specify in the shortcut that started your application? Here's how you find out.
See also: StartupInfo, Hello.
Customizing the Ride (Part 2), April 12, 2010
A few more of my favorite IDE tips and tricks. This time I'll show you the (admittedly very crude) way to force enumerated constant names to hold their case, as well as a way to have internal min/max enumeration elements that can be used to easily test the validity of passed parameters.
Customizing the Ride (Part 1), April 6, 2010
A few of my favorite IDE tips and tricks. Included is a way to backup the registry settings for the VB5, VB6 or VBA IDEs so that they may be immediately reapplied anytime you do a complete new install; the method that seems to work more than any other when you need to recover a missing menu item or toolwindow; and, a reminder of just how useful the Templates directory functionality is.
Easing the Data Cramp, March 22, 2010
There's actually a very easy way to grow the virtual memory space within your application's process to 3, or even 4GB, on a system that's properly configured. It's just a matter of flipping the LARGE_ADDRESS_AWARE bit in the EXE header. Here's a demonstration how to do that, and then test the results.
See also: MemStatus.
Searching Within Byte Arrays, March 16, 2010
Did you know you can search Byte arrays with InstrB, just like you can search Strings with Instr? During a recent conversation, I found this wasn't as widely known as I might've guessed. Here's all the info you should need, if this blurb doesn't do it for you already, to get going. The article also includes a few ideas on the easiest ways to load up the sub-arrays you'll be searching for.
Redesign IDE Dialogs, March 3, 2010
Here's a look at how to use one freeware tool, ResHacker, to modify the dialogs in the VB5 or VB6 IDE. Specifically, I provide instructions to resize the References dialog, so you can see the entire path of the highlighted file. That dialog was as good as it got at 640x480, but the times have changed a bit since then, and there's no reason you shouldn't be able to use it properly now.
The Next Y2K, February 16, 2010
There's an issue with "Unix Time" that you probably ought to be aware of. Your ClassicVB apps won't be affected, unless they interact with external apps or libraries that rely on this style of marking time. The short story is, the clock rolls over in January 2038. Forewarned is forearmed.
See also: TimeZone.
Creating Nested Folders, February 4, 2010
It's a common need. Nested folders, sometimes deeply nested. VB provides the MkDir method, but that only works one level at a time. This column just wraps up a method to take any length path, and make sure it exists in its entirety. Assuming it's legal, at any rate. Nothing fancy, just an extension of the existing toolset to make one of the tools infinitely more useful.
Monitoring System Power Status, January 5, 2010
Third in a series on the utility of subclassing the hidden top-level window that ClassicVB creates for every application. This column shows how to hook into an ongoing stream of power notifications, alerting you to the current status of the system battery whenever it changes. This may become an increasingly useful capability, as the proliferation of portable devices continues unabated.
See also: SysInfo.
Listening to ThunderMain, December 17, 2009
Second in a series on the utility of subclassing the hidden top-level window that ClassicVB creates for every application. This column offers a broad insight into the sorts of notifications Windows routinely supplies, but Microsoft chose not to forward on to us as events. A sample project is developed that roughly replicates the SYSINFO.OCX control that shipped with VB4.
See also: SysInfo.
No Such Thing as a Windowless VB App, November 16, 2009
Every application ever written with Classic VB has a hidden top-level window, generically referred to as "ThunderMain", which VB uses to sink important system notifications. This short article shows how to find this hidden window, by enumerating all the windows in the current process. Once you have its handle, it's a pretty simple task to hook into its message stream, so that you could be alerted just as VB itself is. For example, if you had a form-less application, but wanted to know when Windows was shutting down, rather than use Form_QueryUnload you'd watch for WM_QUERYENDSESSION.
See also: SysInfo.
Inside Alternative Data Streams, November 3, 2009
Alternative Data Streams (ADS) may be one of the best kept secrets of Windows NT. Supported since the introduction of NTFS, in the early part of the last decade of the last century, ADS offer a way to tuck re-creatable data away out of sight. VB has always been able to read and write ADS, but now with the methods outlined in this article and the related download, you can also enumerate and delete ADS from any file or folder on an NTFS volume.
See also: Streams.
Microsoft's VB6 Support Strategy?, October 27, 2009
After years neglecting the VB6 community, Microsoft seems to be missing something. Us! They've recently added an entire new subsite under MSDN dedicated to proselytizing the wayward ones. While I appreciate them recognizing, finally, that lots of us didn't care for what they did to Classic VB, this new effort is insulting in its own ways too. But hey, watch the movie, and decide for yourself if they understand yet that it's wrong to break functional code.
Finding an Associated Executable, October 13, 2009
So it turns out after all these years that FindExecutable is broken. It works very randomly when the associated file extension is five, or presumably more, characters. This article explores the IQueryAssociations interface, which is most easily accessible to Classic VB through the AssocQueryString API, and provides a wealth of practical information about any given file extension. For example, you can get the friendly name of both the associated application and the specific data files, the string used to execute any associated verb, various DDE commands, the MIME content-type, and more. In the process, we build a drop-in ready class which provides these values as read-only properties for the supplied file extension. Note that, unlike FindExecutable, AssocQueryString does not require that the file actually exist before providing feedback on the filetype.
See also: Assoc, Which.
Finding the Right Tool For the Job, September 22, 2009
I needed to use the dumpbin utility on a virtual machine the other day, but it wasn't there. So I jumped back my regular box, and sure enough it worked just fine. But where was it? I had no idea. Looking at the %path% variable, I saw about twenty folders. I needed a new tool to help me find tools. I was vaguely aware of a unix command that would tell you which executable would run, and decided it was time to migrate that to Windows. This sample just recreates the same search pattern that Windows uses, when it attempts to execute an unqualified command, by looking in turn through the current directory and each directory on the path until it finds a match.
See also: Which, Console.
Thoughtful UI Tweaks Can Make All the Difference, August 25, 2009
Okay, so this starts out with a bit of a rant on disrespectful programming practices, but at least it finishes up with the code you need to avoid irritating users needlessly. It's really not that difficult to reposition dialogs where they were the last time up, but people appreciate that. But what if the monitor you had previously displayed that form on is now gone or resized? This shows how to make sure your dialogs are onscreen and as close to where they were as is possible.
See also: Monitors.
Persisting Environment Variables, August 18, 2009
Ever wanted to set an environment variable, and have it stick "forever" after? Here's the code you'll need to do that, in almost all circumstances. It simply involves setting a few registry values and notifying all running applications. But there's a catch. If you're trying to do this from a console application, the current instance of cmd.exe pays absolutely no attention to the WM_SETTINGCHANGE message you broadcast. No avoiding that, I'm afraid.
See also: MEnvVars.bas.
Reacting to the Mousewheel, August 11, 2009
Building on the last article, here I provide a drop-in ready class module that uses the SetWindowSubclass method to monitor mousewheel movements. As hard as it is to believe now, even VB6 was released in the pre-mousewheel era. Here you can learn how to lend full support to the ubiquitous device.
See also: HookXP, MouseEvent.
Hooking the Mouse, July 28, 2009
This one riffs on the same theme as the last - using SetWindowSubclass to easily add new functionality to your forms. Here, we look at building a single class module that can manage a collection of objects it will watch for mouse messages. We then raise the missing MouseEnter and MouseLeave events, as well as others, to notify the listener.
See also: HookXP, MouseEvent.
Subclassing the XP Way, July 16, 2009
Truth is, these functions weren't documented until Windows XP came along, but they've been there for far longer. The SetWindowSubclass API provides an almost infinitely safer method of subclassing than the more classic way of replacing a window's default message procedure manually. This article explores a true hidden gem for Classic VB programmers. You'll be amazed to find that you can now have multiple message handlers, and no longer be concerned with the teardown order.
See also: HookXP, SnapDialog.
The Only Add-In Always Used, June 15, 2009
Recently, Peter Young offered permission for me to redistribute his invaluable add-in, vbAdvance, here on this site. Now that it's freeware, I'm allowed to mention it in my VSM writings. Thought I'd try to alert as wide an audience as possible that this tool is once again available. It's a pretty rare project that I don't use some feature offered by vbAdvance.
See also: Console, vbAdvance.
Using a Standard Terminal Font, June 2, 2009
Need to recreate that olde-timey Terminal look? There's a stock object built into every version of Windows that'll serve that need. This column shows how to select the standard (stock) fonts into any window with an hWnd. Nothing too fancy and in fact very easy; just nice to know when you need it.
See also: StockFont.
Determining Process Times, May 5, 2009
Here we look at finding out how long any given process has been running. This technique can be used to determine how long Windows itself has been up and responsive, by querying how long certain critical processes have been running. You can also use the GetProcessTimes API to query both Kernel and User time for any process, to learn how much "work" it's done during its run.
See also: Uptime.
Mining the Registry for Structures, April 20, 2009
Need to extract binary data from the registry? Here's a quick primer on reading and interpreting structures stored there. This column shows how to grab any REG_BINARY value from the registry, check to see that it's the proper size, and convert it to a predefined structure type. This is a great tool to skirt the limitations of REG_SZ or even REG_DWORD, and can be used in either HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE.
See also: Uptime.
Prisoner of Geography, March 23, 2009
Americans (specifically, of the USian variety), are blessed and cursed by their cultural ignorance. It seems the rest of the world has adopted our language as the standard, so when we're forced to work with other languages -- in particular those with "awkward" character sets -- we're often at a partial to total loss as to how to proceed. This column talks a little about that, and ClassicVB's character set schizophrenia with its half-baked Unicode implementation. As a bonus, we've (community effort) updated the SendKeys replacement module to handle Unicode characters as well.
See also: SendInput.
Working with Multiple Monitors, March 2, 2009
Most of the time it doesn't matter where the user puts your application's windows, but every now and then you really need to know -- or even decide this for yourself. This column looks at the ways to determine individual monitor coordinates, which monitor an application window or any given point is over, and how to determine the dimensions of the overall virtual desktop, as well as how to distinguish pseudo display devices from real ones.
See also: Monitors, SnapDialog.
Forward Compatibility, February 2, 2009
Patrick Meader liked to call this new column my "blog." Taking that cue, I sorta snapped one day and just whooped out a little opinion piece on Trust and what I consider to be of utmost importance when considering where to invest your code assets. Save the protests for someone who doesn't care about their data, ok?  :-)
Lemme Tell Ya Where To Stick It, January 19, 2009
Used to be you just stuck your INI file in the same folder as the EXE, and life was good. The rules changed years ago, but it wasn't until the Bad Cop Vista came along and started enforcing them that hardly anyone noticed. This column looks at where you need to put your application data these days, if you don't want any ugly surprises.
See also: SysFolders, kpINI.
Got One Right!, December 8, 2008
The lowly INI file is one feature of Windows 1.0 that has survived and indeed still provides the best answer to persisting application settings in many situations. This column gives a brief history of Microsoft's embrace and subsequent rejection of this winning design, as well as a link to a drop-in ready class file I wrote to ease your use of INI files.
See also: kpINI.
Executing Debuggables, November 17, 2008
Do you make heavy use of Debug.Print when you're trying to track down a bug or some other odd behavior in your application? Do you sometimes wish you could use that handy feature from an executable? The Win32 OutputDebugString function effectively offers you this option. This column shows you how, and provides links to two handy utilities for intercepting this output.
See also: Console.
Take Control of Window Movements, April 14, 2008
Ever noticed how some utilities snap to the edges of your screen when you drag them around? This article discussions how easy this user-friendly feature is to support, using native subclassing and hooking the WM_WINDOWPOSCHANGING message. The drop-in ready class developed for your download also supports multiple monitor systems as well as recognizing where the taskbar is. You can determine how far away the form must be before it snaps to the screen edge.
See also: SnapDialog, HookMe.
Simple Asynchronous Downloads, March 27, 2008
There are probably as many strategies for downloading files from the Internet as there are .NET programmers -- that is, no where near the number of Classic VB developers, but still more than a mere handful. Ask the question in a newsgroup, and you'll quickly get a good half-dozen suggestions and a handful of links, all pointing to different ideas. But rarely, if ever, do I see anyone suggest what I consider to be probably the single most powerful "unknown" native method Classic VB offers: the AsyncRead method of UserControl and UserDocument objects.
See also: NetGrab, NetCam.
Are You Safer Now?, January 29, 2008
Are you as frustrated as I am at the overwhelming inconvenience lost in search of safety over the last few years? This column takes a look at just how silly the anti-virus game has gotten, and shows how I had to "crawl under the velvet rope" when McAfee wasn't looking.
VB Statement Against Vista, November 13, 2007
VB survived Vista nearly intact, with the glaring exception of one statement. Learn what your options with SendKeys are under the newest operating system.
See also: SendInput.
Vista Versus VB, September 17, 2007
Yes, it is possible to install VB6 on Vista. Yes, it's possible to install SP5 on Vista, too. Experience the joy of installing VB6 with SP5 and/or SP6, through the eyes of someone just as amazed as you may be at the obstacles tossed up in your way. Luckily, all stunts were performed on a test track (VM) by an experienced driver (me). Well, the first thing, anyway.
Viva la VB!, September 4, 2007
VSM's revival of my old column, albeit this time it's only going to appear online. "Not that there's anything wrong with that." This piece simply reintroduces me to what really must be an entirely new universe of readers, and outlines where I hope to take future columns. They apparently are sensing that perhaps the news of Classic VB's death was indeed greatly exaggerated? I also spend a bit of time advocating for what I've found to be the best tool Microsoft has released in ages - Virtual PC 2007.

Visual Studio Magazine, 2001-2005   Hide

Support Classic VB, Guest Opinion, May 2005
In the only guest opinion ever provided by this author, he urges everyone to consider expressing their desire to Microsoft continue support for Classic Visual Basic by signing the petition
Work With HTML and the Clipboard, Q&A, February 2003
Learn how to format HTML for placement on the Windows clipboard, such that other applications, like Microsoft Word or FrontPage can recognize it. Come to terms with the barely documented CF_HTML format so you can read and write it with ease. Learn a sneaky way to have Internet Explorer strip all the HTML out of a snippet, so that you're left with just the raw text.
Download original code sample. Open full article in new window.
Add Hotkey Support, Q&A, January 2003
Use the RegisterHotKey API and a bit of subclassing to add support for system-wide hotkeys to your application. Sink WM_HOTKEY messages in a standard BAS module, and dispatch the handling to a dedicated class instance which can in turn notify the affected form(s).
Download original code sample. Open full article in new window.
Use the System's File Properties Dialog, Q&A, December 2002
Offer your users the opportunity to bring up Windows standard file properties dialog for any given file. This can be a useful feature in a utility type, file-based, application.
Download original code sample. Open full article in new window.
Crank Up an App's Response Time, Q&A, November 2002
Adjust the relative priority of your process, or any process in the system, to increase its responsiveness or allow it to fall into the background and only work when the system isn't otherwise busy.
Download original code sample. Open full article in new window.
Keep a Window Visible, Q&A, September 2002
Use a little subclassing to restrict users from moving your forms offscreen. If you produce adware, please don't read this column.
Download original code sample. See also: HookMe. Open full article in new window.
Use API Callbacks to Object Interfaces Safely, Q&A, August 2002
Pass object interface pointers through API callbacks, so that the proper instances are notified with a minimum of indirection. This technique allows you to do things like process EnumWindows calls within specific class instances. Easy and powerful - what a combination!
Download original code sample. Open full article in new window.
Drag and Drop URLs, Q&A, July 2002
Learn how to accept URLs dragged from Internet Explorer using OLE Drag and Drop methods. Bonus code shows how to break apart URLs into their constituent parts (protocol, server, folder, file, etc.) or combine the separate parts into a valid URL.
Download original code sample. See also: NetUrl. Open full article in new window.
Determine If Word is Installed, Q&A, June 2002
Optimize your Office automation by determining if Microsoft Word is installed, and if so what version of it is there. Work around a bug in the way checkmarks are displayed in menus, when they are turned on or off at the time the menu is selected.
Download original code sample. Open full article in new window.
Prevent CD AutoRun, Q&A, May 2002
Sometimes you don't want to allow autorun applications to start up when the user inserts a CD, such as during an installation application that's verifying a previous version for upgrade. Learn how to watch for notification of autorun instances, and prevent them from starting. Also, how to load a form by name.
Download original code sample. See also: HookMe. Open full article in new window.
Restore Tray Icons After Crashes, Q&A, April 2002
Prevent your tray app from pulling one of those lame-o disappearing icon tricks when Explorer crashes. Windows shoots a registered message to all top-level windows whenever Explorer (re)starts, and watching for this allows you to (re)inject your icon into the system tray. Learn how to draw a graphical lasso, to facilitate your user selecting a rectangular area within a graphic.
Download original code sample. See also: Lasso, Tray. Open full article in new window.
Name That Message, Q&A, March 2002
Enumerate a system table in which Windows stores all sorts of goodies, in particular the names of registered messages. Entries in this table fall within the semi- magic range of &hC000 through &hFFFF. 
Download original code sample. See also: EnumMsgs. Open full article in new window.
Enhance the Printers Collection, Desktop Developer, February 2002
Run through all the basic APIs to entirely recreate the Printers dialog offered by Windows. Monitor all ongoing print jobs, pause or cancel queued jobs, determine job attributes, and much more. Also, overcome a bug in VB5 where it doesn't properly populate the Printers collections on machines that are connected to lots of printers. The code from this column seems to be the single most referred to download from this site in the Classic VB newsgroups.
Download original code sample. See also: PrnInfo.
Add Images to MDIForm Backgrounds, Q&A, January 2002
Learn a new technique for painting on, or adding images to, an MDIForm's background. This method only works in VB6, and doesn't require the cumbersome subclassing that was needed in previous versions. Numerous "canned" routines are provided to tile an image, stretch or center an image, paint a gradient, and much more, all in a drop-in ready class module. Determine the name of of the EXE that's called your DLL or OCX by examining the current process's command line.
Download original code sample. See also: CmdLine, MdiBack.
Let Me Count the Ways, Desktop Developer, November 2001
Rare is the application that doesn't need to iterate through some collection of system data. This column goes through the basics of using system enumerations, demonstrating common methods to handle different strategies including callbacks, multiple data instances within a passed buffer, picking apart snapsnots, and repeated calls for the next data element.
Download original code sample. See also: AltTab, FileInfo, HexDump, PassSniff.
Kill an App Gently, Desktop Developer, September 2001
So you've made the trip to Bigger Hammer Hardware, and you're convinced TerminateProcess is just the ticket for you, huh? Not quite so fast, there, Bubba! Read this column to learn how to fully emulate what Windows itself does when you attempt to kill a process via Task Manager. Start by asking nicely, and only pull out the big guns when all else fails.
Download original code sample. See also: TaskList.
Extract Color Values Painlessly, Q&A, September 2001
Break out the individual color components (red, green, and blue) from Long color values, such as those returned by GetPixel. This column provides several drop-in ready functions useful for this common task. Add a 3D border to your borderless forms by toggling a few window style bits. Use longer timer intervals, minutes rather than seconds, with VB's native Timer control.
Download original code sample. See also: FormBdr, Rgb.

Visual Basic Programmer's Journal, 1995-2001   Hide

Fill in Irregularly Shaped Areas, Ask the VB Pro, August 2001
Restore QuickBasic's handy-dandy Paint statement to Visual Basic with this drop-in module that emulates it using the Windows ExtFloodFill API. Just provide the coordinates and color, and your floodfill begins from that point outward. Explore aspects of moving items from one Listbox to another, and build your own dual-list custom control with buttons to move selected or all items either way. Reduce flicker in your textboxes when you add new text to the end.
Download original code sample. See also: DualList, Flood.
Preview Uninstalled Fonts, Ask the VB Pro, July 2001
Solve the age-old mystery of previewing uninstalled TrueType fonts by using the drop-in ready class provided in this column. This month we explore the twisted storage within TTF files, and put together the tools necessary to take them apart, table by table. You will gain a better understanding of what big-endian and little-endian really mean. TTF is a format originally designed for use on Motorola-based systems, but knowing how to reverse byte pairs allows you, and Windows, to use them at will. The solution presented here dives into any given TTF to retrieve many of its unique characteristics, such as Font Name, Family, Subfamily, Trademark, and so on. And, it provides a way to temporarily tell the system the font is installed so you can use it within your own app, but others don't see it.
Download original code sample. See also: FontPre.
Soup Up Office VBA, Ask the VB Pro, June 2001
Do you miss the Clipboard object when you shift gears into VBA? I did too, and did something about it. This issue we reproduce this classic object so that it can be fully used within Office applications. Techniques demonstrated in the last couple columns are heavily exercised here, combining to form a really nice solution. For a final demonstration, we loop through a selected Range within an Excel worksheet, convert it to HTML, and copy it onto the clipboard so it's ready to be pasted into FrontPage (or any other editor).
Download original code sample. See also: ClipEx, MemoryDC, StrBldr.
Build Strings Faster, Ask the VB Pro, May 2001
Okay, I admit it - some of the .net stuff is pretty darned cool. For instance, the StringBuilder class. It's always been common knowledge that concatenating strings was inefficient and for the best possible speed you should preallocate a buffer and stuff it appropriately. This month's column recreates a Classic VB version of the StringBuilder class, and it positively smokes when building large strings from many smaller parts. We also revisit raising events from arrays of objects - this time by creating an intermediate notification object. This method avoids the potentially deadly issue of circular references.
Download original code sample. See also: ObjArrays, StrBldr.
Work With Memory Bitmaps, Ask the VB Pro, April 2001
Explore ways to manipulate your standard picture objects in memory. The example used shows how to retrieve and set the colors of individual pixels of an invisible StdPicture object. Another example shows how to disassociate a bitmap from its StdPicture container, so that you can hand it off to other processes or the Windows clipboard. The core of these solutions lies in creating a memory-based device context, and using that to manipulate bitmaps any way you wish - very powerful. The last tip in this column concerns highlighting controls upon receiving focus - for example, dropping a Combobox list or changing the BackColor of a textbox.
Download original code sample. See also: MemoryDC.
Don't Depend on SysInfo Control, Ask the VB Pro, March 2001
Lose an extra dependency by directly querying the system for the information it provides, or have the system notify you, rather than asking a flaky OCX to do the job for you. Set up your DLLs so they're automatically notified when certain system events occur. You can create a hidden, top-level window that will receive all the routine notifications Windows provides, so you're always aware of the system state. Use the ExitProcess API safely, so that you can return an exit code to calling applications. The demo app for this recreates the classic Hello World app Charles Petzold wrote, so it covers much more than just providing an exit code. Get by VB's limitation of not allowing direct assignment of a function address, such as to an element of a UDT, with a simple custom function.
Download original code sample. See also: Hello.
Look Into Raw Memory Contents, Ask the VB Pro, February 2001
Ever wished VB would show you the contents of any random area in memory? This column shows you can produce a memory dump into the Immediate window, similar to those you'll see in most hex editors. Also included in the handy debugging module are functions to dereference pointers to both ANSI and Unicode string data and DWORD values. With these tools, you can conquer any API! Also included is a technique to turn your command buttons into auto-repeaters that will continue firing events as long as the user holds their mouse button down. 
Download original code sample. See also: HexDump, NetDomain.
Add a Window to the Taskbar, Ask the VB Pro, January 2001
Explore window style bits. Learn how to modify dialogs from other applications, such as control panel applets, to have them appear in the Taskbar. Overcome many other "read-only at runtime" properties of provided by your forms, as well. Toggle the ShowInTaskbar property at runtime. Uncover the name of your domain controller in Windows 2000.
Download original code sample. See also: FormBdr, NetDomain.
Manipulate Your Message Boxes, Ask the VB Pro, December 2000
Position your message boxes wherever you'd like to, specifying precise screen coordinates or centering them over your main form. Pop your message boxes up on top of even topmost windows. Learn how to add a Clone method to your objects, so you can get precise copies without multiple references.
Download original code sample. See also: CloneObjs, MovedMsg.
Toggle the Titlebar (and Other Form Tricks), Ask the VB Pro, November 2000
The production ready class that is demonstrated in this column is called FormBorder, as it originally dealt with the sorts of properties associated with different border styles, but it has grown to far beyond that! Learn how to toggle most of the "read-only at runtime" properties offered by your forms. This column specifically talks about setting window style bits to enable toggling the titlebar on and off at runtime, allowing sizing and control boxes, turning your form into a toolwindow, making it topmost, and many other things not normally accessible at runtime. After you've made your window captionless, you can decide to let the user drag it around the screen anyway, or pop the system menu by right-clicking. Lots of "silly form tricks," here!
Download original code sample. See also: FormBdr.
Produce Translucent Effects, Ask the VB Pro, October 2000
Windows 2000 introduced the concept of translucent, or layered, windows. Put the drop-in ready class presented in this column to add this functionality to your own application's forms. Another drop-in class offered in this column provides all the standard mathematical functions necessary to do math with rational numbers (fractions). This class holds special meaning to me, as it was the first one I stepped through using the F8 key -- early in the VB4 beta days -- to learn how VB classes worked.
Download original code sample. See also: Fraction, Translucent.
Is That App Hung? Find Out, Ask the VB Pro, September 2000
Check whether another application is hung the same was as Task Manager uses to inform you that something is "not responding." Offer your users the chance to start another process by invoking Windows standard Run dialog. Hook the creation of foreign dialogs so that you can customize their appearance before your users see them. Stuff a standard textbox with more than 64K characters on NT systems.
Download original code sample. See also: TaskList.
Listen to Objects With Interface, Ask the VB Pro, August 2000
Raise events from arrays of custom objects. Control which field of a DateTimePicker control receives focus when the user tabs into it. Learn the basic of setting and clearing individual bits of a integral variable, and explore the bonus code for scads more bit manipulation possibilities, including rotation and shifting.
Download original code sample. See also: ObjArrays, Twiddle.
Detect Library Startup and Shutdown, Ask the VB Pro, July 2000
Create psuedo Initialize and Terminate events for your ActiveX libraries, so you can perform startup and teardown activities. React as the user moves the highlighted selection within a CombBox dropdown. Figure out the App.Path of the parent application from within a UserControl. Take complete charge of the mouse for demos -- move the cursor anywhere, click with any button on any window, spin the mousewheel.
Download original code sample. See also: MouseEvent.
Draw Bitmaps on Device Contexts, Ask the VB Pro, June 2000
Discover how easy it is to create bitmaps in memory, and load them onto the Windows clipboard. This provides the perfect method to create Commandbar buttons at runtime. Explore several options for displaying the full text of ListBox items when the list is too narrow. Define your own custom message values to use with SendMessage. Assign an icon to the EXE even when you don't have any forms in your project.
Download original code sample. See also: ClipEx.
Mine Your Resources, Ask the VB Pro, May 2000
Enumerate and extract bitmap, icon, and string resources from EXE and DLL files. Learn how to redirect system callbacks and enumerations into the appropriate form and class instances, rather than have them all dump back into a standard BAS module.
Download original code sample. See also: EnumRes.
Copy Several Files Into One, Ask the VB Pro, April 2000
Overcome the limitations of FileCopy by performing a manual copy with your own code. This method allows lots more possibilities, such as monitoring progress, concatenating multiple files, or even cancelling the copy operation, all while allowing your application to remain responsive. Determine whether the user has a CD-ROM drive. Check to see whether a given file exists on an FTP server.
Download original code sample. See also: FtpExists, NetUrl.
Retrieve Windows Font Specification, Ask the VB Pro, March 2000
Use a production-ready class to convert system fonts, such as those used in window titles, to StdFont objects accessible to any controls or forms in your project. Query the system for the current Alt-Tab order of applications. Update your application icon at runtime, including the depiction used in Windows Alt-Tab dialog.
Download original code sample. See also: AltTab, AppIcon, NCMetrics.
Extend Scrollbar Range With Class, Ask the VB Pro, February 2000
One legacy of Windows 95 not being fully 32-bit, is that many of the Integer properties in VB4/32 could've been updated to Long, but weren't. Probably no such limitation is so frustrating as that of VB's intrinsic Scrollbar controls. This column provides a drop-in class that offers full 32-bit support to native Scrollbars. Also demonstrated is just how easy it was (not applicable to Win2000+) to read behind the asterisks and recover passwords. The column concludes with a demonstration of how just two instances of an application with a GDI resource leak can actually bring NT to its knees.
Download original code sample. See also: LongScroll, PassSniff.
Find and Convert a Drive Letter, Ask the VB Pro, January 2000
Check whether a drive letter is mapped to a network share, and if so convert it to Universal Naming Convention (UNC) format. Convert older style Windows Metafiles (WMF) to the newer, more versatile Enhanced Metafile (EMF) format.
Download original code sample. See also: UncName, Wmf2Emf.
Load Arrays With Values Quickly, Ask the VB Pro, December 1999
Initialize an array of constants by reading them from a resource file, similar to QuickBasic's lost Data command. Abstract a recordset behind a class that provides the user interface with easily queried First and Last properties it can use to enable navigation controls. Attach a subform onto a main form, so that it moves and minimizes in sync. Trick Windows into painting the titlebars of your paired forms as if both are active if either is active.
Download original code sample. See also: FormPair.
Who Says VB Can't Use Pointers?, Ask the VB Pro, November 1999
An unusual Q&A column, in that it only covers a single subject -- making use of pointers within VB. For this example, iterating the Internet cache is used, as it returns a rich memory-based structure that we can pick apart into strings and numbers.
Download original code sample. See also: NetUser, NetWksta.
Move Data With Memory-Mapped Files, Ask the VB Pro, October 1999
Map the contents of any disk-based file directly into your process's memory space, allowing near instantaneous access to any bytes within. This technique allows you to process multiple megabytes of data in a fraction of the time required for more standard disk i/o techniques. Decode obscure API error code values into (potentially?) more meaningful textual error messages.
Download original code sample. See also: ApiErrMsg, ListSearch, MapFile.
Call the Right Function, Ask the VB Pro, September 1999
Make sure API functions are actually exported from the DLL before attempting to call them. For example, use GetDiskFreeSpaceEx instead of the earlier incarnation GetDiskFreeSpace, when its available. Learn how to use 8-byte Currency variables with APIs that require LARGE_INTEGER parameters. Adjust the height of Combobox dropdown windows so that all items are visible, and the user won't have to scroll.
Download original code sample. See also: DrvInfo, FullDrop.
Use a Label Control as a Hyperlink, Ask the VB Pro, August 1999
The often-neglected DragDrop functionality provides the means to offer the often-requested MouseLeave notification, which is needed to properly implement a hyperlink's visual behaviors. Compile WAV files into your application, or into a DLL used by your application, to avoid network traffic reaching out to load them individually from the server.
Download original code sample. See also: HyperLabel, HyperJmp.
Use Smart Text Tricks, Ask the VB Pro, July 1999
Create graphics on the fly using symbol fonts to "trick" MSFlexGrid controls into using "multiple" fonts. Add new properties to fonts, drawing text using only outlines, adding drop shadows, or different fill and outline colors. Force your controls to use a fixed-pitch font for even spacing of columnar data. Use a barely documented method of the IFont interface to Clone StdFont objects, breaking the bonds of shared references.
Download original code sample. See also: TextOutline.
Get a Grip With Subclassing, Ask the VB Pro, June 1999
Explore a number of methods to add a size grip, or Shangle as Alan Cooper calls them, to your VB forms. Avoid firing intense code such as painting on every Resize event, waiting instead until the user finishes resizing the window. Produce a demo DLL that can only be used within specific VB IDE(s), restricting the potential customer from distributing it with their finished application.
Download original code sample. See also: Grabber.
Repair Distorted, Shrunken Icons, Ask the VB Pro, April 1999
Learn some of the mysteries of how VB chooses which icon resource to use for what purpose -- in particular, how to design a dual-resource icon that VB can interpret correctly, so that it uses the 16x16 or 32x32 images without distortion. Come to a better understanding of GlobalMultiUse objects, so that your library consumers can make use of always-available classes. Determine the current time zone name, daylight savings and stardard time dates, offset from GMT, and more. Convert relative dates such as "first Sunday in April" or "last Sunday in October" to actual values.
Download original code sample. See also: TimeZone.
Run on Reboot, Ask the VB Pro, March 1999
Instruct Windows to start your application automatically the next, or every, time the current or any user logs in by writing to the Run or RunOnce registry keys. Limit usercontrols such that no more than a single instance may be placed on any given form.
Download original code sample. See also: DrvMap, RunOnce.
Force Your Way to the Foreground, Ask the VB Pro, February 1999
Overcome the limitations imposed on SetForegroundWindow in Windows 98 and 2000, so that you can truly force your application to the front in cases where you just can't resist irritating your users. Enumerate all top-level windows to approximate the list of applications presented by NT's Task Manager. Use recursive callbacks to uncover the handle to the VB IDE's Immediate window, in a fruitless attempt to clear it. Open the common file dialogs at system folders, such as Network Neighborhood, My Computer, or Control Panel, by passing their unique CLSIDs as the InitDir.
Download original code sample. See also: ForceFore, TaskList.
Print Text at an Angle, Ask the VB Pro, January 1999
Create a logical font at any specified angle, and use it within your forms, Picture boxes, or even memory device contexts. Set a default timeout period for standard MsgBox's, so that they are automatically dismissed if the user isn't present. Calculate "great circle" distances with a simple class-based approach.
Download original code sample. See also: RotText, TimedMsg.
Verifying Internet Access, Ask the VB Pro, December 1998
Use WinInet functions to determine whether a connection to the internet is active, to autodial the default connectoid, or to hang-up. This column stresses the need, and demonstrates how, to "try the wire" by actually attempting to connect to known-good sites. Become familiar with the CF_HDROP clipboard format so that you can read and write lists of files placed on the clipboard.
Download original code sample. See also: ClipFileCopy, NetConnect.
VB Can't Can Do That!, Ask the VB Pro, October 1998
Display the correct name of your usercontrol at design-time, just like VB does with its intrinsic controls, by paying attention to the AmbientChanged event. Force VB's native Scrollbar to correctly paint its background on NT systems by subclassing the owner form. Convert a PIDL to a SafeArray, so that it may be used with the WebBrowser control's Navigate2 method to open one of Windows special folders.
Download original code sample. See also: HookMe.
Solve These Irregular Problems, Ask the VB Pro, September 1998
Build a polygonal button control, generating a MaskPicture at runtime to provide areas that are considered outside the bounds of the usercontrol. Transform a memory-based bitmap into a StdPicture object. Call Control Panel applets from within your application. Find the ListIndex for whichever item in a ListBox is under the cursor.
Download original code sample. See also: PolyBtn, Shell32.
Sounds Like Trouble, Ask the VB Pro, August 1998
Play system defined sounds, like those associated with the standard messagebox types. Learn the basics of playing MIDI files, to avoid the initial hurdles with Multimedia Control Interface (MCI). Access the implemented abstract classes of your UserControl through its Object property. Overcoming problems with multiple string tables in a resource file for proper localization. Translate API error codes into meaningful messages.
Download original code sample. See also: ApiErrMsg, SysSnd.
Share Data Between Object Instances, Black Belt Programming, August 1998
This column examines three different strategies for sharing data and even events between separate object instances. Find out how simple it is to share static data that each control instance relies upon. With a bit more strategy, you can even share events, such as system callbacks.
Download original code sample. See also: SyncEvts.
Handle Strings, Dates, and Colors, Ask the VB Pro, July 1998
Pass strings between instances of your application, tossing the command line of a new instance to a previous instance, for example. Plus, two techniques that are quite useful for setting properties of your UserControls: Interpret a date from a wide variety of possible user-input types, and offer the standard color dropdown in the Properties window.
Download original code sample. See also: PrevInst. Co-authored with Phil Weber.
List Your Higher Windows, Ask the VB Pro, June 1998
Make the most of VB5's AddressOf operator to start taking advantage of the many callbacks offered by Windows. In this column, explore the use of EnumWindows to collect an list of all top-level windows. Play any WAV file with a single API call. Or with just a few more APIs, play any system-defined sound. 
Download original code sample. See also: FindPart, SysSnd. Co-authored with Phil Weber.
Who's My Parent?, Ask the VB Pro, May 1998
Various methods to establish parent-child relationships between COM objects, including nasty circular referencing, and even nastier (but far cleaner!) temporary theft of object references by storing a pointer to the parent object. Use ShellExecute to fire off LNK (shortcut) files. Prevent a Textbox from gaining focus, so the text it contains can't be copied, without having it appear grayed out. Drill down to get the hWnd of the taskbar's clock window. 
Download original code sample.
Getting Out Of a Dither, Ask the VB Pro, April 1998
Come to a better understanding of VB's PaletteMode property, so that you can avoid Windows default dithering on 256-color displays. Determine whether any given COM object is running locally or remotely. Use the new ScaleX and ScaleY methods of a UserControl to ensure the coordinates you return in Mouse events match those of your control's container. Take advantage of new WinInet functionality to automatically connect to the internet whenever you need to.
Download original code sample. See also: NetConnect. Co-authored with Phil Weber.
Tailor Your Displays, Ask the VB Pro, March 1998
VB's Statusbar control doesn't act as a control container, so how can you show a Progressbar there, like so many applications commonly do? Easily, if you use the drop-in CProgBarEx class provided with this column. This class can be used in any application when the author would prefer not shipping the common controls OCX, or would otherwise like to draw a custom progress indicator. 
Download original code sample. See also: StatProg, ProgBar. Co-authored with Phil Weber.
Spool, Shell, and Hook, Ask the VB Pro, February 1998
Submit files that were "printed to disk" directly to Windows print spooler for printing on-demand. Learn what that value returned from VB's Shell function actually means, and how to use it to find the top-level window of the spawned application by enumerating all top-level windows using two different methods. Explore different ways to "shell and wait" for an application to finish. Subclass a Combobox in order to find it's dropdown window, so that it can be resized appropriately.
Download original code sample. See also: FullDrop, Shell32, Spool. Co-authored with Phil Weber.
Write Your Own Animation Control, COMponent Builder, January 1998
Construct a simple class that acts as an Animation control and supports playing both AVI files and resources. This technique allows you to distribute one less OCX with your application. 
Download original code sample. See also: AniCtrl.
Copy and Paste with RichTextBox, Ask the VB Pro, December 1997
Standardize your clipboard operations, including Undo, so the same routines work with either standard or rich Textbox controls. Learn about VB5's new Template offerings, and how they greatly expand on the older default project concept. (I always hated the name they changed this column to, with this issue, btw.)
Download original code sample. See also: ClipView, RMenu.
Display Text with Property Settings, Q&A, October 1997
Populate the standard Properties window, for your UserControl, with an enumerated list that contains values defined with spaces in their names. Or, use one of VB's standard enumerated types for your UserControl property settings. Extract all properties of an Access database field, including the field's Description. Use OLE Automation to manipulate Word documents. Decompiling an old VB3 application to recover the source, and coping with early VB version's binary file format.
Download original code sample.
Let Users Automate File Pasting, Q&A, September 1997
Rereading this article, it amazes me the name given to it by the editors. The guts of the first answer involve picking a window, hWnd actually, by dragging a cursor around on screen, similar to how Spy++ works. The final result being the ability to paste a text string from the clipboard into a foreign window. The second topic shows how to detect when a Listbox has been scrolled by subclassing and watching for WM_VSCROLL.
Download original code sample. See also: WndPick.
Name the Domain, Q&A, 1997 Enterprise Edition
Crack the secrets of calling the 'W' functions with String parameters, overcoming VB's inherent desire to convert all such data from Unicode to ANSI.  Functions such as NetWkstaGetInfo accept only Unicode parameters, but can by called from 32-bit VB by using byte arrays. Dereference Unicode string pointers with a custom PointerToStringW function. Avoid the dreaded "Invalid Use of Null" error with a simple precaution. Count by fives. Seemlessly tile a bitmap across a Form or Picture box.
Download original code sample. See also: CustomBlt, NetUser, NetWksta.
The Keys to Your Controls, Q&A, August 1997
Refer to and operate on any control or control array by name, by referencing its key within VB4's Controls collection. This technique makes possible generic routines that can iterate any control array, for example clearing an array of textboxes. Leverage the FindFirstFile API in a recursive function to ProperCase filenames and complete paths for more friendly display. Hand-edit references to comctl32.ocx in your VBP files to overcome "issues" associated with sharing source amongst developers using slightly different versions of this common control.
Download original code sample. See also: FileInfo.
Make the Most of Resources, Programming Techniques, January 1997
Learn how to start utilizing the new ability offered in VB4 to include resource files within your application. Some techniques shown include bundling an assortment of icons into the EXE which can be associated with the application, use embedded icons for simple animation with DrawIcon, and play WAV files directly from within your application. Also shown is a way to load a bitmap from your resource file into a memory-based device context (DC), and then tile it across the background of your form. An update on the SysTray technique presented in November 1996.
Download original code sample. See also: CustomBlt, ResDemo, Tray.
Stay in the Tray, Programming Techniques, November 1996
Learn the proper way to put your application in the system tray, and handle the notification messages sent to it through subclassing. Conserve system resources by storing icons in hidden Label controls. Find the directory Windows is using for temporary files.
Download original code sample. See also: Tray.
Unicode Strings You Along, Programming Techniques, September 1996
Avoid automatic conversion of String parameters to avoid corruption when calling "Wide" APIs. Determine whether you're running on Windows 95 or NT with the GetVersion API. Create a simple bar chart using an array of Label controls.
Download original code sample. See also: OpSys.
Out of Context, Programming Techniques, July 1996
Subclass the WM_CONTEXTMENU message to properly replace default context menus with your own customized offerings. Add Undo support to your Textbox and Richtext box controls. Restore a previously running instance of your application, rather than allow a new one to start. Define your own SysInt datatype which adapts its length to either 16- or 32-bits depending on what Windows platform your code is compiled for (shades of what Microsoft should have done rather than redefine the intrinsic Integer and Long datatypes for the .NET platform!). Overcome a bug in VB2 and VB3 that prevented you from updating the caption of a minimized MDI form at runtime.
Download original code sample. See also: RMenu, PrevInst.
Step up the pace of code-intense routines, First Looks, May 1996
A product review of PowerBasic's new PB/DLL product. They have since expanded the line into a full set of (Windows) 32-bit offerings, and I'm told to expect more platforms as time goes on. Definitely worth a look for BASIC devotees, as future directions are contemplated.
Chef's Surprise, Programming Techniques, May 1996
A potpourri of VB3 tips and tricks, published to offset the overwhelming balance of VB4 content in the remainder of the magazine this month, and a test for Unicode-induced String corruption. Keep a window minimized if it doesn't need to have an active interface, accept notification whenever the system colors are changed, and emulate the Sleep API in 16-bits. (This article is the first-known published use of the term "UniMess" as well, which was coined by yours truly during the VB4 beta as it became apparent that Microsoft had essentially broken billions of lines of binary data handling code with the redefinition of the fundamental String datatype.)
Download original code sample.
Don't Be Square, Programming Techniques, April 1996
There's no reason windows need to be rectangular. Learn how to make irregularly shaped windows with a few simply API calls. How's your trigonometry holding up? Remember how to calculate an (x,y) pair given an origin, distance, and direction? Restrict the cursor to a given rectangle onscreen to really frustrate your users! And finally, back in the (g)olden days of Classic VB, you could actually erase the Debug window from within your application.
Download original code sample. See also: WinRgn.
Making Progress, Programming Techniques, March 1996
Create a Progress Bar "control", using a class module which draws on a dedicated Picture box control, which will work in both 16- and 32-bit versions of VB4 (and later).
Download original code sample. See also: ProgBar.
Subclassing?, Programming Techniques, January 1996
Explore the new world of class module based subclassing, by wrapping the “Type-A-Matic” listbox technique shown in November 1995 into a conditionally-compiled Win16/Win32 drop-in ready class.
Download original code sample. See also: ListSearch.
Coercion Aversion, Programming Techniques, November 1995
In the new version of Visual Basic, watch out for ETC, unaffectionately known as “Evil Type Coercion.” Plus, build a “Type-A-Matic” listbox, that searches for entries as your user types. Find out whether a given executable file is currently running.
Download original code sample.
Playing the Shell Game, Programming Techniques, September 1995
Build a better Shell function, in order to know when the application you've started has finished (ie, "Shell and Wait"). Enumerate all the top-level windows in the system, in order to build a better AppActivate function by finding windows that start with or contain a given string. 
Download original code sample. See also: ListSearch.
Subclass Your Way Around VB's Limitations, Feature Article, September 1995
Venture beyond the customization capabilities of VB code by subclassing Windows messages. Find out how to do eight popular subclassing tasks:
  1. Showing statusbar information for menu commands
  2. Adding a command to a form's system menu
  3. Supporting drag-and-drop from File Manager
  4. Left-justify caption text
  5. Restricting a window's size range
  6. Painting the background of an MDI Form
  7. Drawing custom menu commands
  8. Hooking into the clipboard viewer chain
  9. Dynamically change menu width (Bonus!)
  10. Detect system color changes (Bonus!)
  11. Force an application to remain minimized (Bonus!)
  12. Prevent a window from being resized or moved (Bonus!)
Download original code sample, which included four bonus topics.
Article and code sample co-authored with Jonathan Wood
Creeping Versionitis, Programming Techniques, July 1995
Beginning the transition to 32-bits, this column shows how to determine whether your Win16 application is running under Windows 3.x or NT, thunking techniques from Win16 code to Win32 DLLs, and illustrates problems with the keyword IIf in VB3.
Download original code sample, which includes the CALL32.DLL library.