We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Create window; drawing.

List244
List244 asked
on
Medium Priority
238 Views
Last Modified: 2010-04-01
Hi, I have a window I created with CreateWindow.  I am trying now to draw to this without using any sort of
additional controls.  However, I do not know how to get the drawings to appear properly. For example, I have:

DeleteObject(Brush);
Brush = CreateHatchBrush(0,RGB(255,0,0));
SelectObject(GetDC(Window),Brush);
Rectangle(GetDC(Window),0,0,200,200);

This is appearing white, what am I doing wrong?


Comment
Watch Question

jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
Where are you using the above? That should be within your Window procedure, to be more precise, when handling WM_PAINT.

Author

Commented:
I am using then above in WM_Paint:

            case WM_PAINT:
                  Draw(&Window);
                  DeleteObject(Brush);
                  Brush = CreateSolidBrush(RGB(255,0,0));
                  DC = GetDC(Window);
                  SelectObject(GetDC(Window),Brush);
                  for (a=0;a<3;a++)
                  {
                        for(b=0;b<3;b++)
                        {
                              Rectangle(DC,b*100,a*100,(b*100)+100,(a*100)+100);      
                        }
                  }
                  ReleaseDC(Window,DC);
                  return DefWindowProc(Window, Message, WParam, LParam);
                  break;

All rectangles are drawn however, white.
CERTIFIED EXPERT
Top Expert 2012
Commented:
Hm, that should be more like

PAINTSTRUCT ps;
HBRUSH hOld;

          case WM_PAINT:
               Draw(&Window);
               Brush = CreateSolidBrush(RGB(255,0,0));
               DC = BeginPaint(Window,&ps);
               hOld = SelectObject(DC,Brush);
               for (a=0;a<3;a++)
               {
                    for(b=0;b<3;b++)
                    {
                         Rectangle(DC,b*100,a*100,(b*100)+100,(a*100)+100);    
                    }
               }
               SelectObject(DC,hOld);
               DeleteObject(Brush);
               EndPaint(Window,&ps);
               ReleaseDC(Window,DC);
               return 0;
               break;

          default:

                return DefWindowProc(Window, Message, WParam, LParam);

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
That works, one more question though, how can I make it draw without having to drag the window
off of the screen for refresh?

Author

Commented:
Got that working, thanks.
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
Sorry for not responding, but evry once in a while I need to eat ;o)

Great that you got it working.

Author

Commented:
Yeah, had slight trouble with invalidaterect, found it needs to be before drawing, not after. All working good now.
Just a few minor AI changes and my program will be working great.
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
*crossing fingers* ;o)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.