-
Dual monitor issue
I have a Windows application in Delphi 5.
I have two monitors. When my application runs, the parent is displayed on the first monitor. When I move the parent window to the second monitor and click a button, this child window stays on the first monitor. Is there a way to make the child window stay with the parent window no matter where the parent window is located? I searched related to this but solution is in C# not in Delphi, I am very new in Delphi. Child forms are creating at run time.
My Code is:
Code:
function BeforeCreateForm(Session:ISmSession;var IsDLL: Boolean):HWND;
var
SmGUIServices: ISmGUIServices;
MainWindowHandle:HWND;
begin
MainWindowHandle:=0;
IsDLL := false;
if (Application.Handle = 0) and (Session <> nil) then
begin
IsDLL := true;
SmGUIServices := (Session.Services.Item[TDM_SmarTeamServices[srvSmGUIService]] as ISmGUIServices);
if SmGUIServices <> nil then
{$IFNDEF BUILTPACKAGE}
MainWindowHandle:=ForceIntegerToHwnd(SmGUIServices.MainWindowHandle);
{$ENDIF}
end;
result:=MainWindowHandle;
end { of BeforeCreateForm } ;
procedure TSmForm.AfterCreateForm(Session:ISmSession; SmHelpContext:TDM_Int32; IsDLL: boolean);
begin
if SmSession<>Session then
SmSession:= Session;
if SmHelpContext > 0 then
HelpContext:=SmHelpContext;
if (IsDLL) then
begin
if (Icon.Empty) and (ParentHWND <> 0) then
SendMessage(Handle, WM_SETICON, 1, SendMessage(ParentHWND, WM_GETICON, 1, 0));
end;
end { of TSmForm.AfterCreateForm } ;
constructor TSmForm.Create(AOwner: TComponent;Session:ISmSession;SmHelpContext:TDM_Int32);
var
IsDLL: Boolean;
begin
ParentHWND:=BeforeCreateForm(Session, IsDLL);
HelpContext := 0;
SmSession:= Session;
inherited Create(AOwner);
AfterCreateForm(Session,SmHelpContext, IsDLL);
end;
procedure TSmForm.CreateParams(var Params: TCreateParams);
var
SmGuiServices: ISmGuiServices;
MDIChild : TIMDIChildForm;
MultiTabType :TDM_Int16;
I:Integer;
begin
inherited CreateParams(Params);
if ParentHWND <> 0 then
begin
Params.WndParent:=ParentHWND;
SmGUIServices := (SmSession.Services.Item[TDM_SmarTeamServices[srvSmGUIService]] as ISmGUIServices);
for I := SmGUIServices.SmViewWindows.Count - 1 downto 0 do
begin
if(SmGUIServices.SmViewWindows.item[I].SmView<>nil) then
if(SmGUIServices.SmViewWindows.item[I].SmView.ViewType <> vwtBomView) then
begin
MDIChild := TIMDIChildForm((SmGUIServices.SmViewWindows.item[I] as ISmRawViewWindow).SmViewWindowHandle);
MultiTabType:=GetMultiTabType( MDIChild.tabSmView, MDIChild.tabSmView.ActivePage.PageIndex);
if UpperCase(SmSession.ApplicationName) = 'MYAPP' then
(MDIChild.MDIViewer.ViewerType = 10))) then
begin
// Params.ExStyle := Params.ExStyle or WS_EX_TOPMOST;
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent := GetDesktopWindow;
exit;
end
else
begin
if (MultiTabType = MT_Viewer) then
begin
Params.ExStyle := Params.ExStyle or WS_EX_TOPMOST;
exit;
end;
end;
end;
end;
end;
end;
-
Re: Dual monitor issue
When posting code, please use code tags so that the code is readable. Go Advanced, select the formatted code and click '#'.
I'm not sure how many replies you're going to have asking a Delphi question in a c++ forum? :eek:
-
Re: Dual monitor issue
I don't found any section for delphi. Is there in Codeguru? if yes then please let me know i will post over there.
-
Re: Dual monitor issue
Make sure the child window gets created with the WS_CHILD window style and set its parent hwnd to the parent window. If both of these are done, the child window will move with the parent. If I am reading your code correctly, you are incorrectly setting the parent window of the child to the desktop.