I was wondering if such is possible in the unmanaged C++ code?
I'm writing a program that shows the current CPU usage on the system, but I observed that on some newer desktops when some lengthy hard drive operation is in process (say, like from a background backup process) the CPU usage stays very low (less than 10%) but the system is somewhat slow to use. So I was thinking to add to my program the current HDD usage on a system-wide scale, I'm just not sure what API to use for that.
You're looking for the "% Disk Time" performance counter. That indicates the (averaged) fraction of time that the disk is busy servicing requests. If it's close to 100%, then the CPU will probably be waiting a lot for I/O's to complete.
Another option is the "Current Disk Queue Length". That indicates how many requests are pending, which in turn is a measure of the excess operations (operations issued - operations completed). If there are zero pending operations in the queue, the CPU is not waiting for the disk; if there are tons, then the CPU has nothing to do.
Of course, if there are low-priority CPU-cound threads, then those will still run while the higher-priority threads are waiting for I/O. Windows won't waste CPU time just because the disk is busy.