|
Terry,
I can see a chance of serious synchronization error. Your UpdateData() is called after sending notification to the parent? In that case, your child dialog will get deleted by parent dialog and after deletion you might be calling UpdateData() which will endup in assertion from MFC. Its a wild guess, since i don't have the full picture of your code.
Trupti Mehta wrote:
i have a practise of calling just dd.~DeptDetails(), but someone pointed out, "Calling destructor without freeing the memory", so where am I going wrong. And keeping that in mind, in many such places I have called free(&dd) before the destructor.
As per C++ standards, you can call destructor only if the object is allocated by placement new . http://weseetips.com/2008/04/01/construct-c-objects-at-predefined-memory-locations/[^]. But i am not sure, whether its legal in WinCE where rules are different.
Trupti Mehta wrote: t present I pass object via parent & update the parent back by CHANGED_DS message. Is their any better way to work out which might reduce sending msg to parent for updated object.
Keep DeptStock as a member of parent and Let the child windows keep a reference to your DeptStock and update that. When the parent window create you child window, pass DeptStock as constructor parameter by reference. So the child dialog can keep a reference to it. So that you can directly modify the DeptStock, by being in the child dialog itself and can avoid that message updating mechanism. You can also use pointers.
Feel free to ask any doubts, and i'll try to help with my limited knowledge.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Jijo raj wrote: I can see a chance of serious synchronization error. Your UpdateData() is called after sending notification to the parent? In that case, your child dialog will get deleted by parent dialog and after deletion you might be calling UpdateData() which will endup in assertion from MFC. Its a wild guess, since i don't have the full picture of your code.
No Jijo, after finishing all taks only communicating with the parent happens. On user clicks to "Yes" button only the child communicates with the parent.
The child1 has a text box, user enters in it & clicks on "Get Data" btn, on that click :
Thanks
Terry
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">Jijo raj wrote:</div>I can see a chance of serious synchronization error. Your UpdateData() is called after sending notification to the parent? In that case, your child dialog will get deleted by parent dialog and after deletion you might be calling UpdateData() which will endup in assertion from MFC. Its a wild guess, since i don't have the full picture of your code.</blockquote>
No Jijo, after finishing all taks only communicating with the parent happens. On user clicks to "Yes" button only the child communicates with the parent.
The child1 has a text box, user enters in it & clicks on "Get Data" btn, on that click :
void CPage1Dlg::OnGetData()
{
AfxMessageBox(_T("Into OnGetData"));
UpdateData(true);
OperatorDetails od;
if (true) {
m_operName = "Trial";
UpdateData (false);
AfxMessageBox(m_operName);
EnableConfirm(true);
} else {
m_operName = "";
EnableConfirm(false);
}
od.~OperatorDetails();
UpdateData (true);
return;
}
void CPage1Dlg::EnableConfirm(bool enable)
{
if (enable) {
GetDlgItem(IDC_NAME_BTN)->ShowWindow(false);
GetDlgItem(IDC_CONFIRM_LABEL)->ShowWindow(true);
GetDlgItem(IDC_YES1_BTN)->ShowWindow(true);
GetDlgItem(IDC_WRONG_BTN)->ShowWindow(true);
} else {
GetDlgItem(IDC_NAME_BTN)->ShowWindow(true);
GetDlgItem(IDC_CONFIRM_LABEL)->ShowWindow(false);
GetDlgItem(IDC_YES1_BTN)->ShowWindow(false);
GetDlgItem(IDC_WRONG_BTN)->ShowWindow(false);
}
}
Then the user has to click Yes or No button. On No, the focus again return to the text box & on yes:
void CPage1Dlg::OnYes()
{
OperatorDetails* odet(m_number, m_operName);
deptStock.SetOperator(odet);
free(&odet);
odet.~OperatorDetails();
TellParent();
return;
}
void CPage1Dlg::TellParent()
{
this->CRHPostMessageToParent(WM_CHANGED_DS, (int)&deptStock);
this->ShowWindow(SW_HIDE);
this->CRHPostMessageToParent(WM_SHOW_NEXT_VIEW, 2);
return;
}
I hope I have made my code very clear to you. You can see the last UpdateData is called in GetData() only. The Assertion Failure & Unsupported operation was attempted message box come in GetData(), 2 times before "Trial" messagebox & 1 time after that. If I comment those 3 UpdateData in GetData(), no such exceptions/messages.
Thanks
Terry
|
|
|
|
|
Jijo raj wrote: Keep DeptStock as a member of parent and Let the child windows keep a reference to your DeptStock and update that. When the parent window create you child window, pass DeptStock as constructor parameter by reference. So the child dialog can keep a reference to it. So that you can directly modify the DeptStock, by being in the child dialog itself and can avoid that message updating mechanism. You can also use pointers.
Thanks jijo, this helped me reduce 1 message to the parent & solved out of memory problem. Based on your info reg. calling destructors, I studied over it & removed all lines wher I have unnecessarily explicitly call the destructor.
This helped, but Still Assertion Failed continues. In fact on ending the child1 & showing child2, i get error message based on wincore lib. Child 2 is visible but the error keeps on coming for some time & then again normal. It seems like something is uncompatible or am doing it wrongly. Can I pass you the code, so you can help me much better. Please let me know how do I send you the parent & child file.
Please help me.
Thanks
Terry
|
|
|
|
|
It seems to me direct call of destructor (od.~OperatorDetails() and so on) is very bad technique (((
|
|
|
|
|
Artem Kustikov wrote: It seems to me direct call of destructor (od.~OperatorDetails() and so on) is very bad technique (((
Then what technique to use?
free(&obj);
obj.~Objct();
I don't get any error or exception no, or stack. On retry it immediately shows "An unsupported operation was attempted". Alt+7 also doesn't work. I am not able to debug or give breakpoints with CE & eVC++4. If their is a way to work out, let me know. To figure out such errors, I always opt for debugging only.
Thanks
Terry
|
|
|
|
|
Hi all,
I have made a dialog based application from which i am calling another dialog based application using shell execute. Now what i want is when my second application is displayed first aplication should hide and it should not be diaplayed in task bar also, and when second application finishes it task first application should become visible.
I tried doing it using:-
CDialog::OnShowWindow(SW_HIDE,SW_PARENTOPENING);
but it doesnot hide the window.
How can i do this....
Thanks in advance
|
|
|
|
|
Instead of ShellExecute() , Create the process by using CreateProcess() . From the PROCESS_INFORMATION structure, you'll get the new process handle.
Now hide yourself by calling ShowWindow( FALSE ) function and wait until your second process gets finished by calling MsgWaitForSingleObject( hSecondProcess, ...) . Now your first application is in waiting state.
Once the second child process is finished, the MsgWaitForSingleObject() will returns and now, show your window again by calling ShowWindow( TRUE ) .
If can use WaitForSingleObject() instead of MsgWaitForSingleObject() , but then your first application dialog will not process any messages.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
You should call ShowWindow(SW_HIDE); instead of OnShowWindow.
-Saurabh
|
|
|
|
|
You need to handle to these programs and then you can use of ShowWindow().
|
|
|
|
|
Hello everyone!
I'm trying to make something similar to the color toolbar in MS Paint. A regular toolbar doesn't do the job, so I must create my own... But how? I can't derive my class from CToolBar (at least not with the class wizard).
I tried deriving from CToolBarCtrl, but I can't figure out how to put it in my window/make it dockable.
Any clues? Thanks in advance!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Will this help. [^]
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Okay, I figured it out. Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Hi,
i'm using the classes from Barretto VN http://www.codeproject.com/KB/tree/enumdeskclones.aspx to build a Win32ExplorerTreeView & ListView and it works very good.
Now i want to load and view an (in the Listview)doubleclicked file in another view, so i need to get the full path name and extension of a file when it is double clicked in a listview for example :
F:\WORKING\MISC\OpenGL C++\OGL\MilkshapeModel.cpp
I think a need a shell function or something like that?
Could you help me with this?
Best regards Croc
|
|
|
|
|
You are not showing the full path of the file obviously, otherwise it would have been too easy to get it from there , but when you get the file name intially (from whatsoever method by extracting string from the selected path or finding files from a directory) do you store the rest of the path and extension of the file in some variable. May be a vector or something? if yes, then when the user clicks on the selected file you can map the entry in the list view to that in your data structure, prepend the path to the file name and do a ShellExecute ( not very sure that you would be needing ShellExecute.)???
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Tkanks for your quick replies, perhaps you have the time to look a bit closer to the example, becuse i tried to get these information from the file for 2 days now and it wouldn't ! . Perhaps you could help me with some details specified to this example !
Best regards
croc
|
|
|
|
|
I didn't have a look at the code as of now. Did you try what I suggested?
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Yes i tried it, but
Here is the code of the function, it's a lot but i hope it will help!
void CShellListView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
{
CString text;
char szBuff[MAX_PATH];
CString ptrPath[5];
int i = 0;
LVHITTESTINFO lvhInf;
GetCursorPos(&lvhInf.pt);
ScreenToClient(&lvhInf.pt);
int item = ListView_HitTest(GetListCtrl().m_hWnd, &lvhInf);
if((LVHT_ONITEMLABEL & lvhInf.flags ) || (LVHT_ONITEMICON & lvhInf.flags))
{
LPTVITEMDATA* lptvid = NULL;
lptvid = (LPTVITEMDATA*) m_pMalloc->Alloc (sizeof (LPTVITEMDATA));
LVITEM lvi;
lvi.mask = LVIF_PARAM;
lvi.iItem = lvhInf.iItem;
ListView_GetItem(GetListCtrl().m_hWnd, &lvi);
lptvid = (LPTVITEMDATA*)lvi.lParam;
ULONG uAttr = SFGAO_FOLDER;
lptvid->lpsfParent->GetAttributesOf(1, (LPCITEMIDLIST *) &lptvid->lpi, &uAttr);
if(uAttr & SFGAO_FOLDER)
{
CShellClass csc;
csc.GetName(lptvid->lpsfParent , lptvid->lpi , SHGDN_NORMAL, szBuff);
this->m_pShellTreeView->SelectThisItem(szBuff);
IShellFolder *psfProgFiles = NULL;
HRESULT hr = lptvid->lpsfParent->BindToObject(lptvid->lpi, NULL, IID_IShellFolder, (LPVOID *) &psfProgFiles);
if(FAILED(hr))
return;
lptvid->lpsfParent = psfProgFiles;
LVPopulateFiles(lptvid);
text = szBuff;
ptrPath[i] = text;
AfxMessageBox(ptrPath[i]);
i++;
}
else
{
AfxMessageBox(ptrPath[0]+ptrPath[1]+ptrPath[2]+ptrPath[3]);
}
}
*pResult = 0;
}
Best regards
Croc
|
|
|
|
|
I have not looked at these classes but why don't you just add a handler and/or a member variable for your purpose?
|
|
|
|
|
CrocodileBuck wrote: I think a need a shell function or something like that?
Sounds like SHGetPathFromIDList() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi Mr.Crow,
yes i tried it with this function, but i didn't manage to get the file path, name and extension.
Could you perhaps explain me how to use this function in the right way?
Best regards
Croc
|
|
|
|
|
Assuming you have a valid IDL pointer:
LPITEMIDLIST idl;
TCHAR szPath[MAX_PATH];
SHGetPathFromIDList(idl, szPath);
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
CrocodileBuck wrote: how to use this function
See here[^].
|
|
|
|
|
I am making web Crawler. I can get hard coded URL but not able to get dynamic generated URL (URL contain ? mark ). Can you tell me, how can i get this in C++.
|
|
|
|
|
sumit.durg wrote: but not able to get dynamic generated URL (URL contain ? mark ).
From where do you want to get this "dynamically generated URL"
and where do you get the hard code URL from?
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|