|
bhanu_8509 wrote: new Dialog1();
If you are creating dialog using new, then in each button click, a new instance of dialog will be created. It might be the reason of memory leak. I think you need to create them once, and reuse it again and again.
- ns ami -
|
|
|
|
|
please tell me how to do this. i cannot create a global object to each and every dialog. frankly I dont know how to create global objects which can be accessed in other dialogs.
thanks.
|
|
|
|
|
For such an application a main dialog/window should be there to track these button selections... So that these kind of recursive DoModal can be avoided.
A sample... not perfect but only to get the idea.
void CMainDlg::ShowDlgs()
{
for( ;; )
{
int nNextDlg = 1;
switch( nNextDlg )
{
case 1:
{
Dialog1 dlg;
nNextDlg = dlg.DoModal();
}
case 2:
{
Dialog2 dlg;
nNextDlg = dlg.DoModal();
}
case ID_EXIT:
return;
}
}
}
Better is to make the use of user/registered message communication between parent (main dialog/window) and child dialogs (Dialog1, Dialog2, etc.), but I don't know exactly what you are trying to do.
- ns ami -
|
|
|
|
|
Why not...
void CMyFirstDialog::OnButtonOne ()
{
EndDialog (ID_BUTTON1);
}
....
...
CDialog *pDlg = new CMyFirstDialog ();
int nReturn = 0;
while (pDlg)
{
nReturn = pDlg->DoModal ();
delete pDlg;
pDlg = NULL;
switch (nReturn)
{
case ID_BUTTON1:
pDlg = new CFirstDlg;
break;
case ID_BUTTON2:
pDlg = new CSecondDlg;
break;
....
}
}
ASSERT(!pDlg);
OK, that was very quick and hacky - with no real error checking, but I hope it gives you an idea. The main difference is you wait till one dialog is finished and tidied up, *then* move on to the next one. Other wise, they just stack one on top of the other...
Iain.
switch (
Codeproject MVP for C++, I can't believe it's for my lounge posts...
modified on Tuesday, January 27, 2009 9:54 AM
|
|
|
|
|
I'm not certain I understand correctly what you want to achieve.
I don't have iTunes in front of me; and I don't see what you mean by "clicks on a button at the right panel".
Me think it's quite moronic to call DoModal() recursively.
If you want to create and display N dialogs M number of times, you'd better
use modeless dialogs and be conscious about managing the memory (when you
create and destroy the dialogs).
|
|
|
|
|
No I dont want to use modeless dialogs. I will try with Ian suggestion and get back to you all.
Thanks.
|
|
|
|
|
Hello Community,
i need to check if users have change the selection in CListCtrl,
i have now this if users change selection with the mouse(mouse click),
but the selection change is posible with the arrow keys too!
How to check this event: user change selection with arrow keys in CListCtrl,
i need to do some updates if there is a new selection in CListCtrl??
Thanks for any help!!
termal
|
|
|
|
|
termal wrote: How to check this event: user change selection with arrow keys in CListCtrl
Make the use of LVN_ITEMCHANGED notification.
- ns ami -
|
|
|
|
|
Hello,
thanks for answer, i try this way!
regards
termal
|
|
|
|
|
Please handle LVN_ITEMCHANGED[^] message. When a selection change occurs in the list control, the parent dialog/window will get a LVN_ITEMCHANGED message
|
|
|
|
|
Hello,
thanks for answer and i hope its ok if i answer here to naven only??
Yes this works fine, and easy to implement this funktion!
Only one funny thing is now in execution of program, this LVN_ITEMCHANGED is send 3 times?? Also my function i called 3 times??
Here my code:
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST, &CMyDialog::OnLvnItemchangedListAll)
void CMyDialog::OnLvnItemchangedListAll(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<lpnmlistview>(pNMHDR);
int iCurIndex = m_cListAll.GetSelectionMark();
CString csItemText = m_cListAll.GetItemText(iCurIndex, 1);
TRACE(L"%s\n", csItemText);
PrintData(csItemText);
*pResult = 0;
}
</lpnmlistview>
So is in output the same text 3 times listed , for example if i have text in my current selection: www.codeproject.com
they is dump three times , any idea how to avoid this(if possible ), or is this common property??
But this is that what i'm looking for!
Thanks for help!
termal
modified on Tuesday, January 27, 2009 10:02 AM
|
|
|
|
|
That is because the notification is sent for different states. You can check the new and old state flags in the "LPNMLISTVIEW pNMLV". And if the new state is selected and old is not selected, then proceed it.
- ns ami -
|
|
|
|
|
termal wrote: thanks for answer and i hope its ok if i answer here to naven only??
Its ok. I will inform ns.ami cause he is my friend and we both work in same company
termal wrote: Only one funny thing is now in execution of program, this LVN_ITEMCHANGED is send 3 times??
Yes this is because, the LVN_ITEMCHANGED is fired not only for selection change but also for foucs changes. So you should check, whether the current LVN_ITEMCHANGED is for selection change or not.
NM_LISTVIEW* pNMListView = reinterpret_cast<NM_LISTVIEW*>(pNMHDR);
if( LVIF_STATE == (pNMListView->uChanged&LVIF_STATE) )
{
if( LVIS_SELECTED == (LVIS_SELECTED&pNMListView->uNewState) )
{
}
else if( LVIS_SELECTED == (LVIS_SELECTED &pNMListView->uOldState) )
{
}
}
|
|
|
|
|
Hello,
thank you very much to you and ns.ami for help, it works now!!
with best thanks
termal
|
|
|
|
|
Naveen wrote: he is my friend and we both work in same company
Please don't tell the truth...
- ns ami -
|
|
|
|
|
I have an application, where i open the private Queue. This works fine.
But when I run this app as a windows service, it gives an error failed to open the Queue, Access is denied.
I know it has got to do something with the rights.
If the app is run as an exe, it will have the logon credentials. When run as windows service it will run with System credentials, which may not have access to Private Queue.
How do i enable my windows service to have access to the private Queue???
Any help will be great.
Thanks,
Saleem
|
|
|
|
|
Md Saleem Navalur wrote: How do i enable my windows service to have access to the private Queue???
Did you try setting the Log On Properties for the service to use the same account as the queue?
|
|
|
|
|
Yes i tried that, it works.
|
|
|
|
|
Hello everybody,
is it possible to determine at realtime the function which has called the current function?
Example
void A(void)
{
DoWork();
}
void B(void)
{
DoWork();
}
void DoWork(void)
{
char *trace = GetTraceOf5LastFunction();
OutputDebugString("DoWork called from function : ");
OutputDebugString(trace);
}
Is it possible?
Big thanks for any help
Edit:
I have found a fonction called "backtrace" which is placed into execinfo.h
But i don't have a such header-file on my system (Visual Studio)
modified on Tuesday, January 27, 2009 6:26 AM
|
|
|
|
|
Can you use of dll's you can load your functions of dll on the current function.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Is there a DLL which executes the work of backtracing?
|
|
|
|
|
Hi,
the easiest way may well be the low-tech one: add a string parameter to the function, and pass the caller's name. That works no matter what.
DoWork("A");
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Tuesday, January 27, 2009 8:10 AM
|
|
|
|
|
This method is the simplest, but i can't write over 100 Debug-Lines into the code
But thanks anyway
|
|
|
|
|
Hi baerten,
I agree with Luc. However you may be able to use a pre-defined macro[^] something like below:
VOID FunctionB(int iVal,char *caller,int line)
{
char szBuf[MAX_PATH];
sprintf(szBuf,"I was called by %s on line %d",caller,line);
MessageBoxA(NULL,szBuf,0,0);
}
VOID FunctionA()
{
FunctionB(1,__FUNCTION__,__LINE__);
}
baerten wrote: i can't write over 100 Debug-Lines into the code
A stack trace is several times more expensive at runtime.
Best Wishes,
-David Delaune
|
|
|
|
|
You need a stack walking function. Here are some[^] links[^] that may be useful.
The second is probably best - John Robbins is a well regarded expert on debugging and things like that. His SUPERASSERT code includes stack tracing code - see the dialog screenshot about half way through the article for an example of what you can get. Obviously you only need the last item in the trace.
One last thing - IIRC, without debug symbols, all you're going to get is the address that called you, not a function name.
|
|
|
|