Skip to content

Commit

Permalink
remote topmost propertity
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryBikini committed Feb 1, 2018
1 parent 493029c commit 3318167
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 82 deletions.
Binary file not shown.
83 changes: 9 additions & 74 deletions WndTop.Setup/InnoSetup/WndTop.iss
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
; Script generated by the Inno Script Studio Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#include <idp.iss>


#define MyAppName "Windows Top"
#define MyAppName "WndTop"
#define MyAppVersion "0.1"
#define MyAppPublisher "GaryBikini"
#define MyAppURL "https://github.com/GaryBikini/WndTop"
#define MyAppExeName "WndTop.exe"
#define MyAppExeName "MyProg.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{1F221905-BDEE-4969-8780-6D7A6BEE5B1F}
AppId={{51ADD678-4C2D-4FD9-A765-0FBC6B043F07}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
Expand All @@ -24,89 +22,26 @@ AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
OutputBaseFilename={#MyAppName}-Installer-{#MyAppVersion}
OutputBaseFilename=setup
Compression=lzma
SetupIconFile=logo.ico
SolidCompression=yes

SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "chinese"; MessagesFile: "compiler:Languages\Chinese.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Files]
Source: "WndTop\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs

Source: "C:\Program Files (x86)\Inno Setup 5\Examples\MyProg.exe"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files


[Code]
function Framework45IsNotInstalled(): Boolean;
var
bSuccess: Boolean;
regVersion: Cardinal;
begin
Result := True;
bSuccess := RegQueryDWordValue(HKLM, 'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release', regVersion);
if (True = bSuccess) and (regVersion >= 378389) then begin
Result := False;
end;
end;
procedure InitializeWizard;
begin
if Framework45IsNotInstalled() then
begin
idpAddFile('http://go.microsoft.com/fwlink/?LinkId=397707', ExpandConstant('{tmp}\NetFrameworkInstaller.exe'));
idpDownloadAfter(wpReady);
end;
end;
procedure InstallFramework;
var
StatusText: string;
ResultCode: Integer;
begin
StatusText := WizardForm.StatusLabel.Caption;
WizardForm.StatusLabel.Caption := 'Installing .NET Framework 4.5.2. This might take a few minutes...';
WizardForm.ProgressGauge.Style := npbstMarquee;
try
if not Exec(ExpandConstant('{tmp}\NetFrameworkInstaller.exe'), '/passive /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
MsgBox('.NET installation failed with code: ' + IntToStr(ResultCode) + '.', mbError, MB_OK);
end;
finally
WizardForm.StatusLabel.Caption := StatusText;
WizardForm.ProgressGauge.Style := npbstNormal;
DeleteFile(ExpandConstant('{tmp}\NetFrameworkInstaller.exe'));
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
case CurStep of
ssPostInstall:
begin
if Framework45IsNotInstalled() then
begin
InstallFramework();
end;
end;
end;
end;
[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}";
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"

Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon

Expand Down
Binary file not shown.
Binary file not shown.
Binary file removed WndTop.Setup/InnoSetup/WndTop/WndTop.exe
Binary file not shown.
Binary file not shown.
Binary file removed WndTop.Setup/InnoSetup/logo.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions WndTop/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"

Topmost="True"
Icon="logo.ico" ResizeMode="CanMinimize"
Topmost="False"
Icon="logo.ico" ResizeMode="CanMinimize" Loaded="Window_Loaded"
>
<Grid>
<ToggleButton x:Name="btnTop"
Expand Down
4 changes: 4 additions & 0 deletions WndTop/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ private void btnRelease_Checked(object sender, RoutedEventArgs e)
Utils.fun(this);
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
//OnTop.Run(200);
}
}
}
53 changes: 47 additions & 6 deletions WndTop/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;

namespace WndTop
Expand All @@ -27,8 +28,15 @@ class Utils



public static void SetOnTop(IntPtr winHandle)
{
SetWindowPos(winHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
}


public static void CancelOnTop(IntPtr winHandle)
{
SetWindowPos(winHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}


private const int WH_MOUSE_LL = 14;
Expand Down Expand Up @@ -125,13 +133,18 @@ private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)

IntPtr winHandle = WindowFromPoint(cusorPoint);

Debug.WriteLine("handle: " + winHandle.ToString("X"));

// Get the final parent handle of the window
while (true)
{
IntPtr temp = GetParent(winHandle);
Debug.WriteLine("parent handle: " + temp.ToString("X"));
if (temp.Equals(IntPtr.Zero))
break;
winHandle = temp;
Debug.WriteLine("handle: " + winHandle.ToString("X"));

}
//IntPtr winHandle = GetActiveWindow();

Expand All @@ -147,14 +160,12 @@ private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)

IntPtr hwndCur = curProcess.MainWindowHandle;

//Debug.WriteLine("\n周齐飞cur: {0} click: {1}", hwndCur.ToString("X"), winHandle.ToString("X"));


if (mainWindow.btnTop.IsChecked == true)
{
if (hwndCur != winHandle)
{
SetWindowPos(winHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
Debug.WriteLine("cur handle: " + winHandle.ToString("X"));
SetOnTop(winHandle);
}
mainWindow.btnTop.IsChecked = false;
}
Expand All @@ -163,7 +174,7 @@ private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (hwndCur != winHandle)
{
SetWindowPos(winHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
CancelOnTop(winHandle);
}
mainWindow.btnRelease.IsChecked = false;
}
Expand Down Expand Up @@ -207,4 +218,34 @@ public static void fun(MainWindow wnd)
}
}
}

class OnTop
{
private static Timer timer;
private static IntPtr intPtr;

public static void Run(int interval)
{
timer = new Timer(interval);

using (Process curProcess = Process.GetCurrentProcess())
{
using (ProcessModule curModule = curProcess.MainModule)
{
//IntPtr hwndCur = GetModuleHandle(curModule.ModuleName);

intPtr = curProcess.MainWindowHandle;

timer.Elapsed += timer_Elapsed;
timer.Start();
}
}

}

private static void timer_Elapsed(object sender, ElapsedEventArgs e)
{
Utils.SetOnTop(intPtr);
}
}
}

0 comments on commit 3318167

Please sign in to comment.