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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

daveb1Author Commented:
Edited text of question.
0
chensuCommented:
You should process the WM_DISPLAYCHANGE message in your frame window.

ON_MESSAGE(WM_DISPLAYCHANGE, OnDisplayChange)

afx_msg LRESULT OnDisplayChange(WPARAM, LPARAM);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.