Duplicate Dialogs
-
Hi, I posted this last week, and tried to work on this over the weekend but with no success. This is something that i can't seem to figure out. Can someone tell me how to do this exactly? I never really coded before and this is causing me much headaches. This was the suggestion that I received from G.Steudtel: Try to get the applications pointer of its CMainCommand instance, and use this pointer. Or send/post the command to the application as if the user has selected the dialog via the menu. Here is what I posted: I have a modeless window and a modal window, each having their own window option that when selected bring up the corresonding window. The modal window has radio buttons on it, so when a specific reaio button is selected and ok is entered, it will display the modless window. When I select the menu to bring up the modeless window it works fine, only opens one window or sets focus to it if it has not been created. When I select the modal window and check the appropriate radio it will display the modeless window regardless if it is created already. It will just continue to duplicate the modeless window. Can someone help me out so that it will set focus on the open window and not diplicate it. currently I am using this code in the OnOK method.
if (!m_pCommandOpt) { m_pCommandOpt = new CMainCommand(this); if (m_pCommandOpt->Create(IDD_MAIN_TAB_DIALOG) == TRUE) { GetDlgItem(IDOK)->EnableWindow(FALSE); m_pCommandOpt->ShowWindow(SW_SHOW); } } else m_pCommandOpt->SetActiveWindow();
THANKS in advance. -
Hi, I posted this last week, and tried to work on this over the weekend but with no success. This is something that i can't seem to figure out. Can someone tell me how to do this exactly? I never really coded before and this is causing me much headaches. This was the suggestion that I received from G.Steudtel: Try to get the applications pointer of its CMainCommand instance, and use this pointer. Or send/post the command to the application as if the user has selected the dialog via the menu. Here is what I posted: I have a modeless window and a modal window, each having their own window option that when selected bring up the corresonding window. The modal window has radio buttons on it, so when a specific reaio button is selected and ok is entered, it will display the modless window. When I select the menu to bring up the modeless window it works fine, only opens one window or sets focus to it if it has not been created. When I select the modal window and check the appropriate radio it will display the modeless window regardless if it is created already. It will just continue to duplicate the modeless window. Can someone help me out so that it will set focus on the open window and not diplicate it. currently I am using this code in the OnOK method.
if (!m_pCommandOpt) { m_pCommandOpt = new CMainCommand(this); if (m_pCommandOpt->Create(IDD_MAIN_TAB_DIALOG) == TRUE) { GetDlgItem(IDOK)->EnableWindow(FALSE); m_pCommandOpt->ShowWindow(SW_SHOW); } } else m_pCommandOpt->SetActiveWindow();
THANKS in advance.Are you using the same pointer in your dialog class as you are when you use the menu? Yes, I know it's a silly question, but I can't really think of any other reason why it wouldn't work. The other thing you could try is to send a WM_COMMAND message corresponding to your menu item, so that all the window stuff is done in the same place. That would probably simplify things. I think this was mentioned before, but it's what I would do, so I'll mention it again :) Hope this helps,
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Are you using the same pointer in your dialog class as you are when you use the menu? Yes, I know it's a silly question, but I can't really think of any other reason why it wouldn't work. The other thing you could try is to send a WM_COMMAND message corresponding to your menu item, so that all the window stuff is done in the same place. That would probably simplify things. I think this was mentioned before, but it's what I would do, so I'll mention it again :) Hope this helps,
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
I am not using the same pointer....I don't know how to get the two classes to communicate with each other. Could you please show me how to get one pointer from one class to another one? I tried to do this, but was couldn't get the code to compile correctly. How would I do the option you mention about the WM_COMMAND? I do not totally understand what you mean by this. THANKS FOR YOUR HELP.
-
I am not using the same pointer....I don't know how to get the two classes to communicate with each other. Could you please show me how to get one pointer from one class to another one? I tried to do this, but was couldn't get the code to compile correctly. How would I do the option you mention about the WM_COMMAND? I do not totally understand what you mean by this. THANKS FOR YOUR HELP.
Jay Hova wrote: How would I do the option you mention about the WM_COMMAND? I do not totally understand what you mean by this. Say your menu item was ID_SHOWDIALOG (for example). You would send a message to your frame window exactly the same as what Windows does when a menu option is chosen.
AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_SHOWDIALOG, NULL);
Hope this helps,
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Jay Hova wrote: How would I do the option you mention about the WM_COMMAND? I do not totally understand what you mean by this. Say your menu item was ID_SHOWDIALOG (for example). You would send a message to your frame window exactly the same as what Windows does when a menu option is chosen.
AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_SHOWDIALOG, NULL);
Hope this helps,
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
I'm sorry for being so slow with this, but what does this exactly do. How will this solve my problem? Also where would i put this code. The code that I posted originally is the same code I use for both menu items... Thanks again for your help and understanding
-
I'm sorry for being so slow with this, but what does this exactly do. How will this solve my problem? Also where would i put this code. The code that I posted originally is the same code I use for both menu items... Thanks again for your help and understanding
Ok. Basically, using that piece of code will simulate in software exactly what happens when the user selects a menu item. You would put this code where you handle the radio button being pressed, so that pressing the radio button behaves the same as selecting a menu item. This means that the code to actually display the dialog would only be in one place, and should solve your problem. Hope this helps,
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Hi, I posted this last week, and tried to work on this over the weekend but with no success. This is something that i can't seem to figure out. Can someone tell me how to do this exactly? I never really coded before and this is causing me much headaches. This was the suggestion that I received from G.Steudtel: Try to get the applications pointer of its CMainCommand instance, and use this pointer. Or send/post the command to the application as if the user has selected the dialog via the menu. Here is what I posted: I have a modeless window and a modal window, each having their own window option that when selected bring up the corresonding window. The modal window has radio buttons on it, so when a specific reaio button is selected and ok is entered, it will display the modless window. When I select the menu to bring up the modeless window it works fine, only opens one window or sets focus to it if it has not been created. When I select the modal window and check the appropriate radio it will display the modeless window regardless if it is created already. It will just continue to duplicate the modeless window. Can someone help me out so that it will set focus on the open window and not diplicate it. currently I am using this code in the OnOK method.
if (!m_pCommandOpt) { m_pCommandOpt = new CMainCommand(this); if (m_pCommandOpt->Create(IDD_MAIN_TAB_DIALOG) == TRUE) { GetDlgItem(IDOK)->EnableWindow(FALSE); m_pCommandOpt->ShowWindow(SW_SHOW); } } else m_pCommandOpt->SetActiveWindow();
THANKS in advance.Hi, I feel sorry for my short and as I thought understandable answer. I didnot know, that you never coded before. So let me dig a little deeper with this answer. In your main application class you should have a pointer to or an instance of class CMainCommand. This pointer or instance must be used by all calls to open the dialogs. Have a look at the headerfile of your application class to find out, wheter the CMainCommand thing is private/protected or public. In the application headerfile add a member function:
CMainCommand* GetCommandPointer(void);
Assuming it is a pointer (lets call it pMainCommand) write in the applications cpp-fileCMainCommand* CWinApp::GetCommandPointer(void) { return pMainCommand;}
Of course you have to substitute CWinApp and pMainCommand with the names of the actual class name and variable name. If you do not use a pointer, but an instance of the class replace pMainCommand with &mainCommand; In your OnOk handler writem_pCommantOpt = DYNAMIC_DOWNCAST(CWinApp,AfxGetApp())->GetCommandPointer();
Here too you have to substitute the CWinApp with the actual name of your application class. Also you have to include the applications header file into your cpp file. (But this should be done already by class wizard) This line above does: It retrieves a pointer to the application class instance, casts it to your application class and after the casting calls GetCommandPointer. Then delete the line where you create an new instance of CMainCommand, bailing out, when the pointer is inavlid and tell the user that someting went wrong.m_pCommantOpt = DYNAMIC_DOWNCAST(CWinApp,AfxGetApp())->GetCommandPointer(); if( m_pCommandOpt != NULL ) { m_pCommandOpt = new CMainCommand(this); if( m_pCommandOpt->Create(IDD_MAIN_TAB_DIALOG) == TRUE ) { GetDlgItem(IDOK)->EnableWindow(FALSE); m_pCommandOpt->ShowWindow(SW_SHOW); } else { m_pCommandOpt->SetActiveWindow(); } } else AfxMessagebox("Something went wrong");
Regards G.Steudtel -
Ok. Basically, using that piece of code will simulate in software exactly what happens when the user selects a menu item. You would put this code where you handle the radio button being pressed, so that pressing the radio button behaves the same as selecting a menu item. This means that the code to actually display the dialog would only be in one place, and should solve your problem. Hope this helps,
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Many thanks Ryan. You just solved my problem that I have spent way too many hours on. Worked like a charm.
You're welcome :)
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Hi, I posted this last week, and tried to work on this over the weekend but with no success. This is something that i can't seem to figure out. Can someone tell me how to do this exactly? I never really coded before and this is causing me much headaches. This was the suggestion that I received from G.Steudtel: Try to get the applications pointer of its CMainCommand instance, and use this pointer. Or send/post the command to the application as if the user has selected the dialog via the menu. Here is what I posted: I have a modeless window and a modal window, each having their own window option that when selected bring up the corresonding window. The modal window has radio buttons on it, so when a specific reaio button is selected and ok is entered, it will display the modless window. When I select the menu to bring up the modeless window it works fine, only opens one window or sets focus to it if it has not been created. When I select the modal window and check the appropriate radio it will display the modeless window regardless if it is created already. It will just continue to duplicate the modeless window. Can someone help me out so that it will set focus on the open window and not diplicate it. currently I am using this code in the OnOK method.
if (!m_pCommandOpt) { m_pCommandOpt = new CMainCommand(this); if (m_pCommandOpt->Create(IDD_MAIN_TAB_DIALOG) == TRUE) { GetDlgItem(IDOK)->EnableWindow(FALSE); m_pCommandOpt->ShowWindow(SW_SHOW); } } else m_pCommandOpt->SetActiveWindow();
THANKS in advance.