Create window; drawing.

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?


LVL 8
List244Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Where are you using the above? That should be within your Window procedure, to be more precise, when handling WM_PAINT.
List244Author 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.
jkrCommented:
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);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

List244Author 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?
List244Author Commented:
Got that working, thanks.
jkrCommented:
Sorry for not responding, but evry once in a while I need to eat ;o)

Great that you got it working.
List244Author 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.
jkrCommented:
*crossing fingers* ;o)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.