Changing the color of Rectangles
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
-----------------------------
"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]
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]
it seems to me in your code you only deleted 1 of the 2 objects you created can you explain this?
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."
-----------------------------
"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."
Also the functions are:
CreatePen(int, int, COLORREF)
CreateSolidBrush(COLORREF)
You got the names mixed up.
CreatePen(int, int, COLORREF)
CreateSolidBrush(COLORREF)
You got the names mixed up.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement