|
-
February 2nd, 2017, 06:35 AM
#1
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
-
February 2nd, 2017, 06:42 AM
#2
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?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 2nd, 2017, 07:00 AM
#3
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.
-
February 9th, 2017, 09:27 AM
#4
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|