Link to home
Start Free TrialLog in
Avatar of Shilpa
Shilpa

asked on

Keeping the modeless dialog active in an MDI application

Hi,
  I have created an MDI application(VC++ 6.0). It contains a small dialog which is opened when the application opens. This dialog is a modeless dialog containing a few options (settings) which can be incorporated in the application. It is something like a control bar or a toolbar in a typical MFC application. The problem here is tht when I click outside the modeless dialog to work on the document, the dialog title bar is deactivated(ie: the focus is removed). I want the modeless dialog to remain active along with the active document in my MDI application. Is it possible to hav 2 windows active at the same time? If so then can anybody please provide me with the solution?
Waiting for a reply eagerly
Thanx
Shilpa
Avatar of MadYugoslav
MadYugoslav
Flag of Serbia image

No. This is not possible to have two active window at the same time.
But, You can have blue title bar (or other).
Avatar of mohd_shafi
mohd_shafi

I agree that in windows there cannot be more than one window active at any given time.
 But one crazy kind of solution is, you have to go to the display properties and in the appearance tab, change the Active and Inactive Title bar color to whatever color you please.
Avatar of Shilpa

ASKER

 But if u say tht it is not possible to hav two windows active at the same time, then how do they hav it for control bars in applications which is active with the active document opened, coz Control bar is also a window. There must be some way to make it active though.
Can anybody out there plz suggest some solution to it??
Thanx
Shilpa
Yes Shilpa,
 One possible solution to your problem is to use CDialogBar. I have given it in steps.
I have tried this out in an MDI application
1. Create your Dialog Resource using Insert Dialog, So you vil get the dialog id say IDD_SHILPADIALOG
2. In the Dialog Properties, change the style to "child" from "popup". Change the Border to "None"
3. See that the "visible" check box is not selected in "more styles" page
4. Declare a member variable "m_Mydlg" of type CDialogBar in your Mainframe.h file
5. Now in your CMainFrame class at the end of the "OnCreate" function add the following code
   (take enough care that you do not write it after return statement)
   
     if(!m_Mydlg.Create(this, IDD_SHILPADIALOG, CBRS_LEFT|CBRS_TOOLTIPS|CBRS_FLYBY, IDD_SHILPADIALOG))
     {
       TRACE0("You have missed something shilpa\n");  
          // approach me if this happens
          return -1;
     }
     
     m_Mydlg.EnableDocking(NULL);     // comment this if you want docking

     // uncomment next line if you want docking
     //m_Mydlg.EnableDocking(CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM);

     // 2nd parameter should be the point where dialog is displayed
     FloatControlBar(&m_Mydlg, CPoint(10,10));
     
     return 0;
     }     // end of CMainFrame::OnCreate(...)
6. After this, you can click accept "comment as answer", my e-mail id is mohd_shafi@hotmail.com

7. That's it

SHAFI
Avatar of Shilpa

ASKER

Hi Shafi,
   Initially I started with a dialog bar, but had to drop the idea since dialog bar was not handling some command handlers for some controls, and it was not invalidating . It was then tht I thought of using the modeless dialog box. I had rightly tried out the same thing tht u hav suggested before. But now I wud like to continue with the modeless dialog box. If u can still suggest somethin better I wud be grateful.
Thanx once again
Shilpa
Hi again,
 I have tried using different controls in the dialog bar and i was successfull too. I even implemented command handlers for some of the controls.
 can u let me know what were the controls which you could not handle properly. I still think dialog bar is the best option
SHAFI
Avatar of Shilpa

ASKER

Hi Shafi,
   I tried using the button control on the dialog bar. Presently wht I hav implemented on the dialog bar is tht, when the user clicks on the button control, he gets a popup generated close to the button, showing 3 different options. I managed to get all this working, but when it came to handling the events for the menu options of the popup menu, I was totally lost. I donno how to disable and enable the menu options through the dialog bar. I m sooo very confused. Is there a solution to this problem shafi??
If yes then please do lemme know abt the same.
Waiting eagerly for ur reply.
Thanx once again
Shilpa
Hy Shilpa,
  well shilpa as far as i have understood, you have created the dialog bar and have handled the button control. I hope u have

handled the button in the CMainFrame class only.
For this you might have dun somethin like this

In Message Map
 ON_BN_CLICKED(ON_BN_CLICKED(IDOK, OnOK)

Then in OnOK
 void CMainFrame::OnOK()
{
     ::AfxMessageBox("Is it OK ");
}

now uar problem iz to get a popup menu handled properly?

am i korect ?

IF( iam korect )
 then let me no, wat code u have written to popup the menu, and where is the exact problem in the code.
 i think i have the solution
ELSE
 plz help me out. let me know how and where u have implemented OnOK, OK
ENDIF

 i think v r deviating from the original problem now, but Kool. i hav also startd typin broken english now, courtesy ..

Awatin reply
SHAFI
Avatar of Shilpa

ASKER

Hi Shafi,
   Thanx first for ur efforts....
I m sorry v r actually deviating from our topic, but I seriously need help on it since I hav started with a dialog bar and given up on modeless dialog(from ur suggestion.
  Initially when I created a button on the dialog bar, I had a problem since the button was always shown disabled on opening of the application. Then I came across this article on Codeguru, which said tht u hav to call this below function in the same class ie: of dialog bar
OnUpdateButton(CCmdUI *pCmdUI)
{
  pCmdUI->Enable();
}
And .....it worked..
Then I incorporated the code to popup a menu when the user clicks on the same button. For tht I dowloaded a CCoolBtn class frm Codeguru itself, which allows u to create a dynamic menu bar. (IF u wud like to go thru the class lemme know ur email id and I will send it across). The code worked and I get the dynamically created menu on clicking the button, at the same time I can even handle the events on clicking on the menu items within the menu. But NOW the only problem is when I click on one menu option, I need to disable the other menu option. And after trying all possible ways I hav miserably failed in my attempts. If u can suggest a solution plz plz plz lemme know at the earliest. Waiting for ur response
Thanx once again
Shilpa
Hi shilpa,
As i had writtn u in the previos mail, it is not necessary to derive a class from CDialogBar, I had also given the steps as to how the CDialogBar object has to be created in the CMainFrame class in OnCreate() function remember.
 And after that i had given steps to handle the CDialogBar OK button(or for that reason handling any other button is quite simple). For that reson, all that codeguru stuff is not required to enable the buttons on the dialog box
 You have to just create the dialog template resource, add whatever buttons you like into that using resource editor. And while creating the CDialogBar using CDialogBar::Create(...) function just specify the dialog resource ID. Add the macros to the MESSAGE_MAP and function prototypes and defintions ALL IN YOUR CMainFrame class only in order to handle buttons and menus.
 I have created a very simple application(MDI, VC++ 6.0 app) with dialog bar with the button handlers, i can send it  across to u by email(ur email id plz). My email id is "mohd_shafi@hotmail.com"(Bangalore)(INDIA). Meanwhile u can send your work on this e-mail id.

Regards
SHAFI

ASKER CERTIFIED SOLUTION
Avatar of mohd_shafi
mohd_shafi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Shilpa

ASKER

Thanx a lot Shafi,
   u made my life simple.

Till then Keep the Spirit

Shilpa