Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张东亮
/
NS100
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 90c1bd42
由
张东亮
编写于
2023-04-11 14:00:17 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1
1 个父辈
b2a03fd1
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
57 行增加
和
4 行删除
SmartScan/Program.cs
SmartScan/Program.cs
查看文件 @
90c1bd4
...
@@ -7,6 +7,9 @@ using System.Runtime.InteropServices;
...
@@ -7,6 +7,9 @@ using System.Runtime.InteropServices;
using
System.IO
;
using
System.IO
;
using
BLL
;
using
BLL
;
using
log4net
;
using
log4net
;
using
System.Text
;
using
System.Collections.Generic
;
using
log4net.Util
;
namespace
SmartScan
namespace
SmartScan
{
{
...
@@ -31,9 +34,9 @@ namespace SmartScan
...
@@ -31,9 +34,9 @@ namespace SmartScan
_
=
new
Mutex
(
true
,
Application
.
ProductName
,
out
bool
ret
);
_
=
new
Mutex
(
true
,
Application
.
ProductName
,
out
bool
ret
);
if
(!
ret
)
if
(!
ret
)
{
{
IntPtr
formhwnd
=
FindWindow
(
null
,
"BarCode Rule Setting"
);
IntPtr
formhwnd
=
GetWindowHandle
(
"BarCode Rule Setting"
);
if
(
formhwnd
==
IntPtr
.
Zero
)
if
(
formhwnd
==
IntPtr
.
Zero
)
formhwnd
=
FindWindow
(
null
,
"条码规则设置"
);
formhwnd
=
GetWindowHandle
(
"条码规则设置"
);
show
(
$
"查找条码规则窗口句柄:{formhwnd}"
);
show
(
$
"查找条码规则窗口句柄:{formhwnd}"
);
if
(
formhwnd
!=
IntPtr
.
Zero
)
if
(
formhwnd
!=
IntPtr
.
Zero
)
...
@@ -193,7 +196,11 @@ namespace SmartScan
...
@@ -193,7 +196,11 @@ namespace SmartScan
/// <param name="fAltTab">True代表窗口正在通过Alt/Ctrl +Tab被切换</param>
/// <param name="fAltTab">True代表窗口正在通过Alt/Ctrl +Tab被切换</param>
[
DllImport
(
"user32.dll "
,
SetLastError
=
true
)]
[
DllImport
(
"user32.dll "
,
SetLastError
=
true
)]
static
extern
void
SwitchToThisWindow
(
IntPtr
hWnd
,
bool
fAltTab
);
static
extern
void
SwitchToThisWindow
(
IntPtr
hWnd
,
bool
fAltTab
);
[
DllImport
(
"user32.dll"
)]
private
static
extern
int
GetClassNameW
(
IntPtr
hWnd
,
[
MarshalAs
(
UnmanagedType
.
LPWStr
)]
StringBuilder
lpString
,
int
nMaxCount
);
private
delegate
bool
WNDENUMPROC
(
IntPtr
hWnd
,
int
lParam
);
[
DllImport
(
"user32.dll"
)]
private
static
extern
bool
EnumWindows
(
WNDENUMPROC
lpEnumFunc
,
int
lParam
);
/// <summary>
/// <summary>
/// 设置窗口的显示状态
/// 设置窗口的显示状态
/// </summary>
/// </summary>
...
@@ -203,7 +210,53 @@ namespace SmartScan
...
@@ -203,7 +210,53 @@ namespace SmartScan
[
DllImport
(
"user32.dll"
,
EntryPoint
=
"ShowWindow"
,
CharSet
=
CharSet
.
Auto
)]
[
DllImport
(
"user32.dll"
,
EntryPoint
=
"ShowWindow"
,
CharSet
=
CharSet
.
Auto
)]
public
static
extern
int
ShowWindow
(
IntPtr
hwnd
,
int
nCmdShow
);
public
static
extern
int
ShowWindow
(
IntPtr
hwnd
,
int
nCmdShow
);
public
const
int
SW_RESTORE
=
9
;
public
const
int
SW_RESTORE
=
9
;
[
DllImport
(
"user32.dll"
)]
private
static
extern
int
GetWindowTextW
(
IntPtr
hWnd
,
[
MarshalAs
(
UnmanagedType
.
LPWStr
)]
StringBuilder
lpString
,
int
nMaxCount
);
#
endregion
#
endregion
//寻找系统的全部窗口
static
WindowInfo
[]
GetAllDesktopWindows
()
{
List
<
WindowInfo
>
wndList
=
new
List
<
WindowInfo
>();
EnumWindows
(
delegate
(
IntPtr
hWnd
,
int
lParam
)
{
WindowInfo
wnd
=
new
WindowInfo
();
StringBuilder
sb
=
new
StringBuilder
(
256
);
//get hwnd
wnd
.
hWnd
=
hWnd
;
//get window name
GetWindowTextW
(
hWnd
,
sb
,
sb
.
Capacity
);
wnd
.
szWindowName
=
sb
.
ToString
();
//get window class
GetClassNameW
(
hWnd
,
sb
,
sb
.
Capacity
);
wnd
.
szClassName
=
sb
.
ToString
();
Console
.
WriteLine
(
"Window handle="
+
wnd
.
hWnd
.
ToString
().
PadRight
(
20
)
+
" szClassName="
+
wnd
.
szClassName
.
PadRight
(
20
)
+
" szWindowName="
+
wnd
.
szWindowName
);
//add it into list
wndList
.
Add
(
wnd
);
return
true
;
},
0
);
return
wndList
.
ToArray
();
}
static
IntPtr
GetWindowHandle
(
string
titleName
)
{
WindowInfo
[]
a
=
GetAllDesktopWindows
();
int
i
=
0
;
for
(
i
=
0
;
i
<
a
.
Length
;
i
++)
{
// MessageBox.Show(a[i].szWindowName.ToString());
if
(
a
[
i
].
szWindowName
.
ToString
().
Contains
(
titleName
))
{
return
a
[
i
].
hWnd
;
}
}
return
IntPtr
.
Zero
;
}
}
public
struct
WindowInfo
{
public
IntPtr
hWnd
;
public
string
szWindowName
;
public
string
szClassName
;
}
}
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论