user2695082
user2695082

Reputation: 329

Get QColor from unsigned long (COLORREF) without including windows.h

I have a project where I need to use an API which expects COLORREF and another API which returns COLORREF. COLORREF is MFC and my project Qt does not want to use any trace of MFC code. COLORREF is nothing but unsigned long eventually, so I hope there could be a solution.

So there are 2 problems:

Upvotes: 0

Views: 1193

Answers (1)

Sami Kuhmonen
Sami Kuhmonen

Reputation: 31193

Since COLORREF is just a DWORD organized as 0x00bbggrr, you can easily convert it to components and construct a QColor out of it.

int r = color & 0xff;
int g = (color >> 8) & 0xff;
int b = (color >> 16) & 0xff;
QColor qc(r, g, b);

Upvotes: 3

Related Questions