Three Ways to Find Files

Let’ say we have to implement a function that search a folder to recursively find files having an extension from a given list of extensions. This article shows three possible implementations: one using FindFirstFile and FindNextFile WinAPI functions, one using CFileFind MFC class and one using Filesystem Library. Find files using FindFirstFile and FindNextFile WinAPI … Read more

How to Get Visual C++ Sample Projects (2)

In a previous article I showed how to get Visual C++ sample projects either by using Visual Studio IDE or by downloading from MSDN – Developer Code Samples site. Recently, I found that we can also download an archive containing a very large number of sample projects from GitHub. Pretty cool! Here is the magic … Read more

Codexpert – 2014 Articles Summary

Microsoft Libraries Multiple-View File Explorer Shows how to easily make a Windows file manager with multiple views by using MFC framework and IExplorerBrowser interface. MFC Support for Direct2D – Part 1 Using the MFC D2D classes for making a simple image viewer. MFC Support for Direct2D – Part 2 Demonstrates how to easily make a … Read more

How to Check the Windows Version

Let’s say we have to check if our application is running under Windows 8.1 or newer. A “classic” way, often found in legacy code, is to call GetVersion or GetVersionEx. Using GetVersion // Example 1 inline BOOL IsWindows_81_Or_Newer() { DWORD dwVersion = ::GetVersion(); WORD wMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); WORD wMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); return (wMajorVersion >= 6) && … Read more

Tree-View Control – TVS_EX_RICHTOOLTIP style

Windows Vista introduced a buch of extended styles for tree-view control (SysTreeView32). Among them, there is TVS_EX_RICHTOOLTIP style which is described in MSDN documentation as follows: “Allow rich tooltips in the tree view (custom drawn with icon and text)”. This article shows a little bit more about how to set and which is the effect of using this extended style. … Read more

Listing Windows Known Folders

If the target system is Windows Vista, Windows Server 2008 or newer, enumerating known folders (formerly known as special folders) like Desktop, Documents, Program Files, etc is quite easy by calling GetFolderIds method of IKnownFolderManager interface. It gets an array of all registered known folder IDs (KNOWNFOLDERID). Once having a folder ID, we can call IKnownFolderManager::GetFolder … Read more

Codexpert – 2013 Articles Summary

C++ Language and STL <filesystem> header in Visual Studio 2012 Shows sample usage of filesystem header, new to VS2012, that defines types and functions for working with files and folders. C++11 concurrency: threads An introduction to threads support in C++11. C++11 concurrency: locks A walk through the synchronization mechanism for multi-threading provided by C++11. C++11 … Read more

Listing Processes – Part 5: Using Windows Management Instrumentation (WMI)

Using Win32_Process WMI class A previous article shows how to use Win32_PhysicalMedia WMI class to get physical drive info. We can write something similar for getting a list of running processes. All we have to do is to replace the WQL query and get specific properties for Win32_Process. However, to simplify the things, I wrote … Read more

Listing Processes – Part 4: Using Remote Desktop Services API

Using Remote Desktop Services API We can call WTSEnumerateProcesses function to get information about the active processes on a specified Remote Desktop Session Host server. However, if pass WTS_CURRENT_SERVER_HANDLE in first argument (server handle), we can enumerate and get info about processes which are running on local machine. The following example calls WTSEnumerateProcesses function, then … Read more

Listing Processes – Part 3: Using Tool Help Library

Tool Help Library makes it easy to enumerate and get info about processes, threads, modules, and heaps. Let’s use it to get a list of running processes. Using Tool Help Library First, take a snapshot by passing TH32CS_SNAPPROCESS flag to CreateToolhelp32Snapshot function. Next, pass the snapshot handle to Process32First, then to Process32Next to get running processes … Read more