问题描述
我正在更新我在VB6中编写的旧版ScreenSaver到VB.net 2010我最初使用的Windows窗体应用程序工作正常,直到预览屏幕。使用以下代码将应用程序加载到预览屏幕(或其他应用程序,如记事本):
公共 Sub SetForm( ByRef frm 作为表单, ByRef arg As 字符串)
Dim 样式作为 整数
Dim preview_hwnd As 整数 = 整数 .Parse( CType (arg,_
字符串))
Dim r 作为 新 R. ECT
' 获取预览窗口的大小。
GetClientRect( preview_hwnd,r)
使用 frm
.WindowState = FormWindowState.Normal
.FormBorderStyle = FormBorderStyle.None
.Width = r.right
.Height = r.bottom
结束 使用
' 将WS_CHILD样式添加到表单中。
style = GetWindowLong(frm.Handle.ToInt32,GWL_STYLE)
style = style 或 WS_CHILD
SetWindowLong(frm.Handle.ToInt32,GWL_STYLE,样式)
' 将表格重新显示到预览窗口。
SetParent(frm.Handle.ToInt32,preview_hwnd)
' 将表单的GWL_PARENT值设置为预览窗口。
SetWindowLong(frm.Handle.ToInt32,GWL_HWNDPARENT ,_
preview_hwnd)
' 将表单放在预览窗口中。
SetWindowPos(frm.Handle.ToInt32, 0 ,r.left, 0 ,r.right,_
r.bottom,SWP_NOACTIVATE 或 SWP_NOZORDER 或 SWP_SHOWWINDOW)
结束 Sub
冻结父窗口,启动表单没有输入。
切换到控制台应用程序并使用
Dim scrsvr As 新 frmScr
scrsvr.Preview = True
SetForm(scrsvr,args( 1 ))
Application.Run(scrsvr)
修复了大部分问题,但表单/屏幕保护程序仍然在预览屏幕中或在不运行setform的情况下作为全屏幕屏幕保护程序运行时,不接受键盘输入。有趣的是,配置屏幕在从控制台应用程序启动时运行正常。
在VB.net 2010中,唯一的选项似乎是从表单运行应用程序(表单应用程序)或从控制台(控制台应用程序)。在VB6中,我们可以运行一个表单应用程序,但是从Sub Main开始。
任何帮助都表示赞赏。
I'm updating an old ScreenSaver that I wrote in VB6 to VB.net 2010 I initially used a windows forms application that worked fine until the preview screen. Loading the application into the preview screen (or other application like notepad) using the code:
Public Sub SetForm(ByRef frm As Form, ByRef arg As String) Dim style As Integer Dim preview_hwnd As Integer = Integer.Parse(CType(arg, _ String)) Dim r As New RECT 'Get the preview window's size. GetClientRect(preview_hwnd, r) With frm .WindowState = FormWindowState.Normal .FormBorderStyle = FormBorderStyle.None .Width = r.right .Height = r.bottom End With ' Add the WS_CHILD style to the form. style = GetWindowLong(frm.Handle.ToInt32, GWL_STYLE) style = style Or WS_CHILD SetWindowLong(frm.Handle.ToInt32, GWL_STYLE, style) ' Reparent the form into the preview window. SetParent(frm.Handle.ToInt32, preview_hwnd) 'Set the form's GWL_PARENT value to the preview window. SetWindowLong(frm.Handle.ToInt32, GWL_HWNDPARENT, _ preview_hwnd) ' Position the form in the preview window. SetWindowPos(frm.Handle.ToInt32, 0, r.left, 0, r.right, _ r.bottom, SWP_NOACTIVATE Or SWP_NOZORDER Or SWP_SHOWWINDOW) End Sub
freezes the parent window and there is no input to the launched form.
Switching to a console app and using
Dim scrsvr As New frmScr scrsvr.Preview = True SetForm(scrsvr, args(1)) Application.Run(scrsvr)
fixed most of the problem, but the form/screensaver still doesn't accept keyboard input, either when in the preview screen or running as a full screen screensaver without running "setform". Interestingly, the configuration screen runs fine when launched from the console app.
In VB.net 2010, the only options seem to be running an app either from a form (forms application) or from the console(Console app). In VB6 we could run a forms app yet start from a Sub Main.
Any help is appreciated.
这篇关于如何捕获从VB.Net 2010中的控制台应用程序启动的表单中的击键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!