Thread: Drawing a line

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    Drawing a line

    How do I do this? I can draw a rectangle but not a line x.x Also how would I go about drawing half of a circle.

    EDIT:

    Also, how would I make my embedded bitmap rotate x.x
    Last edited by Homunculus; 03-18-2006 at 10:10 PM.

  2. #2
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    Are you using the GDI?

    Link

    Link2
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    thx

    Ok, now using the POINT structure, how would I specify current position?

    If you know a good set of tutorials on doing this stuff , please direct me=P im programming in pure win32 api. Meaning no MFC etc.

  4. #4
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Set your starting point:-
    MoveToEx(hdc, x, y, NULL);

    GO!
    LineTo(hdc, x2, y2);

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    71
    ok thanks =P, now how do I make my embedded bitmap rotate? would I have to mix opengl and bind textures and crap?

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    also

    I have want to have it draw when I click a button, I will show what I've done:

    Code:
                     switch(GET_WM_COMMAND_ID(wParam,lParam))
                     {
                         case BUTTON123:
                              {
                                   HDC hdc;
                                   PAINTSTRUCT ps;
                                   HPEN hPen;
                                   
                                   hdc = BeginPaint(Phys,&ps);
                                   hPen = CreatePen(PS_DASHDOTDOT,1,RGB(0,0,0));
                                   
                                   LineTo(hdc,200,200);
                                   
                                   EndPaint(Phys,&ps);
                              }
                         break;
                     }
    This is in a child window >.<

    It doesn't do anything when the button is clicked... I tried sending a wm_paint message and having it paint that when the message is handled. and in that having a variable that gets cordinates, but nothing works

  7. #7
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Try not to call BeginPaint/EndPaint outside of a WM_PAINT response, you'll achieve nothing.

    Replace them with
    hdc = GetDC(hwnd);
    ReleaseDC(hwnd, hdc);

    hwnd being the variable you're using for your window handle.

    Also, creating a pen is all well and good, but you'll need to select it into the dc to use it. So, after your CreatePen bit:-
    hOld = SelectObject(hdc, hPen);

    Make hOld another HPEN.
    Then, after your line drawing and before ReleaseDC:-
    SelectObject(hdc, hOld);
    DeleteObject(hPen);

    This stops you from potentially running out of GDI handles (it stops working, as does most of Windows).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 19
    Last Post: 05-30-2007, 05:47 PM
  2. Move the Caret to a line
    By TheDan in forum Windows Programming
    Replies: 3
    Last Post: 08-07-2005, 12:59 PM
  3. Read only one line using seekg
    By RedZippo in forum C++ Programming
    Replies: 3
    Last Post: 03-31-2004, 11:10 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 04:53 PM