//--------------------------------------------------------------------------- inline void __fastcall DoFormWindowProc(TCustomForm * Form, TWndMethod WndProc, TMessage & Message) { if ((Message.Msg == WM_SYSCOMMAND) && (Message.WParam == SC_CONTEXTHELP)) { InvokeHelp(Form->ActiveControl); Message.Result = 1; } else if (Message.Msg == CM_SHOWINGCHANGED) { TForm * AForm = dynamic_cast<TForm *>(Form); assert(AForm != NULL); if ((Application->MainForm == Form) || // this particularly happens if error occurs while main // window is being shown (e.g. non existent local directory when opening // explorer) ((Application->MainForm != NULL) && !Application->MainForm->Visible)) { if (Form->Showing) { SendMessage(Form->Handle, WM_SETICON, ICON_BIG, reinterpret_cast<long>(Application->Icon->Handle)); } if (!Form->Showing) { // when closing main form, remember its monitor, // so that the next form is shown on the same one LastMonitor = Form->Monitor; } else if ((LastMonitor != NULL) && (LastMonitor != Form->Monitor) && Form->Showing) { // would actually always be poScreenCenter, see _SafeFormCreate if ((AForm->Position == poMainFormCenter) || (AForm->Position == poOwnerFormCenter) || (AForm->Position == poScreenCenter)) { // this would typically be an authentication dialog, // but it may as well be an message box // taken from TCustomForm::SetWindowToMonitor AForm->SetBounds(LastMonitor->Left + ((LastMonitor->Width - AForm->Width) / 2), LastMonitor->Top + ((LastMonitor->Height - AForm->Height) / 2), AForm->Width, AForm->Height); AForm->Position = poDesigned; } else if ((AForm->Position != poDesigned) && (AForm->Position != poDefaultPosOnly)) { // we do not expect any other positioning assert(false); } } else { TForm * AForm = dynamic_cast<TForm *>(Form); assert(AForm != NULL); // otherwise it would not get centered if ((AForm->Position == poMainFormCenter) || (AForm->Position == poOwnerFormCenter)) { AForm->Position = poScreenCenter; } } } bool WasFormCenter = (AForm->Position == poMainFormCenter) || (AForm->Position == poOwnerFormCenter); WndProc(Message); // Make sure dialogs are shown on-screen even if center of the main window // is off-screen. Occurs e.g. if you move the main window so that // only window title is visible above taksbar. if (Form->Showing && WasFormCenter && (AForm->Position == poDesigned)) { TRect Rect; // Reading Form.Left/Form.Top instead here does not work, likely due to some // bug, when querying TProgressForm opened from TEditorForm (reloading remote file) GetWindowRect(Form->Handle, &Rect); int Left = Rect.Left; int Top = Rect.Top; TRect WorkArea = AForm->Monitor->WorkareaRect; if (Left + Rect.Width() > WorkArea.Right) { Left = WorkArea.Right - Rect.Width(); } if (Left < WorkArea.Left) { Left = WorkArea.Left; } if (Top + Rect.Height() > WorkArea.Bottom) { Top = WorkArea.Bottom - Rect.Height(); } if (Top < WorkArea.Top) { Top = WorkArea.Top; } if ((Left != Rect.Left) || (Top != Rect.Top)) { SetWindowPos(Form->Handle, 0, Left, Top, Rect.Width(), Rect.Height(), SWP_NOZORDER + SWP_NOACTIVATE); } } } else { WndProc(Message); } }
//--------------------------------------------------------------------- void __fastcall FormHelp(TForm * Form) { InvokeHelp(Form->ActiveControl != NULL ? Form->ActiveControl : Form); }