Skip to content

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

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #191469
    method
    Member

    could any one tell me step by step how to add color picker to my MFC and dialog project?Thanks

    #191481

    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)

    #191480
    method
    Member

    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

    #191479

    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.

    #191478
    method
    Member

    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

    #191477

    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

    #191476
    method
    Member

    @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:

    
    
    Configuration: color1 - Win32 Debug
    Compiling...
    color1Dlg.cpp
    C:colorcolor1color1Dlg.cpp(205) : error C2065: 'm_edit' : undeclared identifier
    C:colorcolor1color1Dlg.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)
    #191475

    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.

    #191474
    method
    Member

    @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 .

    #191473

    // 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

    #191472
    method
    Member

    @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:

    
    
    Configuration: color1 - Win32 Debug
    Compiling...
    color1Dlg.cpp
    C:colorcolor1color1Dlg.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)
    #191471

    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

    #191470
    Dody
    Member

    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

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.