-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/guyrleech/Microsoft
- Loading branch information
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
' Intended to be called by Quick Access Toolbar button when column with date/time imported from csv | ||
' | ||
' Save in "Personal Macro Workbook" (%AppData%\Excel\XLSTART\Personal.xlsb) to autoload | ||
|
||
' @guyrleech 2022/01/26 | ||
|
||
Public Sub FormatAsDateTime() | ||
Dim myRange As Range | ||
Set myRange = Selection | ||
myRange.NumberFormat = "dd/mm/yyyy hh:mm:ss.000" | ||
End Sub | ||
|
||
|
||
Public Sub FormatAsTime() | ||
Dim myRange As Range | ||
Set myRange = Selection | ||
myRange.NumberFormat = "hh:mm:ss.000" | ||
End Sub | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<# | ||
.SYNOPSIS | ||
Dot source this module and call the P/Invoke members as required | ||
.EXAMPLE | ||
. 'Z:\Guys Scripts\Scripts\Window Helper Functions.ps1' | ||
[PInvoke.Win32.UserInput]::IdleTime | ||
.NOTES | ||
Modification# History: | ||
@guyrleech 2022-01-19 First standalone public release | ||
#> | ||
|
||
## Borrowed from http://stackoverflow.com/a/15846912 and adapted | ||
Add-Type @' | ||
using System; | ||
using System.Text; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
namespace PInvoke.Win32 | ||
{ | ||
public static class UserInput | ||
{ | ||
[DllImport("user32.dll", SetLastError=true)] | ||
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); | ||
[DllImport("user32.dll")] | ||
public static extern IntPtr GetTopWindow(IntPtr hWnd); | ||
[DllImport("user32.dll", SetLastError = true)] | ||
public static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd); | ||
public enum GetWindow_Cmd : uint { | ||
GW_HWNDFIRST = 0, | ||
GW_HWNDLAST = 1, | ||
GW_HWNDNEXT = 2, | ||
GW_HWNDPREV = 3, | ||
GW_OWNER = 4, | ||
GW_CHILD = 5, | ||
GW_ENABLEDPOPUP = 6 | ||
} | ||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] | ||
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); | ||
[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)] | ||
public static extern int GetWindowTextLength(IntPtr hWnd); | ||
[DllImport("user32.dll")] | ||
public static extern IntPtr FindWindow(IntPtr sClassName, String sAppName); | ||
[DllImport("user32.dll")] | ||
public static extern bool IsWindowVisible(IntPtr hWnd); | ||
[DllImport("user32.dll")] | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); | ||
public struct RECT | ||
{ | ||
public int Left; | ||
public int Top; | ||
public int Right; | ||
public int Bottom; | ||
} | ||
[DllImport("user32.dll")] | ||
public static extern IntPtr GetForegroundWindow(); | ||
[DllImport("user32.dll", SetLastError=true)] | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
public static extern bool SetForegroundWindow(IntPtr hWnd); | ||
[DllImport("user32.dll")] | ||
public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId); | ||
[DllImport("user32.dll", SetLastError=false)] | ||
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); | ||
[StructLayout(LayoutKind.Sequential)] | ||
private struct LASTINPUTINFO | ||
{ | ||
public uint cbSize; | ||
public int dwTime; | ||
} | ||
public static DateTime LastInput | ||
{ | ||
get | ||
{ | ||
DateTime bootTime = DateTime.UtcNow.AddMilliseconds(-Environment.TickCount); | ||
DateTime lastInput = bootTime.AddMilliseconds(LastInputTicks); | ||
return lastInput; | ||
} | ||
} | ||
public static TimeSpan IdleTime | ||
{ | ||
get | ||
{ | ||
return DateTime.UtcNow.Subtract(LastInput); | ||
} | ||
} | ||
public static int LastInputTicks | ||
{ | ||
get | ||
{ | ||
LASTINPUTINFO lii = new LASTINPUTINFO(); | ||
lii.cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO)); | ||
GetLastInputInfo(ref lii); | ||
return lii.dwTime; | ||
} | ||
} | ||
} | ||
} | ||
'@ | ||
|