Thread: ellipse in a win32 application

  1. #1
    Bios Raider biosninja's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    765

    Question ellipse in a win32 application

    I was just wondering if I could draw an ellipse in a win32 aplication? If it possible, how?

    I'm using Borland C++ 5.02

    (can I use the BGI functions?)

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    if you use the WINAPI then you could use the ellipse function.

  3. #3
    Bios Raider biosninja's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    765
    Ok. I'm quite new to win programming (started yesterday).
    Please explan what the winapi is?

  4. #4
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    it's what is used to program windows.

    if you cannot write a simple windows program yet, then i'd suggest you learn a little bit more about windows programming before you try drawing ellipsis and things alike.

  5. #5
    Bios Raider biosninja's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    765
    I have written a simple window. I just wasn't quite sure what the winapi was.

    thanx.

  6. #6
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    The API is sort of like the rules that you follow...eg,, in the Win32API, you must had declared the WinMain() function (hence, a rule).

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Its sort of....

    Like math.h contains functions for mathematics, the WIN32 api has functions for MS Windows.

    Lots of stuff for those controls you see on dialogs, networking stuff ect.

    You done the 'hello world' or 'my first window' app?

    Looked for 'Programming Windows' by Petzold? (the WIN32 API bible)

    To draw an elipse you will need to handle WM_PAINT messages in your windows callback function.

    Something like (I am without my compiler so doing this from memory and from MSVC)
    Code:
    case WM_PAINT:
    
    RECT     Rect, SmallRect;
    HDC      hdc=NULL;
    HBRUSH   hWhiteBrush=NULL;
    HPEN     hBlackPen=NULL;
    COLORREF Black = RGB(0,0,0);
    int      iPenThickness=1;
    
    //get ready
    GetClientRect(hWnd,&Rect);//get the area
    hWhiteBrush = GetStockObject( WHITE_BRUSH ); //for the background
    hBlackPen = CreateSolidPen( hdc, Black, iPenThickness); //to draw the shape
    
    //start painting
    hdc=BeginPaint(hWnd); //to get the current screen device to paint on to
    
    FillRect(hdc,&Rect,hWhiteBrush);//paint the window white (wipe it clear)
    
    //don't know the elipse drawing function so a rectangle in the middle
    SmallRect.left = (Rect.right-Rect.left)/4; 
    SmallRect.right = Rect.right-SmallRect.left; 
    SmallRect.top = (Rect.bottom-Rect.top)/4;
    SmallRect.bottom = Rect.bottom-SmallRect.top
    FrameRect(hdc,&SmallRect,hBlackPen); //the rectangle is drawn
    
    EndPaint(hWnd); //let windows know we have finished and it can draw the screen
    
    //clean up
    DeleteObject(hBlackPen); // not selected in so just delete
    DeleteObject(hWhiteBrush); // don't have to delete stock object but...
    return FALSE;
    break;//for syntax only
    Don't worry it is not as hard as it looks, you will get used to it pretty soon.

    Don't let that idiot 'the dog' put you off. He just doesn't know himself. So is trying to make himself look better, by downgrading you.

    Don't let him.



    Here puppy, puppy......FETCH!!
    Last edited by novacain; 08-02-2002 at 07:21 AM.

  8. #8
    Registered User
    Join Date
    Aug 2002
    Posts
    57
    novacain made it extremely difficult, as difficult as a NeHe tutorial.....

    [code]
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    PAINTSTRUCT ps;
    HDC hdc=NULL;
    HBRUSH hBrush, oldbrush;
    HPEN hPen, oldpen;

    switch(msg) {
    case WM_CREATE:
    hdc= GetDC(hwnd);
    ReleaseDC(hwnd);
    break;
    case WM_PAINT:
    hdc= BeginPaint(hwnd, &ps);
    hBrush= CreateSolidBrush(RGB(0, 0, 0));
    hPen= CreatePen(PS_SOLID, RGB(255, 0, 0));

    oldbrush= (HBRUSH)SelectObject(hwnd, hBrush);
    oldpen= (HPEN)SelectObject(hwnd, hPen);

    Ellipse(hdc, 0, 0, 50, 50);

    SelectObject(hwnd, oldbrush);
    SelectObject(hwnd, oldpen);

    DeleteObject(hBrush);
    DeleteObject(hPen);
    break;
    case WM_CLOSE:
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hwnd, msg, wParam, lParam);
    }

    return 0;
    }

    Its something like that

  9. #9
    Ken Fitlike
    Guest
    >>novacain made it extremely difficult, as difficult as a NeHe tutorial.....<<

    Actually, I find Novacain's (and NeHe's stuff) to be very readable and informative. He (Novacain) uses code tags properly, his code is nicely indented and well-commented (essential for the complete beginner). In addition he has provided further references and sources of information. He has also provided disclaimers ie

    >>Something like (I am without my compiler so doing this from memory and from MSVC)<<

    and

    >>//don't know the elipse drawing function so a rectangle in the middle<<

    Also, as a member with a 1000+ post count given solely in altruistic services of programmers of all skill levels, whether amateur or professional, I understand he may well be the proud owner of a world famous 'GovtCheez doll'. (search the GD board, it's a good laugh).

    Nevertheless, Alphabird32, you have provided a concrete example of the use of the Ellipse function - which is most commendable. Welcome to cprog.

    Now here's how it should really be done (just joking).
    Code:
    case WM_PAINT:
        {
        PAINTSTRUCT ps;
       
        //don't need to declare an HDC variable as BeginPaint
        //fills out the hdc member of the PAINTSTRUCT struct with
        //that info.
        BeginPaint(hwnd,&ps);
            //use default pen for that HDC (device context) to draw
            //an ellipse bounded by a rectangle given by last four 
            //parameters of the 'Ellipse' function.
            Ellipse(ps.hdc,0,0,100,100); 
        EndPaint(hwnd,&ps);
        [color=blue]return[/blue] 0;
        }
    (..and yes, I do tend towards comment overkill... )

    >>I'm using Borland C++ 5.02<<

    I think most simple win32 API source should compile with little or no modification. This is speculative, however, as i've only used the bcc5.5 cmd line tools and borland c++ builder 1 & 4; which I never had any problems with.

  10. #10
    Ken Fitlike
    Guest
    Aaarggghhh! The board didn't let me log me in! I can't edit! Noooo!

    ::holds head in shame while shuffling from one foot to the other::

    Looks like i'm utterly inept at using code and other tags properly.

    COLORREF clrMyFace=RGB(255,0,0);

    And so it should...

  11. #11
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    ....Seems to be working now....
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  12. #12
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    this person may be a carrier of the misinformation virus.
    Given the scottish water suppy just now Ken, that might not be the only thing you are carrying!

    [Lame excuss for the OT post] The windows API is a set of functions which window provides the programmer, these range from calls to change the GUI to calls to windows debuging features.[/Lame excuss for the OT post]
    Last edited by VBprogrammer; 08-10-2002 at 09:59 AM.
    VC++ 6

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>I understand he may well be the proud owner of a world famous 'GovtCheez doll'.

    The evil switch jammed in the ON position and I had to bash it with my copy of Petzold's 5th before it could re-format my HD. I didn't know they came with a floppy.

    Still, I miss it's little grin.

    Alphabird32
    People who don't call EndPaint() after BeginPaint() (ect) should not be too quick poke holes in others code.

  14. #14
    Registered User
    Join Date
    Aug 2002
    Posts
    57
    I forgot, sue me.

  15. #15
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Originally posted by Alphabird32
    I forgot, sue me.
    Welcome back, GBonny!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-08-2008, 04:48 PM
  2. win32 application wizard in microsoft visual studio
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 02-25-2008, 01:26 AM
  3. Adding interface to Win32 console application
    By motiz in forum Windows Programming
    Replies: 5
    Last Post: 01-03-2008, 03:17 AM
  4. Painting with Tex on a Win32 Application
    By webzest in forum C++ Programming
    Replies: 5
    Last Post: 08-16-2004, 03:04 PM
  5. How To Convert A Dos-Prompt C++ PRogram Into Win32 Application ?
    By SonicWave in forum Windows Programming
    Replies: 1
    Last Post: 09-15-2001, 11:03 AM