|
Here is the Constructor:
CLine::CLine(CPoint Start, CPoint End, COLORREF aColor, int aWidth, int aStyle, int aType, int aRouteType)
{
m_StartPoint = Start;
m_EndPoint = End;
m_Color = aColor;
m_Width = aWidth;
m_Style = aStyle;
m_StartPointRect = (0,0,0,0);
m_EndPointRect = (0,0,0,0);
m_Type = aType;
m_RouteType = aRouteType;
m_StartPointRect = CRect(m_StartPoint.x-3, m_StartPoint.y-3, m_StartPoint.x+3, m_StartPoint.y+3);
m_EndPointRect = CRect(m_EndPoint.x-3, m_EndPoint.y-3, m_EndPoint.x+3, m_EndPoint.y+3);
TermRectRgnPts[0] = CPoint(m_EndPoint.x, m_EndPoint.y - RADIUS);
TermRectRgnPts[1] = CPoint(m_EndPoint.x + RADIUS, m_EndPoint.y);
TermRectRgnPts[2] = CPoint(m_EndPoint.x, m_EndPoint.y + RADIUS);
TermRectRgnPts[3] = CPoint(m_EndPoint.x - RADIUS, m_EndPoint.y);
m_RouteTermRect = CRect(m_EndPoint.x - RADIUS, m_EndPoint.y - RADIUS, m_EndPoint.x + RADIUS, m_EndPoint.y + RADIUS);
m_EnclosingRect = CRect(Start, End);
m_EnclosingRect.NormalizeRect();
m_StartPtScreenPct.XPercent = 0.0;
m_StartPtScreenPct.YPercent = 0.0;
m_EndPtScreenPct.XPercent = 0.0;
m_EndPtScreenPct.YPercent = 0.0;
}
Here is the Draw Function:
void CLine::Draw(CDC* pDC, int aStyle, int aWidth, CElement* pElement, int aRouteType)
{
//Create a pen and initialize it to the object color and line width of 1 pixel
CPen aPen;
COLORREF aColor = m_Color;
m_DC = pDC;
if(this == pElement)
{
aColor = SELECT_COLOR;
m_Style = aStyle;
m_Width = aWidth;
//m_Width = 0;
}
if(!aPen.CreatePen(PS_SOLID, m_Width, aColor))
{
// Pen creation failed. Abort the program
AfxMessageBox("Pen creation failed drawing a line", MB_OK);
AfxAbort();
}
unsigned Type1[4];
int c1 = GetPattern(Type1, true, m_Width, aStyle);
CPen *pOldPen;
SetPattern(Type1, c1);
{
// do drawing inside path for win95/8 compatibility
pDC->BeginPath();
MoveTo(m_StartPoint);
LineTo(m_EndPoint);
pDC->EndPath();
LOGBRUSH lbrush;
lbrush.lbStyle = BS_SOLID;
lbrush.lbColor = aColor;
CPen Pen(PS_GEOMETRIC | PS_SOLID |
(true ?
(PS_JOIN_ROUND | PS_ENDCAP_ROUND):
(PS_JOIN_MITER | PS_ENDCAP_FLAT) ) , m_Width, &lbrush);
pOldPen = m_DC->SelectObject(&Pen);
pDC->StrokePath();
pDC->SelectObject(pOldPen);
aPen.DeleteObject();
// make pen and stroke path
//DrawPathOutline(aColor);
}
pOldPen = pDC->SelectObject(&aPen);
/*pDC->MoveTo(m_StartPoint);
pDC->LineTo(m_EndPoint);*/
if (aRouteType != 0)
{
int Xv, Yv;
int Xp, Yp;
int C = 14;
double Xprime, Yprime;
CPoint PerpEndPoint, PerpStartPoint;
Xv = m_EndPoint.x - m_StartPoint.x;
Yv = m_EndPoint.y - m_StartPoint.y;
Xp = Yv;
Yp = (-1) * Xv;
Xprime = ( Xp / sqrt( Xp * Xp + Yp * Yp )) * C / 2;
Yprime = ( Yp / sqrt( Xp * Xp + Yp * Yp )) * C / 2;
PerpStartPoint.x = (long)(m_EndPoint.x + Xprime);
PerpStartPoint.y = (long)(m_EndPoint.y + Yprime);
PerpEndPoint.x = (long)(m_EndPoint.x - Xprime);
PerpEndPoint.y = (long)(m_EndPoint.y - Yprime);
if (aRouteType == ROUTE_TYPE_PASS)
{
CArray <cpoint, cpoint=""> ArrowPointArray;
CPoint ArrowPoint;
LPPOINT test;
tagPOINT *PerpStart, *PerpEnd, *Arrow;
ArrowPoint.x = (long)(((Xv / sqrt( Xv * Xv + Yv * Yv)) * C/2) + m_EndPoint.x);
ArrowPoint.y = (long)(((Yv / sqrt( Xv * Xv + Yv * Yv)) * C/2) + m_EndPoint.y);
ArrowPointArray.Add(PerpStartPoint);
ArrowPointArray.Add(PerpEndPoint);
ArrowPointArray.Add(ArrowPoint);
/* Draw the route terminator for blocking routes */
pDC->BeginPath();
pDC->MoveTo(PerpStartPoint);
pDC->LineTo(PerpEndPoint);
pDC->LineTo(ArrowPoint);
pDC->LineTo(PerpStartPoint);
pDC->EndPath();
}
else
{
/* Draw the route terminator for blocking routes */
pDC->BeginPath();
pDC->MoveTo(PerpStartPoint);
pDC->LineTo(PerpEndPoint);
pDC->EndPath();
}
// make pen and stroke path
DrawPathOutline(aColor);
}
pDC->SelectObject(pOldPen);
delete[] m_Pattern;
aPen.DeleteObject();
}
|
|
|
|
|
Stew wrote:
LOGBRUSH lbrush;
lbrush.lbStyle = BS_SOLID;
lbrush.lbColor = aColor;
CPen Pen(PS_GEOMETRIC | PS_SOLID |
(true ?
(PS_JOIN_ROUND | PS_ENDCAP_ROUND):
(PS_JOIN_MITER | PS_ENDCAP_FLAT) ) , m_Width, &lbrush);
pOldPen = m_DC->SelectObject(&Pen);
pDC->StrokePath();
pDC->SelectObject(pOldPen);
aPen.DeleteObject();
here, you're creating and selecting "Pen", but doing a DeleteObject on aPen.
?
-c
Conservative:
One who admires radicals centuries after they're dead.
-- Leo C. Rosten
|
|
|
|
|
Minor mishap. With all the things I've been trying, I missed that. At any rate, I changed it and it's still usurping all of the GDI resources and not freeing them. Let me ask you this, do cursors take up GDI resources? I don't think they do, but I'm not sure.
|
|
|
|
|
i don't think so.
this is probably something really simple, but easy to overlook...
-c
Conservative:
One who admires radicals centuries after they're dead.
-- Leo C. Rosten
|
|
|
|
|
Hi Stew,
I am currently facing the same problem...did you solve it??. I noticed that GDI resource are returned properly to system after calling StrokePath() or StrokeAndFillPath().
My code
<br />
pDC->BeginPath();
pDC->MoveTo(some point);<br />
pDC->LineTo(another point);<br />
pDC->EndPath();<br />
pDC->WidenPath();<br />
HRGN hRgn=::PathToRegion(pDC->GetSafeHdc());<br />
::FillRgn(pDC->GetSafeHdc(),m_hLastSecondRgn,(HBRUSH)GreyBrush);<br />
This code doesn't return GDI resource...please help cause I have been stuck on this for quite some time now...
Regards
Mustafa
|
|
|
|
|
I am pretty sure MFC does a lot of caching which will make it that much harder to determine if/where you have a leak as the memory will not be releasing when you think it should.
May want to try straight Win32 first - if you haven't already.
...cmk
|
|
|
|
|
yes as the title is saying i'm searching for a book that can give me enougth stuff for network code
i've one book :
Network Programming for Microsoft Windows, Second Edition
it help me learning about winsocks.
but as i want to learn about instant messaging or ftp server and plus someone advise me this book :
Internetworking with TCP/IP Vol. III Client-Server Programming and Applications-Windows Sockets Version
has someone read or heard about this book and can give me some advises it would be helpfull for me
or if you know a links for download online books it would be helpfull too
if you think that you can't , that means that you can : if you understand this there youn can
|
|
|
|
|
Search www.amazon.com
http://www.amazon.com/exec/obidos/search-handle-form/102-9678160-8616910
|
|
|
|
|
For instant messaging you can download the TOC specification from AOL.
It is their 'open source' protocol (as opposed to OSCAR their proprietary).
There are also a lot of open source projects that wrap the various IM protocols (AIM, Yahoo IM, MSN, ...).
...cmk
|
|
|
|
|
Anyone knows a simple way to create a program which acts like a ms-dos TSR program, which doesn't appear minimized at the taskbar and doesn't appear the program's icon on the system tray? A program which will act exactly like a linux deamon. I trying to create a daemon which stays listening for incoming connection requests, and acts like a linux telnet deamon. Could you show me a code example just for that? Thanks.
|
|
|
|
|
time to learn about NT services.
-c
Conservative:
One who admires radicals centuries after they're dead.
-- Leo C. Rosten
|
|
|
|
|
Does anyone know how GetWindowExt function works?
I've written in my View class:
(in OnInitialUpdate)
CSize sizeTotal(1000, 1000);<br />
SetScrollSizes(MM_LOMETRIC, sizeTotal);
then somewhere in the program I write
CClientDC dc(this);<br />
OnPrepareDC(&dc);<br />
CSize size = dc.GetWindowExt();
And size.cy equals to -254!
Does anyone know the clue?
|
|
|
|
|
Space Ace wrote:
then somewhere in the program
where in the program? are you calling it before the window has been shown ?
-c
Conservative:
One who admires radicals centuries after they're dead.
-- Leo C. Rosten
|
|
|
|
|
Chris Losinger wrote:
where in the program?
Well, I'm calling it in OnLButtonDown (just as a test). By this time the window is definitely already shown.
|
|
|
|
|
what happens if you don't call OnPrepareDC ?
-c
Conservative:
One who admires radicals centuries after they're dead.
-- Leo C. Rosten
|
|
|
|
|
Chris Losinger wrote:
what happens if you don't call OnPrepareDC ?
This way it doesn't work either. In this case it returns 1 which is obvious: if we don't call OnPrepareDC the map mode is not set.
|
|
|
|
|
Its odd. My app wil be working fine. Then alll of a sudden, it will start crashing if closed with the x button on the right hand size . I'm jsut performing a read operation by pressing a button once in each run. Then if I go back into VC and rebuild and run again its okay for a while, then misbehaves again...No code changes are happening, it just decides to misbehave. it always reads the same file at this point.
What can be the reason, and how do I prevent this problem. This way i can distribute my project thinking it works fine, then all of a sudden it will start crashing with the user and I'll be in trouble..help!
(happens in release and debug mode both)
|
|
|
|
|
I'm jsut performing a read operation by pressing a button once in each run
You have to give some details...
rechi
|
|
|
|
|
Its an MDI MFC database app. Its function (its a little test project) is to open a recordset, and read in some data into an Access database. One of the fields is a blob (ole object), several are text, and one is a memo. When the app runs it asks you to browse for the blob you want to store. Automaticallly after this it opens a test data file (.txt), reads in a buffer, and writes it to the memo field. The text fields are filled with hardwired values. Anyways this is the app, which "corrupts" itself after being run from the IDE repeatedly with no code changes! A rebuild all repairs things. Its pretty sporadic and happens unexpectedly.
Thanks for being interested,
ns
|
|
|
|
|
sounds like a memory overwrite to me
check all your buffers are big enuff for what they have to store
"... and so i said to him ... if it don't dance (or code) and you can't eat it either f**k it or throw it away" sonork: 100.18128 8028finder.com
|
|
|
|
|
Add a handler for OnSysCommand() and set a breakpoint in it. That will help you trace thru the crash. The nID your're interested in debugging is SC_CLOSE .
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
The nID your're interested in debugging is SC_CLOSE. <br />
<br />
Sorry but whats an nID and whats SC_CLOSE? Like WM_CLOSE? Is OnSysCommand accessible through the class wizard? I didnt see it in my view class. or in the mainframe class either. Its not in the "Add windows message handler" context menu either...So how shall I add an OnSysCommand handler?
Sorry to bug you so much about stuff thats obvious to you (but a mystery to me!)
thanks
|
|
|
|
|
When you click the "x" button, Windows sends you a WM_SYSCOMMAND message. This message is also sent when you invoke commands from a top level window's system menu (the menu at the top left). To differentiate the different system commands, Windows sets the nID parameter sent along with the message.
The MFC handler for WM_SYSCOMMAND is OnSysCommand . You can add this handler using ClassWizard. The nID is the parameter name and is set to SC_CLOSE to identify that the user clicked the "x" button (or selected "Close" from the system menu).
That's the code path you want to step thru to see where your app is crashing.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
how to edit any column item in a list control in report style?
I can edit only first(zeroth) column items!
|
|
|
|
|
Simply use CListCtrl::SetItem with nSubItem set to the subitem index you wish to change. Example:
LVITEM pItem;
pItem.iItem = 2;
pItem.iSubItem = 3;
pItem.mask = TVIF_TEXT;
pItem.pszText = (LPTSTR)(LPCTSTR)"Your Text";
m_ctlListBox.SetItem(&pItem);
modified 12-Sep-18 21:01pm.
|
|
|
|