Thread: Brush color

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    162

    Brush color

    Hello
    Can you check my code I canīt find out what is wrong with it..

    Code:
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    HDC              hDC;
    PAINTSTRUCT      ps;
    HBRUSH           hGreenBrush;
    RECT             hRect;
            switch(message)
            {
              case WM_PAINT:
                   hGreenBrush = CreateSolidBrush(RGB(0,255,0));
                   hDC = BeginPaint(hWnd, &ps);
                   &hRect = Rectangle(hDC, 10,10,500,200);
                   FillRect(hDC, &hRect, hGreenBrush);
                   EndPaint(hWnd, &ps);
                   return 0;
              case WM_DESTROY:
              PostQuitMessage(0);
              return 0;
            }
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    There is supposed to be an error on the highlighted line. At least my compiler asserts it

    Dev-c++

    Thx for helping me

  2. #2
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Try using SetRect() instead of Rectangle().

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Quote Originally Posted by Queatrix View Post
    Try using SetRect() instead of Rectangle().
    Sorry does not work either... Should I change something else in the code, I am a beginner so I do not know the correct syntax of SetRect() exactly

  4. #4
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Like:
    Code:
    SetRect(&hRect, 10, 10, 500, 200);

  5. #5
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    Rectangle()'s return type is bool not RECT* therefore you cannot set &hRect equal to the return value of Rectangle(). You will have set the values of hRect yourself or use the function mentioned by Queatrix.
    Don't quote me on that... ...seriously

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    And DeleteObject the brush handle returned from CreateSolidBrush when you're done with it.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Thank you very much now it seems to work the way it should...

  8. #8
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    you named your variable hRect, but it's not a handle, so it should be just rect for example.

  9. #9
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Actually it really should be somthing like rcRect.

  10. #10
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    Quote Originally Posted by Queatrix View Post
    Actually it really should be somthing like rcRect.
    A variable name can start with an abbreviation of the type, but may also be just the struct name.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BRUSH PEN Color
    By arjunajay in forum Windows Programming
    Replies: 2
    Last Post: 08-27-2006, 09:06 PM
  2. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 06:23 PM
  3. egavga.bgi problem
    By sunil21 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-22-2003, 05:06 PM
  4. My opinion on skin color
    By Leeman_s in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 07-11-2003, 12:12 PM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM