Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

BuddyLee

Changing the color of Rectangles

This topic is 5653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
If you are doing some coding in win32 you could change the color of the rectangle by creating a brush with a different color. For the outline create a pen with a color of choice. check out
www.gametutorials.com and www.winprog.org for tutorials


      
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
static HPEN myPen, old_pen;
static HBRUSH myBrush;
HDC hdc;
PAINTSTRUCT ps;

switch (message)
{
case WM_CREATE:
mypen = CreateSolidPen(PS_SOLID, 1, RGB(0,0,255));//blue pen

myBrush = CreateBrush(RGB(0,255,0));//green brush

return 0;

case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
old_pen =(HPEN)SelectObject(hdc, myPen);
Rectangle(hdc, 50, 50, 100, 100);
SelectObject(hdc, myBrush);
Rectangle(hdc, 200, 200, 250, 250);

EndPaint(hwnd,&ps);
return 0;

case WM_DESTROY:
DeleteObject(myPen);
DeleteObject(SelectObject(hdc, old_pen));
PostQuitMessage(0);
return 0;
}

return DefWindowProc(hwnd, message, wParam, lParam);
}




-----------------------------
"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."



[edited by - cMADsc on April 2, 2003 5:31:36 PM]

[edited by - cMADsc on April 2, 2003 5:34:13 PM]

Share this post


Link to post
Share on other sites
I went back and edited the code, now myPen and myBrush are both deleted. old_pen is what is initially in the hDC, just restoring it.


-----------------------------
"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."

Share this post


Link to post
Share on other sites
Also the functions are:

CreatePen(int, int, COLORREF)
CreateSolidBrush(COLORREF)

You got the names mixed up.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!