[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

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?


0
List244
Asked:
List244
  • 4
  • 4
1 Solution
 
jkrCommented:
Where are you using the above? That should be within your Window procedure, to be more precise, when handling WM_PAINT.
0
 
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.
0
 
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);
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

Great that you got it working.
0
 
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.
0
 
jkrCommented:
*crossing fingers* ;o)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now