|
Hi.
I use Programming Windows with MFC, Second Edition by Jeff Prosise as a reference for the OLE Clipboard. Prosise demonstrates both Win32 API method and MFC simple classes encapsulating the Win32 API method for the OLE Clipboard.
The Win32 API method is not difficult, just takes up a little bit more code than if you use MFC. I would like to know is there any advantage to using Win32 API instead of MFC for OLE Clipboard and even COM?
I enjoy working with Win32 API, but not for GUI.
Thanks,
Kuphryn
|
|
|
|
|
kuphryn wrote:
I would like to know is there any advantage to using Win32 API instead of MFC for OLE Clipboard and even COM?
I would say the advantage is that you do not need to carry around the baggage that is involved with an MFC solution. You dont need to link to the libraries and inherit from the MFC base classes. This is if you feel comfortable enough to do it with the Win32 API.
As far as COM development, MFC does make it a lot easier than straight C++ because it will take care of a lot of the basic boiler plate stuff that you need to do for every COM object. However if you want a framework for COM objects I would suggest ATL instead. COM is what it was specifically designed to do. COM was added to MFC as an after thought, and it is a little clumsy compared to ATL.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Thanks.
I prefer MFC for GUI, so all my program are under MFC's doc/view. Other than GUI, I prefer to use Win32 API if possible because I have more control.
Kuphryn
|
|
|
|
|
Okay. I tested an OLE Clipboard implementation with some lines of text. Everything works good, except for that fact that the data buffer ingored all newlines. For example, let this copy the following data, which I first save in a string object, to the OLE Clipboard.
-----
Test
1
2
3
Testing Completed
-----
This is what I would see when I paste to Notepad.
-----
Test[]1[]2[]3[]Testing Completed
-----
I am using the OLE Clipboard strictly for text. I would like to know is it possible to copy data to the clipboard so Windows would recognize all new lines?
Thanks,
Kuphryn
|
|
|
|
|
i want to write an app that can play flash movies on different monitors in a multi-monitor system (winxp) ... i looked around a lot trying to find some kind of dev kit letting me put the player code into my app but nux! i can start a movie using shellexecute() and all that but it all seems a bit icky and clunky cos i have to stop movies and play other movies at async times ... i was thinking to have all 4 movies playing but suspended as processes and kick them off when i need them
any better ways that anyone knows of?
"... 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
|
|
|
|
|
How about using the Shockwave Flash ActiveX control?
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
|
I think you can get the code of the flash player freely. I already did it with the vs 4 of the player.
|
|
|
|
|
My app is crashing on machines that aren't equipped with a lot of memory due to the fact that it is eating up all of the system's GDI resources and, apparently, not freeing them. I'm trying to figure out what I'm doing wrong. I've tried DeleteObject after creating a CPen, selecting it into the DC, using it, and selecting the old pen back into the DC as I have read on this message board and in the MSDN library and it hasn't worked. I've also tried using the CAutoPen class that I found on this site for creating a CPen, selecting it into the DC, and selecting the old pen back into the DC when the pen goes out of scope. Nothing seems to be working to give back the GDI resources. Does anyone have any ideas as far as what they think I might be missing?
|
|
|
|
|
are you using other GDI resources, besides CPen (CBrush, CBitmap, etc) ?
-c
Conservative:
One who admires radicals centuries after they're dead.
-- Leo C. Rosten
|
|
|
|
|
I'm using CPen, CFont, and CRgn
|
|
|
|
|
are you doing the same :
CGDIObejct *pOld = dc.SelectObejct(&newObj);
...
dc.SelectObject(pOld);
newObj.DestroyObject();
sequence for all of them?
-c
Conservative:
One who admires radicals centuries after they're dead.
-- Leo C. Rosten
|
|
|
|
|
I'm not selecting the region into the DC or deleting it or anything. You think that might be my issue? The only thing is. I've whittled down my app, for testing to find this problem, to not do anything except let me draw a line. In the line class, I have the selectobject and deleteobject calls for the pen and it still eats the GDI memory like crazy because I redraw it each time I mouse over it. But the function for drawing the line when I first draw it or when I mouse over it and off of it is the same function. I'm not sure what I'm missing, but it's obviously something.
|
|
|
|
|
can you post the line-only code?
-c
Conservative:
One who admires radicals centuries after they're dead.
-- Leo C. Rosten
|
|
|
|
|
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
|
|
|
|
|