|
They can.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi,
i am saving a HDC in one fuction of a class by using the following code
<br />
MyClass::MyFunction()<br />
{<br />
CDC dc;<br />
AfxGetApp()->CreatePrinterDC(dc);<br />
m_Hdc = dc.GetSafeHdc( );<br />
dc.Detach();<br />
}
Now in some other classes i am Creating a CDC class objcet using this HDC.
CDC *pDC = CDC::FromHandle(MyClasss::getMyHDC());
But some time it is causing my application to crash. But if i replace FromHandle() by Attach() and detach() the application is working fine.
So, i just want to know whether it is safe to use FromHandle() or not. If not should i replace all my FromHandle() by Attach and detach.
Thanks Ashwani
|
|
|
|
|
ashtwin wrote: CDC *pDC = CDC::FromHandle(MyClasss::getMyHDC());
Are you storing the pDC beyond a function call, CDC::FromHandle returns a temporary CDC object if HDC is not already attached. CDC::DeleteTempMap will delete the temporary CDC objects in idle processing. so if you using the object beyond a function call and there by alowing the idle processing to delete the object, application can crash if you access the temp object.
CDC::FromHandle() is less error-prone in the sense you do not have to remember to "detach". but remember it is used only in immediate processing.
In your MyClass::MyFunction(), you are Detaching the CDC, so it is sure that FromHandle creates temp map object, and possibly you are storing beyond a function call.
I suggest you to Keep attached the Printer DC with a member variable CDC and use it everywhere or use attach detach you should match the two calls then, or use FromHandle but with in a function call.
If the frequency of the call is high reduce the number of attach - detach.
modified on Friday, March 14, 2008 8:50 AM
|
|
|
|
|
Hi,
Currently i am using the pDC within the same fuction call though i am calling a seperate function to create it which is returning this pDC to the parent function and again from the parent function i am calling a seperate function which has pDC as one of its parameter.
<br />
CDC* dc = myPrintObj.createDCForPrint(printRect);<br />
doPrintWfReport(dc, printJob);<br />
The Funtion where i am getting the CDC object is as follows
<br />
CDC* PrintJob::PrintJobToPrinterType::createDCForPrint(const NcWfPrintJob& client, const CRect& printRect)<br />
{<br />
REQUIRE(!printRect.IsRectEmpty());<br />
<br />
DOCINFO DI;<br />
ZeroMemory(&DI, sizeof(DOCINFO));<br />
DI.cbSize = sizeof(DOCINFO);<br />
DI.lpszDocName = NcCommonResources().getWFReportDocName();<br />
<br />
CDC* pDC = CDC::FromHandle(client.getPrintInfo().hDC);<br />
pDC->SetMapMode(MM_HIMETRIC);<br />
<br />
pDC->StartDoc(&DI);<br />
pDC->StartPage();<br />
<br />
return pDC;<br />
}<br />
In the current design it is not possible for me to have a CDC object as a member varaible. Is it OK to use FromHandlePermanent() instead of FromHandle().
Thanks
|
|
|
|
|
Do you have FromHandlePermanent for CDC, i think it is for CWnd::FromHandlePermanent.
ashtwin wrote: Currently i am using the pDC within the same fuction call
I assume this is your new change, and works without crash.
ashtwin wrote: In the current design it is not possible for me to have a CDC object as a member varaible
why it is not possible, in createDCForPrint why don't you attach the printer DC to a member variable CDC::Attach and when you done printing you can call cleanup function like DeleteDCForPrint and detach and delete the DC stored in member variable. If you are using the DC within the function call as said above it is ok, make sure the idle processing which deletes the temp DC object not allowed to execute in between.
|
|
|
|
|
Sorry, u r right CDC don't have FromHandlePermanent(). Now the question is whether we can return a temporary object pointer from a function or not?
Thanks
Ashwani
|
|
|
|
|
ashtwin wrote: Now the question is whether we can return a temporary object pointer from a function or not?
That i answered repeatedly, if you are sure the idle processing is not allowed to execute that is used CDC within a function callstack which is running in the same thread as of the Message loop ad you are not doing windows message processing in between.
|
|
|
|
|
Ok, thanks.
I think
dc.StartDoc;
is the culprit. Because after prompting Save as dialogue the system will become idle and temporary objects are getting deleted during this call only.
|
|
|
|
|
Then what about returning an object which is attached using CDC::Attach not CDC::FromHandle.
CDC *CreatePrinterDC()
{
....
CDC *pdcPrinter = new CDC;
pdcPrinter ->Attach(hdcPrinter);
....
return pdcPrinter;
}
clean up
delete pdcPrinter; in main function;
|
|
|
|
|
Hi,
i think the solution which u r suggesting will definately work.
But i have overridden createDCForPrint() and in one function i am already using new to create CMetaFileDC object.
I will try to implement ur solution if possible.
Thanks
|
|
|
|
|
Hi
How can I read a selected file propetry sheet objects (info in propery pages)?
|
|
|
|
|
Your question is too vague. Please explain.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
If there are 10 files of same extension.In run time there is change in no of file how to get size of all files and sum it up as we dosent know the names of file.For vc++ dialog based application.give a sample code if possible
|
|
|
|
|
Check the following article[^]
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
Ah, in addition to my other reply post check this[^]
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
Hi All,
I have a dialog based app..It has some buttons on it.
When I click a button, a Modal Dialog Box pops up.
Now, how do I position the Modal Dialog Box so that it is drawn over the button... ??
I want to draw the dialog boxws right over the corresponding buttons..
I have used SetWindowPos but it positions the dialog box relative to the top left of the screen.
I want to position it relative to the upper left vertex of the application's main dialog box
Hope I have clearly stated my problem
Regards,
AbbyIndian
...A Programmer may or may not be the master of the programming language grammar...
|
|
|
|
|
You need to use better coordinates for SetWindowPos then.
If you use GetDlgItem (IDC_MYBUTTON)->GetWindowRect (&rcCoords) , then you'll get the button's position in screen coordinates, which you can then use in SetWindowPos for your secondary dialog.
Iain.
Iain Clarke appears because CPallini still cares.
|
|
|
|
|
Thanks for the response
But don't we have same flag or attribute setting or some other way after which we can provide relative x,y points to SetWindowPos ??
Regards,
AbbyIndian
...A Programmer may or may not be the master of the programming language grammar...
|
|
|
|
|
Nope.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Ok..
Thank you
Regards,
AbbyIndian
...A Programmer may or may not be the master of the programming language grammar...
|
|
|
|
|
This code snippet worked fine for me:
void CMyMainDialog::OnButton1()
{
CMyPopupDialog dlg(&m_btn1);
dlg.DoModal();
}
BOOL CMyPopupDialog::OnInitDialog()
{
CDialog::OnInitDialog();
CRect rc;
m_pParent->GetWindowRect(rc);
SetWindowPos(NULL, rc.left, rc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
return TRUE;
}
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello friends,
I am trying to built in project in Visual Studio 2005. Project is created in MFC(Application project) and Visual studio 2003 by other person.
I am getting an error while comping. The error points towards
some file comsuppwd.lib .
I am just putting error names here as follows,
error LNK2005: "class _variant_t vtMissing" (?vtMissing@@3V_variant_t@@A) already defined in comsuppwd.lib(comutil.obj) comsuppd.lib
and other is
fatal error LNK1169: one or more multiply defined symbols found
I searched on net but not able to solve this error. please help me.
Thanks in Advance.
|
|
|
|
|
"Explicit references to comsupp.lib, either from the comment pragma or via the command line, should be changed to now use either comsuppw.lib or comsuppwd.lib, as /Zc:wchar_t is now on by default. comsupp.lib should still be used when compiling with /Zc:wchar_t-." from msdn.
try setting "vsproperty->language->Treat wchar_t as Built-in type = No". or specify the lib as above.
|
|
|
|
|
We solved this by Ignoring the library comsuppd.lib/comsuppwd.lib
Properties->Linker->Input->Ignore Specific Library
Hope it helps you
Thanks,
Vijay
|
|
|
|
|
I want to burn the data in DVD using the inbuit software in windows xp operating system.How to do it. I want to do in vc++ dialog based application.
|
|
|
|