Groups | Search | Server Info | Login | Register


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

Simplest possible C win32 app to draw line?

From Dan Kegel <daniel.r.kegel@gmail.com>
Newsgroups comp.os.ms-windows.programmer.misc
Subject Simplest possible C win32 app to draw line?
Date 2012-06-16 14:03 -0700
Organization http://groups.google.com
Message-ID <d0bc4f37-5302-496a-aab1-088c75262034@googlegroups.com> (permalink)

Show all headers | View raw


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

Back to comp.os.ms-windows.programmer.misc | Previous | NextNext 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