Thread: Polygon

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    932

    Polygon

    What am i doing wrong with this function?
    I get an error on the DeleteObject() line. Why would it want to convert it to int.

    Code:
    void DrawPolygon (HWND hwnd, HDC hdc)
         
         int          i ;
         POINT        apt[10] ;
         static POINT aptFigure [10] = { 10,70, 50,70, 50,10, 90,10, 90,50,
                                         30,50, 30,90, 70,90, 70,30, 10,30 };
    
    
         HBRUSH hbr = CreateSolidBrush (RGB (rand () % 256, rand () % 256, rand () % 256)) ;
         HBRUSH hOld = (HBRUSH) SelectObject (hdc,hbr);
         for (i = 0 ; i < 10 ; i++)
              {
                   apt[i].x = cxClient * aptFigure[i].x / 200 ;
                   apt[i].y = cyClient * aptFigure[i].y / 100 ;
              }
    
         SetPolyFillMode (hdc, ALTERNATE) ;
         Polygon (hdc, apt, 10) ;
    
         for (i = 0 ; i < 10 ; i++)
              {
                   apt[i].x += cxClient / 2 ;
              }
    
         SetPolyFillMode (hdc, WINDING) ;
         Polygon (hdc, apt, 10) ;
         SelectObject (hdc,hOld) ;
         DeleteObject (hbr) ; //cannot convert from 'HBRUSH' to 'int'
            There is no context in which this conversion is possible
    
    Using Windows 10 with Code Blocks and MingW.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Usually you see that message when no prototype for the function is in scope; that seems unlikely here since it didn't complain about anything else. Small comfort, but (after adding windows.h and braces around the whole function) I couldn't get that error.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That does look right to me.

    Further, a copy'n'paste of your code [with some minor fixups] compiles correctly in gcc-mingw 3.4.5

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    What a dork! I forgot the curly braces!

    Thank you guys!
    Using Windows 10 with Code Blocks and MingW.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    One more thing that i dont understand please.

    Code:
    static POINT aptFigure [10] = { 10,70, 50,70, 50,10, 90,10, 90,50,
                                         30,50, 30,90, 70,90, 70,30, 10,30 };
    How can you give two values for one element of the array?
    Finally its not a multidimensional array like
    Code:
    static POINT aptFigure [10] [10]
    I cant find any reference to it in tutorials.
    Using Windows 10 with Code Blocks and MingW.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    POINT is a struct that contains two elements (you know that -- you've used the .x and .y fields in the bit above). So the first element is aptFigure[0].x, the next is aptFigure[0].y, then aptFigure[1].x, and so on. (For clarity, I would recommend putting each pair of numbers inside its own set of curly braces, but as you can see it's not strictly required.)

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Thank you Tabstop, i get it now.
    Using Windows 10 with Code Blocks and MingW.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And it should really look like this:
    Code:
         static POINT aptFigure [10] = { {10,70}, {50,70}, {50,10}, {90,10}, 
    				     {90,50}, {30,50}, {30,90}, {70,90}, 
    				     {70,30}, {10,30} };
    When compiling using gcc -Wall, it actually warns when the braces are missing [the point being that it's hard to tell what is what].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Point in polygon test - spherical coords
    By bhdz in forum C Programming
    Replies: 1
    Last Post: 11-07-2007, 01:25 PM
  2. help how to make polygon
    By gamett711221 in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2005, 08:33 PM
  3. my polygon class
    By ichijoji in forum Game Programming
    Replies: 5
    Last Post: 08-02-2004, 08:42 AM
  4. Polygon problem
    By kiss_psycho in forum C++ Programming
    Replies: 0
    Last Post: 10-13-2003, 03:51 PM
  5. IDEA: Polygon unions and intersections
    By Magos in forum Contests Board
    Replies: 3
    Last Post: 05-21-2003, 07:16 PM