Question About Line Drawing with Messaging

This is a discussion on Question About Line Drawing with Messaging within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm new to windows programming, and I'm trying to make it draw lines to wherever the user clicks. Right ...

  1. #1
    Unregistered
    Guest

    Question Question About Line Drawing with Messaging

    Hi, I'm new to windows programming, and I'm trying to make it draw lines to wherever the user clicks. Right now I have this, and it works, but I think there must be a better way to send the message to WM_PAINT than passing -1 as the wParam.

    -----------

    switch (message)
    {
    case WM_PAINT:
    BeginPaint(hWnd, &ps);
    hdc = GetDC(hWnd);
    if(wParam == -1)
    LineTo(hdc, LOWORD(lParam), HIWORD(lParam));
    EndPaint(hWnd, &ps);
    break;

    case WM_LBUTTONDOWN:
    PostMessage(hWnd,WM_PAINT,-1,lParam);
    break;

    case WM_DESTROY:
    PostQuitMessage(0);
    break;

    default:
    return DefWindowProc(hWnd, message, wParam, lParam);
    }

    -------

    Thanks!

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    first watch the GetXX() and CreateXX() functions as they allocate GDI memory.

    All GetXX() must have a ReleaseXX()
    All CreateXX() must have a DeleteXX()

    Use
    Code:
    hdc=BeginPaint(hwnd,&ps);//or use the one in the ps struct
    if(wParam == -1) 
       LineTo(hdc, LOWORD(lParam), HIWORD(lParam)); 
    EndPaint(hwnd,&ps);
    Does this have a problem drawing the line in the right spot if the window is not full screen?
    Does the line stay there always?

    Where is the call to to set the pen pos before LineTo() (especially on the first drawing of the line)
    MoveToEx(hdc,XCood,YCood,(LPPOINT)NULL);


    To send a paint msg you can use
    InvalidateRect() or UpdateWindow() or RedrawWindow()

    You should create a compatible DC, bitmap ect and draw to it. Then BitBlt() this HDC to your 'hdc' in response to a WM_PAINT.
    Use GetUpdateRect() before your WM_PAINT to find the area that needs redrawing.

    (try a search here as there is lots of code on paint functions posted)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Unregistered
    Guest
    Ok thanks. But that doesn't mean I need DeleteWindowEx() because of my CreateWindowEx() does it?

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    No, The DestroyWindow() should cover that.

    Only for the GDI functions inc Create* / Get

    (Font, brush, pen, bitmap and DC.)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing a line
    By Homunculus in forum Windows Programming
    Replies: 6
    Last Post: 03-19-2006, 03:32 PM
  2. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM
  3. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  4. Drawing a line on the screen
    By Leano in forum C++ Programming
    Replies: 3
    Last Post: 01-31-2003, 08:24 PM

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