This site hosted by Free.ProHosting.com
Google

How can I change the position of OpenDialog?

Applies To: C++Builder 1 or higher
Category: Knowledge Base

I tried using SetWindowPos and MoveWindow to change the position of my OpenDialog but these API functions don't seem to work. How can I center my OpenDialog?
 
 1.
  Start a new application.
 
 2.
  Add an OpenDialog. Edit its OnShow event:
 
void __fastcall TForm1::OpenDialog1Show(TObject *Sender)
{
    TRect rect;
    GetWindowRect(GetParent(dynamic_cast<TOpenDialog*>
        (Sender)->Handle), &rect);
    const int DialogWidth  = rect.right - rect.left;
    const int DialogHeight = rect.bottom - rect.top;
 
    MoveWindow(GetParent(dynamic_cast<TOpenDialog*>
        (Sender)->Handle),
        (Width-DialogWidth)/2 + Left,
        (Height-DialogHeight)/2 + Top,
        DialogWidth, DialogHeight, true);
    Abort();
}
 
 3.
  Add a Button. Edit its OnClick event:
 
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    OpenDialog1->Execute();
}
 
The Abort procedure cancels the WM_NOTIFY message that Windows sends to its common dialogs. This allows you to change the position of OpenDialog.

C++Builder Developer's Network
Copyright © Yoto Yotov