Link to home
Start Free TrialLog in
Avatar of gilbert_chang
gilbert_chang

asked on

Changing an initial position of a dialog

I want to create a dialog that will start at a known position (not in the middle of the screen as the default).
I tried:
BOOL CMyDlg::PreCreateWindow(CREATESTRUCT& cs)
{      
    cs.cy = Const;
    cs.cx = Const;
    cs.y = Const;    
    cs.x = Const;      

    return CDialog::PreCreateWindow(cs);
}
But it doesn't work.
Any ideas?
Thanks.
ASKER CERTIFIED SOLUTION
Avatar of nil_dib
nil_dib

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 gilbert_chang
gilbert_chang

ASKER

I have. Doesn't work.
Oppps ....
this work fine in my app ....
BOOL CMyDlg::OnInitDialog()
{
      CDialog::OnInitDialog();

      SetWindowPos( &wndTopMost, 5, 5, 80, 80, SWP_SHOWWINDOW);
      
      return TRUE;  // return TRUE  unless you set the focus to a control
}

did you delete the PreCreateWindow method?
I did delete the PreCreateWindow method.
All this line does is change the dimensions of the window, but not it's position.
mail me your code
jds1@ipa.fhg.de
mmhhh....
the code works fine
I set the lParam to a value, and the dialog is displayed in the
top left corner.

LONG lParam = 100;

CMyDlg dia;
xPos = LOWORD(lParam);  // horizontal position of cursor
yPos = HIWORD(lParam);  // vertical position of cursor
...

Could it be that the lParam is exact the value of the mid screen coorinates?
Try to set xPos and yPos to a value.
CMyDlg dia;
xPos = 100;  // horizontal position of cursor
yPos = 100;  // vertical position of cursor
and look for the result ....

Another idea: look for the return value of SetWindowPos.
Should be 1.
It shouldn't matter much, since when I tried your:
SetWindowPos( &wndTopMost, 5, 5, 80, 80, SWP_SHOWWINDOW);
It didn't work either, with nothing to do with xPos,yPos.
I debugged, and got xPos=550, yPos=y , so it should have changed something anyway.
Is it possible that I am creating some kind of a dialog that resets its position after OnInitDialog?
Thanks.
No, I've tested your code and it works (with lParam = 100).
>>and got xPos=550, yPos=y
What is y (What is the value of lParam)?
Which compiler?
Do you have other windows displayed at the same time?
 

y=0, VC++5,I have another window (The main window) displayed at the same time.
The window we are talking about should be one that pops when the mouse moves over something.
thanks