Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I set position of OpenDialog object?

Status
Not open for further replies.

HuntsvilleRob

Programmer
Nov 3, 2010
26
0
0
US
Hello. I have posted this question before but I still don't have an answer. Your help would be MOST appreciated!
What I want to do is really very simple. I wish to launch an OpenDialog from my app and I wish to set the position to be in the center of the parent window. However, there is no Top or Left property for the OpenDialog. There is not even a Position property. The Windows OS is deciding where the OpenDialog will be positioned and I don't know how to control this. How do I set the Left, Top, and/or Position of the OpenDialog? Thanks so much.

-Rob
 
Hi, try this :)

Code:
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	Timer1->Enabled = true;
	OpenDialog1->Execute();
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
	Timer1->Interval = 125;
	UnicodeString TMPApriDialog_Title = L"ApriDialog_Univocal_Title_UDY78d093204du38287429dhqhdqi";
	static UnicodeString ORIGApriDialog_Title = L"";
	if( ORIGApriDialog_Title == L"" )
		ORIGApriDialog_Title = OpenDialog1->Title;
	OpenDialog1->Title = TMPApriDialog_Title;
	HWND hwnd = FindWindow(NULL, TMPApriDialog_Title.c_str() );
	if( hwnd )
	{
		WINDOWINFO info;
		info.cbSize = sizeof(WINDOWINFO);
		::GetWindowInfo( hwnd, &info );
		int x = this->Left + ( (this->Width  - (info.rcWindow.right  - info.rcWindow.left) ) /2 );
		int y = this->Top  + ( (this->Height - (info.rcWindow.bottom - info.rcWindow.top ) ) /2 );
		::SetWindowPos( hwnd          // handle of window
					  , HWND_TOP      // placement-order handle
					  , x             // horizontal position
					  , y             // vertical position
					  , 0             // width
					  , 0             // height
					  , SWP_NOSIZE ); // window-positioning flags
		OpenDialog1->Title = ORIGApriDialog_Title;
		ORIGApriDialog_Title = L"";
		Timer1->Enabled = false;
	}
}
//---------------------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top