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?)
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?)
if you use the WINAPI then you could use the ellipse function.
Ok. I'm quite new to win programming (started yesterday).
Please explan what the winapi is?
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.
I have written a simple window. I just wasn't quite sure what the winapi was.
thanx.
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).
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)
Don't worry it is not as hard as it looks, you will get used to it pretty soon.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 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.
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
>>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).
(..and yes, I do tend towards comment overkill... )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; }
>>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.
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...
....Seems to be working now....
CProgramming FAQ
Caution: 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!this person may be a carrier of the misinformation virus.
[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
>>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.
I forgot, sue me.
Welcome back, GBonny!Originally posted by Alphabird32
I forgot, sue me.