Drawing a line on the screen

This is a discussion on Drawing a line on the screen within the C++ Programming forums, part of the General Programming Boards category; I am trying to simply draw a line on to a small window. (as the form.canvas.drawline() function would do in ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    2

    Drawing a line on the screen

    I am trying to simply draw a line on to a small window.
    (as the form.canvas.drawline() function would do in Delphi).

    I am using MS VC++ 6 and am developing on Win 2K

    So far I have:

    #include <afxwin.h>

    const char *szWndClass = "DrawLine";
    const char *szProgramName = "Draw Line";

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {

    WNDCLASS wc;
    HWND hWnd;
    MSG msg;
    HRESULT hr;
    HDC hDC;

    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = MsgProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH )GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = szWndClass;
    RegisterClass(&wc);

    hWnd = CreateWindowEx(WS_EX_TOPMOST,
    szWndClass, szProgramName,
    WS_OVERLAPPEDWINDOW, 0, 0,
    320, 240, NULL, NULL, hInstance,
    NULL);

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    hDC = GetDC(hWnd);

    hDC.MoveTo(10,10);
    hDC.LineTo(100,100);
    .
    .
    .

    When I try to compile this, it thows up an error that the right of MoveTo and LineTo must point to class/struct/union.

    I don't need to do anything more than draw a few lines on the screen and it doesn't have to be fast so would rather not get in to OpenGL or DirectDraw if possible.

    Thank you

  2. #2
    Registered User Anarchist's Avatar
    Join Date
    Jan 2002
    Posts
    12
    In the book I learnt from it shows
    MoveToEx(hdc, 20, 10, NULL)
    and
    LineTo(hdc, 100, 100)

    I asssume the MoveTo would work the same as the Line to

    I know these worked on NT XP and 98 so I assume they should work with 2000 aswell

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    2
    8 minutes after I posted my problem, and it works perfectly!

    Now that's what I call service

    Thanks a lot

  4. #4
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    gotta love the CBoard!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to do encryption in C
    By sankarv in forum C Programming
    Replies: 33
    Last Post: 12-28-2010, 10:01 AM
  2. OpenGL Linux Line Drawing Problem
    By swanley007 in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2006, 09:31 AM
  3. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  4. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 03:56 PM
  5. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 03:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21