Groups | Search | Server Info | Login | Register


Groups > comp.os.ms-windows.programmer.misc > #24

Re: Simplest possible C win32 app to draw line?

Newsgroups comp.os.ms-windows.programmer.misc
Date 2013-06-15 22:55 -0700
References <d0bc4f37-5302-496a-aab1-088c75262034@googlegroups.com>
Message-ID <0eac2ee9-502e-49c2-878c-77fe9103c46f@googlegroups.com> (permalink)
Subject Re: Simplest possible C win32 app to draw line?
From moosavi78@gmail.com

Show all headers | View raw


On Sunday, June 17, 2012 1:33:51 AM UTC+4:30, Dan Kegel wrote:
> What is the absolute simplest win32 program that draws a line in a window?
> 
> 
> 
> I tried
> 
> 
> 
> #include <windows.h>
> 
> int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpCmdLine, int nShowCmd)
> 
> {
> 
>     MSG msg;
> 
>     HWND hwnd;
> 
>     HDC hdc;
> 
>     RECT rect;
> 
>     WNDCLASS wc;
> 
> 
> 
>     ZeroMemory(&wc, sizeof(wc));
> 
>     wc.lpfnWndProc = DefWindowProc;
> 
>     wc.hInstance = hinst;
> 
>     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
> 
>     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
> 
>     wc.lpszClassName = "Foobar";
> 
>     RegisterClass(&wc);
> 
>     hwnd = CreateWindow(
> 
>         "Foobar",
> 
>         "Foobar",
> 
>         WS_OVERLAPPEDWINDOW,
> 
>         CW_USEDEFAULT, CW_USEDEFAULT,
> 
>         512, 512,
> 
>         NULL,
> 
>         NULL,
> 
>         hinst,
> 
>         0);
> 
>     hdc = GetDC(hwnd);
> 
>     GetClientRect(hwnd, &rect);
> 
>     FillRect(hdc, &rect, (HBRUSH) (COLOR_WINDOW+1));
> 
>     MoveToEx(hdc, 100, 100, NULL);
> 
>     LineTo(hdc, 200, 200);
> 
>     ReleaseDC(hwnd, hdc);
> 
>     ShowWindow(hwnd, nShowCmd);
> 
>     Sleep(5000);
> 
>     return 0;
> 
> }
> 
> 
> 
> but the window was not shown.  Is the problem that I
> 
> don't have a window proc?  I was hoping I could just
> 
> draw immediately without having to use the event system.
> 
> 
> 
> Thanks,
> 
> Dan

Try all those codes in a WP_PAINT message and create hdc with BeginPaint and Release HDC with EndPaint . this should work !

Back to comp.os.ms-windows.programmer.misc | Previous | NextPrevious in thread | Find similar


Thread

Simplest possible C win32 app to draw line? Dan Kegel <daniel.r.kegel@gmail.com> - 2012-06-16 14:03 -0700
  Re: Simplest possible C win32 app to draw line? moosavi78@gmail.com - 2013-06-15 22:55 -0700

csiph-web