Rather than checking the clipboard content in a loop, use one of the methods mentioned in the Microsoft documentation:
Monitoring Clipboard Contents | Using the Clipboard - Win32 apps | Microsoft Learn[
^]
The simplest option would appear to be calling
GetClipboardSequenceNumber[
^], which will return an integer that will be incremented each time the clipboard contents change. However, the docs do say that
"this is a not a notification method and should not be used in a polling loop".
To receive a notification, the recommended approach is to call
AddClipboardFormatListener[
^] to register your window as a "format listener", which will receive a
WM_CLIPBOARDUPDATE
message whenever the contents of the clipboard have changed. You will also need to call
RemoveClipboardFormatListener[
^] when your window closes.
The older approach of creating a "clipboard viewer" window is no longer recommended, and should only be used if you need to support systems older than Windows Vista. It's much more fiddly to set up, easy to get wrong, and liable to breaking the clipboard functionality completely, requiring a reboot.