How to add color picker into visual c++ MFC and dialog

Here you can talk about C++ And C# And Other languages programming.

How to add color picker into visual c++ MFC and dialog

Postby method » Thu Jul 06, 2006 3:21 pm


could any one tell me step by step how to add color picker to my MFC and dialog project?Thanks
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby BattleStar-Galactica » Thu Jul 06, 2006 5:58 pm

are you learning mfc too :?:




try this


CColorDialog dlg;
if (dlg.DoModal() == IDOK)
m_edit.SetBackColor(dlg.GetColor());

this is a example to set background color of my edit control(m_edit)
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby method » Fri Jul 07, 2006 2:25 am

nanomachine007 thank u for u reply. But i want be able to select any color i want, just like the attached pic.

yes i want to learn this c++ i find it more powerfull . Could u explain to me exactly how to add it to my project. I also want the color iteslf and it code appers in picture box and textbox.Thanks
Attachments
color.JPG
color.JPG (9.73 KiB) Viewed 9754 times
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby BattleStar-Galactica » Fri Jul 07, 2006 3:36 am

are you trying that code i posted. that code product the result look like the pic. a popup color dialog. it's not really like your pic but i just can show u like that, i am newbie too for mfc.
Attachments
pickupcolor.jpg
pickupcolor.jpg (35.23 KiB) Viewed 9751 times
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby method » Fri Jul 07, 2006 3:43 am

Thanks man but where should i place the code ? i created a button and placed it inside and nothing worked!!

Let me know what other refrences and controles do i need. I want to get the color code and use it later and also display both color and color code in picture box and text box but u never mentioned how !!!

AS u new i am new to this visual c++ so let me know step by step how to make your code work for my purpuse.Thanks
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby BattleStar-Galactica » Fri Jul 07, 2006 3:48 am

dlg.GetColor();

that's line get return color structure, check help online about CColorDialog and you will find your answer.

that's code i put it in a button click
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby method » Fri Jul 07, 2006 3:56 am

nanomachine007 wrote:dlg.GetColor();

that's line get return color structure, check help online about CColorDialog and you will find your answer.

that's code i put it in a button click



2 errors both pointing at :

m_edit.SetBackColor(dlg.GetColor());

Could also tell me how to make .exe out of this project so i be able to use it without visual studio or sending it to some one.?


Error:

Code: Select all
--------------------Configuration: color1 - Win32 Debug--------------------
Compiling...
color1Dlg.cpp
C:\color\color1\color1Dlg.cpp(205) : error C2065: 'm_edit' : undeclared identifier
C:\color\color1\color1Dlg.cpp(205) : error C2228: left of '.SetBackColor' must have class/struct/union type
Error executing cl.exe.

color1.exe - 2 error(s), 0 warning(s)
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby BattleStar-Galactica » Fri Jul 07, 2006 4:07 am

man the m_edit is a instance of my class derived from CEdit. I have created a CCustomEdit derived from CEdit blablablabal and my m_edit is an instance of CCustomeEdit blablabla.

I just show u how to make popup color dialog.


you dont need m_edit and i think loco forum is not really for mfc lol


CColorDialog dlg;
if (dlg.DoModal() == IDOK)
yourcolorpickuphere=dlg.GetColor();

I cannot give u step by step i just can give u a hint or tips man. it's too long step by step.
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby method » Fri Jul 07, 2006 4:11 am

nanomachine007 wrote:man the m_edit is a instance of my class derived from CEdit. I have created a CCustomEdit derived from CEdit blablablabal and my m_edit is an instance of CCustomeEdit blablabla.

I just show u how to make popup color dialog.


you dont need m_edit and i think loco forum is not really for mfc lol


CColorDialog dlg;
if (dlg.DoModal() == IDOK)
yourcolorpickuphere=dlg.GetColor();

I cannot give u step by step i just can give u a hint or tips man. it's too long step by step.


man i just used this line inside button click event and nothing happend!!

CColorDialog dlg;

just show me how to make the color selectrd pops up and if i do selection it puts that color code inside a variable. That is all i want for now .
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby BattleStar-Galactica » Fri Jul 07, 2006 4:17 am

// Get the selected color from the CColorDialog.
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
{
COLORREF color = dlg.GetColor();

}




try that code in a button click dude, and i think u must go to codeproject.com to learn mfc
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby method » Fri Jul 07, 2006 4:37 am

nanomachine007 wrote:// Get the selected color from the CColorDialog.
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
{
COLORREF color = dlg.GetColor();

}




try that code in a button click dude, and i think u must go to codeproject.com to learn mfc


Thanks man . Now it pops up the color selecter but i can not use the value of color ? it keeps telling me the value is not defined when using the value of color inside send massage!! I need to get the color code after selection of color and use it inside send massage.Also how to make .exe out of this? I know i need lots of work in visual c++ i will go to that site from now one.


error:

Code: Select all
--------------------Configuration: color1 - Win32 Debug--------------------
Compiling...
color1Dlg.cpp
C:\color\color1\color1Dlg.cpp(247) : error C2065: 'color' : undeclared identifier
Generating Code...
Compiling...
color1.cpp
Generating Code...
Error executing cl.exe.

color1.exe - 1 error(s), 0 warning(s)
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby BattleStar-Galactica » Fri Jul 07, 2006 9:51 am

have you ever make a setup file with vb.net, it's the same. in mfc when u buidl your project, it build automatic .exe file extension no???

to use COLORREF, you should include this header into your project Windows.h


in c++ is not the same in vb6, you have to include the header file necessary for what you want to use. but if u check help u should know it, cuz normally they tell u object name and object members and what file header should be included to your project to use that object.

read more hehehhe, i learn new thing just read the documentation. read and read it's my advance
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby Dody » Sat Jul 08, 2006 4:57 am

very shortly and very easy, download a new colorpicker class, include it in your project folder, add the .cpp and .h files into your workspace, and change the class of your button into the new class, of course with creating a new member variable, and you will be done... the picture you attached was an old program I made, and this is how I did it... so good luck
User avatar
Dody
imFiles Senior
imFiles Senior
 
Posts: 177
Joined: Tue Jan 04, 2005 2:44 pm


Return to C++, C# And Others Programming

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 0 guests