You can listen for WM_SETTINGCHANGE
notification messages. The MSDN documentation is a little sparse, but the sample code from the documentation of SetDefaultPrinter
makes it clear that a WM_SETTINGCHANGE
message should be broadcast by any party that modifies the default printer.
Unfortunately the WM_SETTINGCHANGE
does not include any information that allows you to determine whether or not the default printer has been changed. You've no way of knowing whether or not a particular WM_SETTINGCHANGE
message indicates change of default printer or indicates change of some other setting.
However, I would question your belief that you should be responding to this message. Consider the following scenario:
- You have a machine with two printers, A and B.
- Printer A is the default printer.
- Application starts.
- User prints, but selects printer B.
- User prints again. Program remembers that last time round the user wanted printer B. But this time user wants printer A and so changes to that printer.
- User then changes default printer to printer B in control panel.
- User goes to print again. Which printer should be offered to the user?
The thing is the application has a history. The last time the user printed they explicitly selected printer A. Why should a change to the default printer mean that next time round the application should offer the new default printer rather than the last printer that the user chose to use?