|
You could try
dc.SaveDC();
and
dc.RestoreDC(-1);
to save and restore the DC state. That should work.
The brush and any other objects can only be destroyed if they are not being referred to by the DC, so your stuff should work anyway...
Steve S
|
|
|
|
|
It works, that's true ... but after 5 seconds you've wasted 512 meg of ram.
Adding dc.SaveDc() and dc.RestoreDC(-1) doesn't make a difference, still leaking.
Passing the brush object instead of the pointer is the only thing that works. But then we are using deep copies (I assume that) and that doesn't speed things up.
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
|
|
|
|
|
Your mix of things might be why.
Does
CBrush* pOld = dc.SelectObject(&brush);
...
dc.SelectObject(pOld);
still leak?
Steve S
|
|
|
|
|
That results in a crash when selecting a pen instead of a brush (selecting a brush is doing allright).
Strange...
Is it the stockobject?
CPen* oldpen=(CPen*)pDC->SelectObject(GetStockObject(NULL_PEN));
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
|
|
|
|
|
Wouldn't it be easier to use pDC->SelectStockObject(NULL_PEN) ?
There are caveats to do with the fact that the pointer may well, in this case be to a temporary CGdiObject, so shouldn't be used in different messages.
I normally use SelectStockObject, or failing that,
CPen* oldpen = (CPen*)pDC->SelectObject(CPen::FromHandle(::GetStockObject(NULL_PEN)));
I prefer use of an explicit FromHandle() call rather than relying on a cast operator.
Steve S
|
|
|
|
|
SelectStockObject instead of SelectObject(GetStockObject) does the trick.
tnx.
|
|
|
|
|
This eats ram like hell too:
CPen pen(PS_SOLID,1,m_clrForeground);<br />
CPen* oldpen=(CPen*)pDC->SelectObject(&pen);<br />
...<br />
pDC->SelectObject(oldpen);
I don't understand this, it's code I see a lot. I feel kinda stupid...
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
|
|
|
|
|
Hi CPians!
I'd like to debug my app, which is a C-dll with visual C++ 6.0. It is bound to an application, which is loaded when starting the debugger.
My problem is that the debugger will not stop at the breakpoints ... I made sure that I have opened the corresponding file (I mean the file that actually gets compiled, and not a copy of the project), that my dll is really being loaded by the application (renaming it would crash the app), and that my code gets compiled (I do not get that message you usually get when trying to put a breakpoint on a part of code which is not compiled). Besides, I am really positive that the code has to go through where I put my breakpoints.
So ... I am lost ... any suggestion ?
Thanks
~RaGE();
|
|
|
|
|
This can sometimes happen moved your project to a different directory, then editted code in the new directories. Some files are still pointing to the old directory.
J.
----------------------------
|
|
|
|
|
hi,
i have a problem with my MFC Dialog, i want to add a minimized respectively a maximized item into the popupmenu, which appears if the right mouse button is pressed on my dialog in the taskbar! There are only MOVE and EXIT items in it! I don't know how to get them in there!
Can someone help me ?
Thanks in advance!
|
|
|
|
|
Hi,
the MFC Dialog, sets the menu options in the OnInitDialog() method. look at the following code:
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
return TRUE;
}
the pointer pSysMenu is the handler to the system menu, and you can add your menu items using pSysMenu->AppendMenu() method, same as the MFC by default adds the 'About' menu.......
hope this helps ya
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
how to save a flash in a webpage as a jpg/gif/bmp file? zhongxunyang 3:53 25 Sep '03
how to save a flash in a webpage as a jpg/gif/bmp file?
i used a flash object that i downloaded from the site of http://bukoo.sourceforge.net to create a flash movie file, and now i want to add a function and it can allow people to save this flash movie as a jpg/gif/bmp file.Can anyone here provide some codes or component to help me realize this function?
|
|
|
|
|
Have you tried getting the display context for the app running the flash object and using BitBlt?
That is where I would start.
|
|
|
|
|
can you provide a source code for how to do it?
is there any component can realize this function?
thanks very much!
|
|
|
|
|
hello!
question:i use serial comunication between pc and SCM
now i send AT command to the SCM by serial port and wait for the SCM response,for our debug purpose,we want to get the debug information by
the serial port ,the debug information will be sent to the serial port
at any time.we want to send AT Command ,then get the proper response,
at the same time ,we can get the debug information by the serial port.
who can tell me how can i do?use overlapped serial comunication or non
overlapped?
thanks a lots
-----------------------------
Mr.Whelk
-----------------------------
Zhuhai City ,Guangdong ,China
|
|
|
|
|
recently, i worked on printing program.
can anyone help me how to get the name of a system pre-defined paper?
such as :
value 1 return Letter (8.5 x 11 in.)
thanks
|
|
|
|
|
I think that may be a problem of the printer driver rather than the problem of the system.
I don't know it exactly, but the paper size is defined in the DEVMODE printer struct (member: dmPaperSize). But here the definiton is only per number (symbolic constant). So I think the printer driver does the mapping from those numbers to the string which is visible in the windows common printer dialog!
|
|
|
|
|
thank you CodeBrain,
I do know the member of DEVMODE dmPaperSize identitify the dimension of the paper. but not very easy to get the size in strings. maybe the only thing i can do is mapping constants to strings by myself.
|
|
|
|
|
Look up DeviceCapabilities specifing DC_PAPERNAMES
Joel Lucsy
|
|
|
|
|
thank you Joel,
it works using DeviceCapabilities function.
very kind of you
|
|
|
|
|
HI,
I have a VC++ application which can be accessed thru a Telnet Server. I want to maintain the Session state in case of any n/w failure between the client and Server.That is when ever a client trys to connect back to the Server after a n/w failure the server has to take the user to the state were he was disconnected.
Question is :
where can do the buffering in order to maintain session,In the Telnet Server or my VC++ application.Pls help
Thnks for reading and Thnks in advance
Ram
|
|
|
|
|
Hi All,
I am working on MFC for some time now. I want to learn VC++ on .Net. Can any one suggest some good books on this. Any good books available for Managed C++? I have seen some good articles here on Managed C++. Thanks to Nish for that. Kindly help..
Thanks in advance.
Vini
|
|
|
|
|
Hi,
I have an existing Win32 console app. I want to now add user interface (MDI) to it, which obviously I would like to be run in a separate thread. I used AfxBeginThread to create a new MFC thread which creates my interface, etc. But, the problem is that in this implementation I do not have any CWinApp object at all, and therefore I cannot use some MFC functions. What is the correct way to create a user interface using MFC in a thread other than the main thread of my app?
Thanks,
Krishnan
|
|
|
|
|
Hi,
there are 2 types of threads in win32/mfc... applications:
1) worker thread.
2) UI thread.
your case is the second one, UI thread. all UI threads in MFC application must inherite CWinThread class..... then when you call AfxBeginThread(..) method, you pass your dervied-CWinThread object as the parameter.
the CWinThread class, has the method : "InitInstance()" there you must create the proper MDI objects you want to display.....
read about UI thread in the MSDN or here...
hope this helps ya
regards,
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
YaronNir wrote:
your case is the second one, UI thread. all UI threads in MFC application must inherite CWinThread class..... then when you call AfxBeginThread(..) method, you pass your dervied-CWinThread object as the parameter.
the CWinThread class, has the method : "InitInstance()" there you must create the proper MDI objects you want to display.....
I have already done that. But, the problem is how do I create a CWinApp object. Since, my app is a console app, I cannot declare a global variable for the CWinApp object. Also that object would be instantiated in the main thread, whereas my UI is in different thread.
|
|
|
|