Dialog position .....

In formView class,i am using a modeless dialog box in RightClick event.Now on clicking different locations of screen,a dialog appears having some information.Now the problem is that i have divided the screen into 4 parts.when user will click on top left side,a dialog should Move to the bottom right side and should remain there for other events of click untill the user closes that dialog.Similarly after closing,again right click to top right position,then dialog should appear in bottom left side and remains there for other events untill it closes.How it can be done.what i do is:
CView::RightButton()
{
buffer=information to be shown in dialogbox;
pDlg->ShowWindow(SW_SHOW);
if((point.x>0 && point.x<=382 ) && (point.y>3 && point.y<=300) )
            
           {
 pDlg->MoveWindow(700,400,250,95,true);
                        }
   if((point.x>=383 && point.x<=790) && (point.y>3 && point.y<=322))
   {                //if (m_bMove)
  pDlg->MoveWindow(10,400,250,95,true);
                   }

            }
Now by doing this,on first click to the Top left side,a dialog appear on the bottom right side but if i click on top right side,the dialog moves towards its new position.Old position doesnot remains there.what should i do.?
cancermcs            

cancermcsAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
itsmeandnobodyelseConnect With a Mentor Commented:
>> And then try passing the variable via REFERENCE

Maybe it's easier to have appropriate member functions like that:

// in mydialog.h:

class CMyDialog : public CDialog
{
private:
      BOOL m_bCanMove;
      ....

public:
      BOOL CanMoved()  {  return m_bCanMoved; }
      void   SetCanMoved( BOOL bCanMoved)  { m_bCanMoved = bCanMoved; }
      ....
};

// in mydialog.cpp

     CMyDialog::CMyDialog(CWnd* pParent)
       : m_bCanMoved(FALSE)
    {
          ....
    }

     BOOL CMyDialog::OnInitDialog()
    {
          m_bCanMoved = TRUE;
          ....
    }

Then the sequence from above turns to

     void CMyView::RightClick()
    {
       // check if dialog can be moved
       if (!pDlg->CanMoved())
            return;

        // disable moving
        pDlg->SetCanMoved(FALSE);

        if((point.x>0 && point.x<=382 ) && (point.y>3 && point.y<=300) )
        {
             pDlg->MoveWindow(700,400,250,95,false);
        }
        else if((point.x>=383 && point.x<=790) && (point.y>3 && point.y<=322))
        {                //if (m_bMove)
             pDlg->MoveWindow(10,400,250,95,false);
        }
        pDlg->ShowWindow(SW_SHOW);

When the dialog get closed - i assume there is an OK button ?? - you have to enable moving.

     void CMyDialog::OnOK()
     {
            ...
            m_bCanMoved = TRUE;
     }

Regards, Alex



0
 
itsmeandnobodyelseCommented:
Assuming that you hide the dialog on close you could ask if the dialog is hidden:

void CMyView::RightButton()
{
      WINDOWPLACEMENT wp; wp.length = sizeof(wp);
      if (pDlg->GetWindowPlacement(&wp))
      {
            if (wp.showCmd != SW_HIDE)
                return;
      }
      ....
}

Or if you disabled the diaog on close it would simplify to

void CMyView::RightButton()
{
      if (pDlg->IsWindowEnabled())
               return;
      ....
}

Regards, Alex



0
 
mrwad99Commented:
Why don't you set some BOOL variable that indicates when the dialogue can be moved by clicking events ?  You could pass this to the dialog by reference then set it accordingly when the dialog is closed.

eg

BOOL m_bCanMove;  // Pass this to the dialogue by reference on construction

Then set this to FALSE in the dialogues' destructor

In the right click handler simply only move the dialog if m_bCanMove is TRUE.

HTH
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
cancermcsAuthor Commented:
u might not understand my problem.when i will click on the specified position of screen,the dialog will appear in a given position.The dialog should maintain the same position when i want to click on some other position of screen.Information in the dialog is updating according to the click area.But doing this ,dialog moves according to the MoveWindow position.It shouldn't change untill i closes the dialog and recall the dialog again.when i will recall the dialog,then the dialog should move to a new position and then remains there for other click events untill it is closed.

 MRWAD99,i tried this but its getting no effect.i made the m_bCanMove =False in Cdlg::OnDestroyWindow() event.
cancermcs
0
 
itsmeandnobodyelseCommented:
>> u might not understand my problem

The solution i posted above returns from CMyView::RightClick _BEFORE_ the calls to MoveWindow if the dialog window isn't hidden or if it is enabled. So, your dialog window should not move if it is open.

Regards, Alex


0
 
mrwad99Commented:
>> MRWAD99,i tried this but its getting no effect.i made the m_bCanMove =False in

Are you passing it to the dialogue via reference or pointer ?  If so then this should work, if *I* understand the problem
0
 
cancermcsAuthor Commented:
hi itsmeansnobodyelse
i did the try,but dialog then remains stick on the position (0,0) and its not changing its position according to my given points.the dialog move to (0,0) always i close it and restart it.But i want to Move the dialog according to my position firstly..and then it should remain on that position.When i close that dialog and again click on opposite side,then new position should be attain,and then it should remain there.

MRWAD99
i am not passing it as a pointer.i just take a BOOL variable in dialog class and make it true in constructor and false in Destroywindow().and true again in CView::RClick.

Plz solve my problem.its very urgent.
thanks
cancermcs
0
 
itsmeandnobodyelseCommented:
>> i did the try,but dialog then remains stick on the position (0,0)

That is because initially the dialog isn't hidden or disabled. So, the MoveWindow calls never get called.

Find out where the dialog (pDlg) gets created and add a

    pDlg->EnableWindow(FALSE);

after that. Then, when right-clicking the condition

   if (pDlg->IsWindowEnabled())
        return;

is false, the Right-Click function gets performed. Now the dialog window should be enabled, moved and shown

        pDlg->EnableWindow(TRUE);

        if((point.x>0 && point.x<=382 ) && (point.y>3 && point.y<=300) )
        {
             pDlg->MoveWindow(700,400,250,95,false);
        }
        else if((point.x>=383 && point.x<=790) && (point.y>3 && point.y<=322))
        {                //if (m_bMove)
             pDlg->MoveWindow(10,400,250,95,false);
        }
        pDlg->ShowWindow(SW_SHOW);

When the dialog get closed - i assume there is an OK button ?? - you have to disable the dialog.

     void CMyDialog::OnOK()
     {
            ...
            EnableWindow(FALSE);
     }

Instead of enabling/disabling the dialog window you may do the same by setting a bool member of the dialog to 'false' or 'true' depending on the dialog is closed or opened.

Regards, Alex



                 


0
 
itsmeandnobodyelseCommented:
>> Plz solve my problem.its very urgent

An urgent problem deserves more than 20 points!

0
 
mrwad99Commented:
>> An urgent problem deserves more than 20 points!

Well I suppose so, but until one reaches expert status it is expensive to get points I dare say.

Try what Alex has said.  And then try passing the variable via REFERENCE.  If you are not doing this then it will of course not work !

CMyDialog::CMyDialog(BOOL& bCanMove // and other relevant dialogue construction stuff)
0
 
mrwad99Commented:
>> Maybe it's easier to have appropriate member functions like that:

Yeah you could do, but I was being conservative with code.  Also it would be better I think to set m_bCanMoved to TRUE in the destructor; since the dialogue can be closed by OK or CANCEL messages.

Anyway, that is enough methinks for a 20 pointer :)
0
 
itsmeandnobodyelseCommented:
>> better I think to set m_bCanMoved to TRUE in the destructor

Only if pDlg gets 'deleted' after close. As the user seems to be able to right-clicking on the view while the dialog is active, the dialog must be modeless. I assume it get created once - maybe in CMyView::OnInitialUpdate - then was hidden by ShowWindow(SW_HIDE) and finally activated by right-clicking in the view. But, maybe i am wrong...

>> since the dialogue can be closed by OK or CANCEL messages

Yes, if there is an CMyDialog::OnCancel() , the m_bCanMoved member must be set to TRUE as well.

If there is a

     pDlg->ShowWindow(SW_HIDE);

somewhere, it could be followed by a

    pDlg->SetCanMoved(TRUE);

Or in the destructor - as you had said - if the dialog gets destroyed after close.

Regards, Alex

Very much comments for my part of 10 points ... ;-)

0
All Courses

From novice to tech pro — start learning today.