|
Hi,
Question: how to pass data between two dialogs (which are in Tab Control)...
For example if we have ListBox1 in Dialog1 and we want to add string to ListBox1 from Dialog2 how to do that?
I try to include Dialog1 header file in Dialog2 and add object ( Dialog1 object_Dialog1;) in to Dialog2,
and then in handler for some button in Dialog2, I wrote:
object_Dialog1.m_ListBox1.AddString(_T("s")); //m_ListBox1 is control variable for ListBox1 in Dialog1
but that cause ASSERT in afxwin2.inl :
_AFXWIN_INLINE int CListBox::AddString(LPCTSTR lpszItem)
{ ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem); }
Does anybody knows how to pass data between two dialogs in Tab Control?
Best Regards
|
|
|
|
|
Hello,
What i usually do in that cases is to use a kind of data model at parent dialog box level.
Each tab works only with the data model.
You monitor Activation unactivation of each tab and update itself based of changes in the common data model.
hope this will help.
Regards
Franck
|
|
|
|
|
Does it means that we can't pass data between dialogs in tab control in a simple way like I try to do it?
Do you know simple way that works ?
And do you know why that ASSERT IsWindow... is triggered?
Regards
|
|
|
|
|
I've never found a reason to fight with a tab control (i.e., CTabCtrl ). Use a property sheet in place of the dialog, and a property page for each tab and you'll be on your way in a matter of minutes. You can use the parent to pass data back and forth between tabs very easily.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Does it means that we can't pass data between dialogs in tab control in a simple way like I try to do it?
Does anybody else knows simple way that works ?
Regards
|
|
|
|
|
The real problem seems to be how you got a dialog 1 object in the dialog 2 class. Your comments seem to say to declared a variable and your reference (with .) seems to say that you instantiated a dialog 1 class inside dialog 2. So, how do you know this instantiation actually points to the dialog 1 that is being displayed.
declaring the variable does *not create the dialog window*. Clearly, to have dialog 1 displayed, somebody has to instantiate it and create it. It was probably your main program (the same one that instantiated dialog 2).
The error is saying that "the object you are referencing (dialog 1) is not a valid window" and that would be true if you never created.
Now what you want to do it obtain the *pointer to dialog 1* created by your parent / main program and store it in a local pointer in dialog 2. Then you can access it with "object_dialog1->m_list......."
Chuck
|
|
|
|
|
Hi Chuck,
I got a class MyTabControl(:public CTabCtrl), in which I create dialog1 and dialog2 in constructor of that class, and in main dialog(called MainDialog) I instantiated those two with object(In main dialog .h I have a object MyTabControl objectMyTC;)
So I try to do this (...on click some button in Dialog1 I wanna to access m_ListBox2 in Dialog2 from Dialog1 in TabControl):
In Dialog1.h I declare:
MainDialog* p_MainDialog;
and in Dialog1.cpp I wrote:
Cwnd* pWnd = (CWnd*) p_MainDialog->objectMyTC.m_Dialog2->GetDlgItem(m_ListBox2);
but when I click button, that also didn't work, I get an exception (..acess violation reading location 0xcdcdeb1).
When I try to debug this line i saw that all objects in MainDialog have hWnd=??? so I guess this has something with it.
Can You please help me what I am doing wrong?
Best Regards and thanks
|
|
|
|
|
0xcdcd...is indicitive of an unitialized variable. You declared p_MainDialog but did you put anything into it?
|
|
|
|
|
Hi Chuck,
I just declare it like I wrote .. I guess I need pointer to parent(main) dialog window....
How You mean "...did you put anything into it? " ...I dont understand?
Can You help me to solve this problem?
Simple sample code (variation of what I wrote)....
Regards
|
|
|
|
|
Where is the statement like:
p_MainDialog = ??????;
as far as I can see, you only declare p_MainDialog but do not initialize it. Since the error indicates an uninitialized variable, I bet they're related.
|
|
|
|
|
Hi,
I put that statement in class Dialog1 in Dialog1.h .
Now I try do declare it in onButton function like MainDialog* p_MainDialog = NULL; // Is this right I guess not ?
but I also get unhandled exception at 0x0045ca30 ....Access violation reading location 0x000000e4.
hWnd is still = ???
Do You know right way to do this?
Regards
|
|
|
|
|
I do not want to sound cruel or anything but if you think that setting a pointer to NULL and then refernceing that pointer would do anything other than crash / throw an exception, you're going to need to take some classes or read a book on programming. I cannot debug your progam for you one message at a time and I'm not inclinded to write it for you.
You will be better off finding someone at your work or in your class to help you with this.
|
|
|
|
|
Hello people!
In our application we have several floating windows next to the main window. One of these float windows is time to time "in the center of attention", even though it might not be the focused/active window of the application. For example the user clicks one of the floats to signalize that he will edit this window and then starts clicking around the main window's controls to make his changes. This, of course, makes the main window the active one and then there is no indication anymore which float will be affected if the user changes anything on the main window. So i got the instruction to "make the float window look active" (not my idea...). I know i could take over the whole border and caption drawing of these windows using WM_NCPAINT but i am hoping for an easier solution. So does any of you know how i could force the window to draw itself as if it was active?
Thanks in advance for any suggestions.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Since the editing is being done in the main window, that is currently active.
And so the last active window becomes inactive.
So you will need to do custom drawing as you said to make this look active.
Another idea will be to make the floating window as top most so that it stays above all windows, even the main window.
Another way will be to change the title bar of the floating window to read something like "Active Window".
Another way would be to call FlashWindow[^] on the floating window till the editing is done, probably in a thread or something.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
«_Superman_» wrote: Since the editing is being done in the main window, that is currently active.
And so the last active window becomes inactive.
-this i understand completely
«_Superman_» wrote: So you will need to do custom drawing as you said to make this look active.
-if nothing better comes up i will have to sadly...
«_Superman_» wrote: Another idea will be to make the floating window as top most so that it stays above all windows, even the main window.
-the floats already are on top of the main window but if they don't overlap each other or any other windows then being on top doesn't really show anything to the user...
«_Superman_» wrote: Another way will be to change the title bar of the floating window to read something like "Active Window".
-i had the same idea and already implemented it but i would like to do the "active looking" part too if it is possible somehow
«_Superman_» wrote: Another way would be to call FlashWindow[^] on the floating window till the editing is done, probably in a thread or something.
-i doubt the users would like that
Thanks for the suggestions.
p.s: Now i am experimenting with WM_NCACTIVATE[^] to not allow inactive painting but i either misunderstood something completely or the help there is misleading because it has the nice sideefect of really not allowing the window to loose activity, once it is up it stays active and i can't click anythging on the main dialog until i close it (from the online help i thought it would only affect drawing).
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Hi all,
I am using date picker control in my dialog. I want to set an old date in that control. following is my code.
SYSTEMTIME sysTime;
memset(&sysTime, 0, sizeof(sysTime));
sysTime.wYear = 2008;
sysTime.wMonth = 8;
sysTime.wDay = 5;
sysTime.wHour = 2;
sysTime.wMinute = 20;
sysTime.wSecond = 20;
sysTime.wDayOfWeek = 1;
m_ctrlDate.SetFormat(_T("dd-MM-yyyy"));
m_ctrlDate.SetTime(&sysTime);
The date picker control is showing date 1/1/1970. How to set date in that control.
Thanks,
|
|
|
|
|
I tried the code that you wrote and it works perfectly.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Same here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi
When i passing the arguments through comment line arguments ..its running good ..and also i can able to see the output ,
my prob is when i use in debugging mode ..its thrown some exception
Unhandled exception at 0x7c81eb33 in Segmentation.exe: Microsoft C++ exception: pnm_error at memory location 0x0012fb6b..
why this kind of prob ..arise ..plz explain ..
Thanks
|
|
|
|
|
Have you the debugger? Use it! Have a look at the 'call stack' window.
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
[My articles]
|
|
|
|
|
Thanks for your response ...
|
|
|
|
|
raju_Code wrote: why this kind of prob ..arise
With what little information you've provided, it could be most anything. What command-line arguments are you sending? How are they being used? What are the compiler/linker differences in release vs. debug mode? Have you stepped through the code using the debugger to narrow down the problem to just a handful of statements?
The common practice these days seems to be to copy/paste some code (I prefer to type all of my code in, especially as a beginner, so I know exactly what is going on), compile it, then run the program. If it does not work, find nearest programming forum and ask for help.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
When I declare a LVFINDINFO object in the function body, EnumChildWindows fails to locate the control of SysListView32 type (a Windows class type). When I remove the LVFINDINFO object from the body, it works well.
The code snippet is as the below.
void CMainDlg::OnBnClickedGetDolby()
{
KillRunningApplet(_T("Sound"));
if(!LaunchCplApplet(_T("mmsys.cpl"), 0, 0)) {
OutputDebugString(_T("LaunchCplApplet fails. \n"));
return;
}
CWnd* pWnd = NULL;
int i = 0;
while(!pWnd) {
pWnd = FindWindow(NULL, _T("Sound"));
if(pWnd) {
OutputDebugString(_T("Found Sound window. \n"));
break;
}
Sleep(10);
i++;
if(i > 1000) {
OutputDebugString(_T("Sound window is not found. \n"));
return;
}
}
m_pListView = NULL;
EnumChildWindows(pWnd->m_hWnd, DoSomethingHelper, (LPARAM)this);
if(m_pListView) {
OutputDebugString(_T("Got SysListView32"));
}
else {
OutputDebugString(_T("SysListView32 is not found."));
return;
}
m_pListView->SendMessage(WM_KEYDOWN, VK_DOWN, 0);
CListView* pView = (CListView*)m_pListView;
CListCtrl& Ctrl = pView->GetListCtrl();
LVFINDINFO info;
int iIndex = 0;
info.flags = LVFI_PARTIAL | LVFI_STRING;
info.psz = _T("Speaker");
}
BOOL CALLBACK DoSomethingHelper(HWND hwnd, LPARAM lParam)
{
TCHAR sClassName[MAX_PATH] = {0};
GetClassName(hwnd, sClassName, MAX_PATH);
if(wcscmp(sClassName, _T("SysListView32")) == 0) {
CMainDlg* pMain = (CMainDlg*)lParam;
pMain->m_pListView = CWnd::FromHandle(hwnd);
}
OutputDebugString(sClassName);
return TRUE;
}
Maxwell Chen
|
|
|
|
|
Okay, never mind. Constructing the LVFINDINFO object takes some time so EnumChildWindows takes longer time to complete. So I added a Sleep(10) after EnumChildWindows call to make it happy.
Maxwell Chen
|
|
|
|
|
Maxwell Chen wrote: pMain->m_pListView = CWnd::FromHandle(hwnd);
Since CWnd::FromHandle documentation [^] states:
The pointer may be temporary and should not be stored for later use.
I would use instead something like
pMain->m_hListView = hwnd;
and then obtain the CWnd pointer inside the CMainDlg::OnBnClickedGetDolby body.
Anyway I really don't know if it would help.
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
[My articles]
|
|
|
|