Pelles C forum

C language => Beginner questions => Topic started by: jcarr on September 02, 2007, 11:40:50 AM

Title: Get just B as int from RGB??
Post by: jcarr on September 02, 2007, 11:40:50 AM
What i am doing is opening a choosecolor() dialog then from the colour the user selects i want to just pick out the BLUE value, and convert it to a integer...

Can someone help?
This is what i have so far...:
Code: [Select]
CHOOSECOLOR cc;
COLORREF done;
cc.lStructSize = sizeof(CHOOSECOLOR);
cc.hwndOwner = hwnd;
cc.rgbResult = done;
cc.Flags = CC_SOLIDCOLOR;

ChooseColor(&cc);

Thanks in advance

~~Jden
Title: Re: Get just B as int from RGB??
Post by: TimoVJL on September 02, 2007, 12:13:20 PM
With macro:
Code: [Select]
BYTE b = GetBValue(done);
Title: Re: Get just B as int from RGB??
Post by: jcarr on September 03, 2007, 06:50:04 AM
Hmmm... ok i see what you mean... Am i able to then say multiply thay number as a BYTE? or do i have to convert first to INT..??

~~Jden
Title: Re: Get just B as int from RGB??
Post by: frankie on September 03, 2007, 10:20:40 AM
Just store the result in a int variable and the compiler will automatically converti it to int.
Title: Re: Get just B as int from RGB??
Post by: jcarr on September 03, 2007, 11:28:23 PM
Ok thanks ill try it and if it doesnt work, im right back here :P

~~Jden/Zyotah
Title: Re: Get just B as int from RGB??
Post by: jcarr on September 03, 2007, 11:33:58 PM
Code: [Select]
CHOOSECOLOR cc;
COLORREF done;
cc.lStructSize = sizeof(CHOOSECOLOR);
cc.hwndOwner = hwnd;
cc.rgbResult = done;
cc.Flags = CC_SOLIDCOLOR;

ChooseColor(&cc);

//BYTE b = GetBValue(done);
int b = GetBValue(done);
char f[10];
_itoa(b, f, 10);
notice(f);
That is what i put in... No matter what colour i choose, 'b' and 'f' become 0...
btw notice(char) is just a shorter messageboxa() function i made... its not thats the porb :P

~~Jden
Title: Re: Get just B as int from RGB??
Post by: TimoVJL on September 04, 2007, 06:28:19 AM
b = GetBValue(cc.rgbResult);
Title: Re: Get just B as int from RGB??
Post by: jcarr on September 07, 2007, 03:30:06 AM
So now that that works... i have run into a problem with the CHOOSECOLOR dialog. When i hit 'Ok' it comes up with that message that it has to close, sorry for the BEEPING inconvenience.... :P
heres me code:
Code: [Select]
CHOOSECOLOR cc;
cc.lStructSize = sizeof(CHOOSECOLOR);
cc.hwndOwner = hwnd;
cc.Flags = CC_SOLIDCOLOR| CC_FULLOPEN;
ChooseColor(&cc);
notice("done");

That "done" notice never appears... It errors right before that...

~~Jden
Title: Re: Get just B as int from RGB??
Post by: MikeH on September 08, 2007, 01:47:58 AM
Try adding:

static COLORREF custcolors[16];
cc.lpCustColors = custcolors;
Title: Re: Get just B as int from RGB??
Post by: jcarr on September 09, 2007, 11:17:00 AM
Thanks it works now