Solved

Dialog position .....

Posted on 2004-08-16
12
269 Views
Last Modified: 2012-05-05
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            

0
Comment
Question by:cancermcs
  • 6
  • 4
  • 2
12 Comments
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11809202
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
 
LVL 19

Expert Comment

by:mrwad99
ID: 11809207
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
 

Author Comment

by:cancermcs
ID: 11817746
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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11818001
>> 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
 
LVL 19

Expert Comment

by:mrwad99
ID: 11818804
>> 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
 

Author Comment

by:cancermcs
ID: 11827838
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11827924
>> 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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11827936
>> Plz solve my problem.its very urgent

An urgent problem deserves more than 20 points!

0
 
LVL 19

Expert Comment

by:mrwad99
ID: 11828171
>> 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
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 20 total points
ID: 11828364
>> 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
 
LVL 19

Expert Comment

by:mrwad99
ID: 11829750
>> 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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11830363
>> 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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now