CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jan 2016
    Posts
    61

    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;
    Last edited by 2kaud; February 2nd, 2017 at 06:38 AM. Reason: Added code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured