|
See if this article helps.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
DEar Friends,
I got the solution. Actually the problem was in the attached lib file. After linking the another or seperate .lib file seperately in Release/Debug mode, problem get solved.
Anyway thanks for your kind co-operation.
Bye
Billar
|
|
|
|
|
dears:
In the following function both Visual C++ 6 and (Insure++ software that detecting memory leaks and bugs) pointing that there are a memory leak in this statement in this function
Since
*CWorkAreaWnd derived from CWnd.
*CDrawObject Derived from CObject and it is the base class for all objects(Shapes here).
* and CDrawObject has m_ObjTracker member function of Type CRectTracker.
code:--------------------------------------------------------------------------------
void CWorkAreaWnd:rawTracker(CDrawObject *pDrawObject , POINT point )
{
/*
** Create Tracker for the selected object.
*/
CPoint n = point ;
CDrawEditor32App * pApp = (CDrawEditor32App*)AfxGetApp();
CDrawEditor32Doc *pDoc = pView->GetDocument();
CRect rect ,objectRect = pDrawObject->getObjectRect();
if (pDrawObject->m_ObjTracker)
{
pDrawObject->m_ObjTracker = NULL;
delete pDrawObject->m_ObjTracker;
}
//////////////////////////////////////////////////////////////////////////////////
pDrawObject->m_ObjTracker = (CTrackerObj *)new CTrackerObj(objectRect,CRectTracker::dottedLine |CRectTracker::resizeInside |CRectTracker::resizeOutside );
//Here compiler and Insure indicate memory leak
/////////////////////////////////////////////////////////////////////////////////
if ((pDrawObject->m_ObjTracker))
{
if(!bArrowKey && !pDoc->pDrawClass->bMultiSelection)
pDrawObject->m_ObjTracker->Track(this, point, TRUE );
else
pDoc->m_Change = TRUE;
pDrawObject->m_ObjTracker->m_rect.NormalizeRect();
CRect TakerRect = pDrawObject->m_ObjTracker->m_rect;
if(!objectRect.EqualRect(TakerRect))
{
rect = pDrawObject->CalculateDimensionRect(TakerRect);
pDrawObject->setObjectRect(rect);
}
}
}
--------------------------------------------------------------------------------
but the problem if i add this at the end of the Fucntion
-------------------------------------------------------
code:
delete pDrawObject->m_ObjTracker;
-------------------------------------------------------------
the program will crash when draw something in screen .
where is the right place to perform free memory in this case?
and why crashing occured since i free memory before the scope of the fucntion end up.
Thanks
|
|
|
|
|
You might get the crash if you don't set pDrawObject->m_ObjTracker to NULL at the end. You will most probably have forgotten to add a delete in the destructor as well
You can, however, make the DrawObject class manage its own memory. Add a function CreateTracker instead of allocating memory in the calling function. In CreateTracker, delete the old tracker if it exists and create a new one with new . Make sure to delete the tracker in the DrawObject destructor.
You are making a maintenance nightmare for yourself by allocating part of a class outside the class, naughty, naughty, naughty *slap on wrist*
|
|
|
|
|
dear:
I got ur point and u r completely right, it is a big nightmare to locate var in calling fucntion, I'm changing the code as u said.
Thanks
|
|
|
|
|
Anyone know how to write a getProcessor ID and getProcessor String?
"Naked we come and bruised we go."
- James Douglas Morrison
Best Wishes,
ez_way
|
|
|
|
|
Take a look at this
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Great answer that you very much1
"Naked we come and bruised we go."
- James Douglas Morrison
Best Wishes,
ez_way
|
|
|
|
|
Hi, I have created a simple tetris game for a school project alogn with some firends. I currently am having a dilema. I have two problems. One has to do with the topic of this message; I am trying to write the score of the game when ever the score of the current game is higher than the score in the file. So if I played and got 1000 points then died it woudl write 1000 to a file (points.txt), and if you played after and got over 1000 it would override my score with yours, but if you got less it wouldnt... Afterwards I want to read the file and output the score within on the score as "highscore: ___". So how do I do this? Source require please... visual is new to me...I'm used to dev c++. I am lookign for a simple way of reading and writing (like adding a .h and calling on one of its functions to read or write). I know abotu fstream but I cant seem to get it to work..
P.S) the second this I was having problems with is I am lookign for a pause function....but that can wait.
Thanks in advanced
Glen Buchholz
|
|
|
|
|
>> I know abotu fstream but I cant seem to get it to work..
Your in a school C++ course and no one can show you how to get fstream working? What school is it?
unsigned long score = 0L;
std::ofstream os("sample.txt");
score = 1000;
os << score;
os.close();
std::ifstream is("sample.txt");
is >> score;
is.close();
>. I am lookign for a pause function
::Sleep( 5000); // sleep for 5 seconds
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Thanx, so much.
Got it working perfectly
P.S) Its a high school and we do things in Dev C++... which we had fstream workign in...vc++ is a bit different...
|
|
|
|
|
All resources of my application is designed in 1024 * 768 pixels resolution ,
after changing the resolution in to standard 800 * 600, some of the screen is beyond the visible area. i want to change my application in a manner that that must work in any resolution ( i found some applications do this very nicely ).
is there any code to do this?
and one more thing, how can i get the current resolution of screen and how can i change that by code?
Thankyou
I want to change Myself..Can u help me?
|
|
|
|
|
Well the main stream approach to building desktop applications is to use windowing techniques to avoid any specific screen resolution dependencies. If I ever installed a desktop application that changed my screen resolution on me I would get rid of it faster than you can say “bite me”.
With that said here is a controversial article to that end:
http://www.codeproject.com/gdi/screenresolution.asp[^]
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
i want an API/code for changing to any resolution that supported by my graphics card.
thank you.
I want to change Myself..Can u help me?
|
|
|
|
|
ChangeDisplaySettings is what you want.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Just a guess, but I would figure you'd find the screen dimensions inside GetSystemMetrics
How do I print my voice mail?
|
|
|
|
|
Hey All,
I am having a small problem setting the focus to a control on a property page in my OnInitDialog() function.
BOOL CPage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
<snip>
if (some_condition)
{
m_Edit.SetReadOnly();
m_ComboBox.SetFocus();
}
else
m_Edit.SetFocus();
return FALSE;
}
It does not matter if some_condition is TRUE or FALSE, the m_Edit control always has the input focus. m_Edit is the first control in the tab order. Does returning FALSE from OnInitDialog() not work for property pages, or am I missing something?
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
For a CPropertyPage -derived class, you need to use the OnSetActive() method instead.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Ok, I am starting to feel like a complete idiot. I still can't get this to work.
BOOL CPage::OnSetActive()
{
BOOL ret = CPropertyPage::OnSetActive();
if (some_condition)
m_Combo.SetFocus();
return ret;
}
m_Combo.SetFocus is called successfully, but the focus remains on the edit control when the page finally shows.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
How about:
#define MSG_SETFOCUS WM_APP+1
BOOL CPage::OnSetActive()
{
BOOL ret = CPropertyPage::OnSetActive();
if (some_condition)
PostMessage(MSG_SETFOCUS);
return ret;
}
LRESULT CPage::MySetFocus( WPARAM, LPARAM )
{
m_Combo.SetFocus();
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
That definitely works, thanks. I will use that hack for now.
But is it really necessary to go through that that type of hack to set the focus to a control? There is obviously something that I am missing.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
'Tis not a hack:
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q148/3/88.asp&NoWebContent=1
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Just because MS does it, does not mean it's not a hack;P
Thanks for the help and the link
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
I simply provided the link so you would have something to reference. Since the tab is the first control on the property page, it only makes sense that it would receive initial focus. I don't consider using PostMessage() a hack.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Ok im going to sound like an idiot asking this... But im having trouble figuring this out.. I'm trying to get it when i click "Button A" It will some words in "Text Box A" Yea im a newb i look like a newb i feel like a newb! Just someone help me please!
|
|
|
|