我有一个程序,它没有实现标准的 Windows 窗口控件(即标题栏和框架)。
我想强制此窗口以给定的大小打开,但我认为不使用标准窗口控件会影响所有常用解决方案,例如 Power Toys 的 FancyZones。
有办法解决这个问题吗?也许有办法强制使用默认标题栏?
答案1
窗口大小调整工具. 更改窗口大小
这使用了 Windows 10 中的内置编译器 - 有三个 VB.NET 编译器、三个 JScript 编译器和三个 C# 编译器。
只需将每个文本文件复制到同一文件夹中,然后双击批处理文件即可制作程序。
REM SizeWindow.bat
REM This file compiles SizeWindow.vb to SizeWindow.exe
REM SizeWindow changes the size of a window
REM To use
REM SizeWindow nnnnxnnnn <Window title>
REM E.G.
REM SizeWindow 300x400 Untitled - Notepad
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:winexe /out:"%~dp0\SizeWindow.exe" "%~dp0\SizeWindow.vb" /verbose
pause
'SizeWindow.vb
Imports System
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Public Module TopMost
Public Declare UNICODE Function FindWindowW Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As IntPtr, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &h4
Sub Main()
On Error Resume Next
Dim hWindows as IntPtr
Dim CmdLine as String
Dim Ret as Integer
CmdLine = Command()
Dim A as String()
Dim B as String()
A = Split(CmdLine, Chr(32), 2, 1)
B = Split(A(0), "x", 2, 1)
hwindows = FindWindowW(vbNullString, A(1))
If hwindows = 0 then
Msgbox(A(1) & " cannot be found.")
Else
Ret = SetWindowPos(hwindows, HWND_NOTOPMOST, 0, 0, B(0), B(1), SWP_NOMOVE + SWP_NOZORDER)
If Ret = 0 Then MsgBox("Set Pos Error is " & Err.LastDllError)
End If
End Sub
End Module
使用
SizeWindow 300x400 Untitled - Notepad
从https://winsourcecode.blogspot.com/2021/03/sizewindowexe-changes-size-of-window.html
如果你需要知道标题或班级名称,请参阅 Winlist.exehttps://winsourcecode.blogspot.com/2019/05/winlistexe-list-open-windows-and-their.html。
使用此命令会给出如下输出
WinList.exe" | Findstr /c:notepad
Window Text Class Name Unicode HWnd ParentHWnd ProcessID ThreadID Process Name
MSCTFIME UI MSCTFIME UI True 1770634 65668 3432 8228 notepad.exe
Default IME IME True 1049692 65668 3432 8228 notepad.exe
Untitled - Notepad Notepad True 460174 65668 3432 8228 notepad.exe
«No Window Text» Edit True 591400 460174 3432 8228 notepad.exe
«No Window Text» msctls_statusbar32 True 1114996 460174 3432 8228 notepad.exe