SelectObject fails during video colour change

Changing the number of colours on my video card in the Windows control panel causes a CDC::SelectObject( &CBitmap) call to fail in my application. The bitmap is created when my application starts up.

I assume the call fails because the new CDC has different settings to the one with which the bitmap was created & that the bitmap will need re-creating. Is there a neat way to handle this situation ?
daveb1Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
chensuConnect With a Mentor Commented:
You should process the WM_DISPLAYCHANGE message in your frame window.

ON_MESSAGE(WM_DISPLAYCHANGE, OnDisplayChange)

afx_msg LRESULT OnDisplayChange(WPARAM, LPARAM);
0
 
daveb1Author Commented:
Edited text of question.
0
 
daveb1Author Commented:
chensu,
I'm already processing the WM_DISPLAYCHANGE message - it seems that the CDC settings change before this message is despatched by Windows - any thoughts ?
Dave
0
 
chensuCommented:
You should not reuse CDC across Windows messages. Creating CDC on the stack should solve the problem.
0
All Courses

From novice to tech pro — start learning today.