Drawing with buttons

This is a discussion on Drawing with buttons within the Windows Programming forums, part of the Platform Specific Boards category; ok, i am a newb at drwing in win32 and i did look through the forum for this but didnt ...

  1. #1
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120

    Drawing with buttons

    ok, i am a newb at drwing in win32 and i did look through the forum for this but didnt really know how to say it so here goes:

    i want to be able to have the user click a button that i create and have it draw using setpixel the stuff that i have set up for it but when it do it like this
    Code:
    case WM_PAINT:
    {
        hdc = BeginPaint(hwnd,&ps);
        for(j=0;j<256;j++)
        {
            for(k=0;k<256;k++)
            {
                SetPixel(hdc,j,k,RGB(0,j,k));
            }
        }
        Arc(hdc,100,100,200,200,100,130,100,130);
        EndPaint(hwnd,&ps);
        break;
    }
    case WM_COMMAND:
    {
        switch(LOWORD(wParam))
        {
            case IDC_BUTTON_IMAGE1:
            {
                for(j=0;j<256;j++)
                {
                    for(k=0;k<256;k++)
                    {
                        SetPixel(hdc,256+j,256+k,RGB(0,j,k));
                    }
                }        
                Arc(hdc,200,200,300,300,100,100,200,200);
                break;
            }
        }
        break;
    }
    only the first part goes, the second part i just get a warning saying
    Code:
    C:\Documents and Settings\me\Desktop\drawing example\main.cpp(108) : warning C4700: local variable 'hdc' used without having been initialized
    I know that i am doing something completely wrong but i do not know what it is?

    any help? am i totally lost? i looked in a bunch of tutorials but i couldnt seem to find any help in them...and i dont have the cash to lay out for the book by charles petzold that goes through all the api stuff

    any thought?
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  2. #2
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    Code:
    case WM_COMMAND:
    {
        switch(LOWORD(wParam))
        {
            case IDC_BUTTON_IMAGE1:
            {
                hdc = GetDC(//Handle to window in here//)             
                 for(j=0;j<256;j++)
                {
                    for(k=0;k<256;k++)
                    {
                        SetPixel(hdc,256+j,256+k,RGB(0,j,k));
                    }
                }        
                Arc(hdc,200,200,300,300,100,100,200,200);
                break;
            }
        }
        break;
    You need to get the device context for your client area before you can draw on it.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  3. #3
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    GREAT!! thanks, i knew i was forgetting something
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  4. #4
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    Just remember to release it once you are done with it by calling ReleaseDC(). So in your case:
    Code:
    case WM_COMMAND:
    {
        switch(LOWORD(wParam))
        {
            case IDC_BUTTON_IMAGE1:
            {
                hdc = GetDC(/*Handle to window in here*/) ; 
                 for(j=0;j<256;j++)
                {
                    for(k=0;k<256;k++)
                    {
                        SetPixel(hdc,256+j,256+k,RGB(0,j,k));
                    }
                }        
                Arc(hdc,200,200,300,300,100,100,200,200);
                ReleaseDC(/*Handle to window in here*/,hdc);
                break;
            }
        }
        break;
    Last edited by Dohojar; 09-12-2003 at 02:33 PM.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 04-09-2009, 02:31 AM
  2. Slow drawing code
    By tjpanda in forum Windows Programming
    Replies: 5
    Last Post: 05-09-2008, 05:09 PM
  3. Ownerdraw buttons (2)
    By maes in forum Windows Programming
    Replies: 7
    Last Post: 09-11-2003, 05:50 AM
  4. couple of questions on drawing text and buttons
    By Leeman_s in forum Windows Programming
    Replies: 3
    Last Post: 12-28-2002, 10:45 AM
  5. Grouping radio buttons
    By Bazz in forum Windows Programming
    Replies: 1
    Last Post: 08-28-2001, 07:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21