1:1 MSPaint clone - not ? but !

Here you can discuss ReactOS related topics.

Moderator: Moderator Team

roytam1
Posts: 43
Joined: Thu Oct 06, 2005 11:14 am

Re: 1:1 MSPaint clone - not ? but !

Post by roytam1 »

gyROS wrote:

Code: Select all

void Line(HDC hdc, short x1, short y1, short x2, short y2, int color, int thickness)
{
    HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, color));
    MoveToEx(hdc, x1, y1, NULL);
    LineTo(hdc, x2, y2);
    DeleteObject(SelectObject(hdc, oldPen));
}
It has to be somewhere in here. I just do not see, where... The Pen is created, selected into the DC, thrown out of the DC again and finally deleted. :|
maybe it should be look similar with this?

Code: Select all

void CWinMsg::OnDraw(HDC hDC)
{
 //move position.
 POINT ptLeftTop;
 ptLeftTop.x = 10;
 ptLeftTop.y = 10;
 MoveToEx(hDC,ptLeftTop.x,ptLeftTop.y,NULL);

 //modify line color and thickness.
 HPEN hPen = CreatePen(PS_SOLID, 10, RGB(0, 255, 0));

 //use new pen.
 HGDIOBJ hOldPen = SelectObject(hDC,hPen);

 //draw a line from (10,10) to (100,100).
 ptLeftTop.x = 100;
 ptLeftTop.y = 100;
 LineTo(hDC,ptLeftTop.x,ptLeftTop.y);

 //restore old pen.
 SelectObject(hDC,hOldPen);

 //delete pen.
 DeleteObject(hPen);
 
}

Blackcrack
Posts: 1808
Joined: Tue Dec 20, 2005 12:55 pm
Contact:

Re: 1:1 MSPaint clone - not ? but !

Post by Blackcrack »

// ( a look to gyROS: look..., i love this work it is real open source, jo' see what i mean :mrgreen: not other ! )

gyROS
Posts: 197
Joined: Sun Nov 09, 2008 8:10 pm
Location: Deutschland

Re: 1:1 MSPaint clone - not ? but !

Post by gyROS »

A short description of what the code does:
1. Create a new pen and select it into the DC. SelectObject returns the old pen, which is then stored in oldPen.
2. Move to position in canvas.
3. Draw the requested line.
4. Select the old pen into the DC again. The object returned by SelectObject, the one from 1., is then passed to DeleteObject, which should delete it.

The123king
Posts: 242
Joined: Mon Jun 16, 2008 6:51 pm

Re: 1:1 MSPaint clone - not ? but !

Post by The123king »

There's GDI leaks in all the tools.

gyROS
Posts: 197
Joined: Sun Nov 09, 2008 8:10 pm
Location: Deutschland

Re: 1:1 MSPaint clone - not ? but !

Post by gyROS »

The123king wrote:There's GDI leaks in all the tools.
Not at all! I got it!
The WM_PAINT handlers of the selection window and tool settings window lacked some ReleaseDC() calls! (Since selections are implemented, the WM_Paint handler of the selection window is invoked whenever something happens in the image.)

The bug is fixed, the package is updated. Apart from this and the line #pragma code_page(1250) in the slovak translation (Does it solve the CP problem?) there are no further changes.
Last edited by gyROS on Thu Mar 19, 2009 11:19 pm, edited 2 times in total.

vicmarcal
Test Team
Posts: 2732
Joined: Mon Jul 07, 2008 12:35 pm

Re: 1:1 MSPaint clone - not ? but !

Post by vicmarcal »

gyros nice work...continue killing them.. :)

gyROS
Posts: 197
Joined: Sun Nov 09, 2008 8:10 pm
Location: Deutschland

Re: 1:1 MSPaint clone - not ? but !

Post by gyROS »

One more demo of what is already possible:
[ external image ]
With initially 146 GDI objects there were 217 in the end, so something is still wrong, but the major bug has gone.

Kario
Posts: 89
Joined: Sun Feb 25, 2007 2:48 am
Location: Slovakia
Contact:

Re: 1:1 MSPaint clone - not ? but !

Post by Kario »

nice work gyROS ;-)
but why, oh why...
... the CP bug didn't die?! :-(

btw. is the file "deckend.xcf" needed in your package?

gyROS
Posts: 197
Joined: Sun Nov 09, 2008 8:10 pm
Location: Deutschland

Re: 1:1 MSPaint clone - not ? but !

Post by gyROS »

deckend.xcf is the GIMP file for the transparency settings icons. It uses multiple layers, so it's easier to edit if the file stays in the package.
Kario wrote:but why, oh why...
... the CP bug didn't die?! :-(
Short and concret: I've no idea!

The123king
Posts: 242
Joined: Mon Jun 16, 2008 6:51 pm

Re: 1:1 MSPaint clone - not ? but !

Post by The123king »

gyROS wrote:One more demo of what is already possible:
[ external image ]
With initially 146 GDI objects there were 217 in the end, so something is still wrong, but the major bug has gone.
Have you uploaded the "fixed" version?


I still see a GDI leak in XP

hto
Developer
Posts: 2193
Joined: Sun Oct 01, 2006 3:43 pm

Post by hto »

Kario wrote: but why, oh why...
... the CP bug didn't die?! :-(
;-)

Kario
Posts: 89
Joined: Sun Feb 25, 2007 2:48 am
Location: Slovakia
Contact:

Re:

Post by Kario »

hto wrote: ;-)
yes, nice, i know about it also... my build also was real slovak before the pragma, and with pragma is also nice real slovak, so i dont know why gyROS has incorrect one :-(

hto
Developer
Posts: 2193
Joined: Sun Oct 01, 2006 3:43 pm

Post by hto »

The solution is simple — to commit it into ReactOS tree, and there it will speak Slovak well.

P.S. The program does not work when compiled with UNICODE, only with ANSI.
Last edited by hto on Sat Mar 21, 2009 1:47 pm, edited 1 time in total.

gyROS
Posts: 197
Joined: Sun Nov 09, 2008 8:10 pm
Location: Deutschland

Re: 1:1 MSPaint clone - not ? but !

Post by gyROS »

Kario wrote:yes, nice, i know about it also... my build also was real slovak before the pragma, and with pragma is also nice real slovak, so i dont know why gyROS has incorrect one :-(
I suppose it is working on your machine, because it is most likely your default system CP. But hto is right. The solution is simple.
The123king wrote:Have you uploaded the "fixed" version?

I still see a GDI leak in XP
I did upload it, but there was one GetDC without ReleaseDC left. Vista did not seem to care about this one that a lot, but Win2000 and Wine did. I've updated the ZIP file once again and I strongly hope you won't encounter this bug anymore. (At least in wine I don't.)

User avatar
Black_Fox
Posts: 1584
Joined: Fri Feb 15, 2008 9:44 pm
Location: Czechia

Re: 1:1 MSPaint clone - not ? but !

Post by Black_Fox »

Nice! No leak on XP now, your Paint.exe even uses a few GDI objects less than its XP counterpart.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest