不好意思 请问:如何把调用的外部程序在屏幕指定位置运行?

firewoods 2008-03-11 04:43:35
求教 如题
我希望实现的是 在点击一个按钮时 把调用的外部程序 放在屏幕上的指定位置运行 这样比较整齐
另外 最好能监控一下这个程序的运行情况 比如:窗口虽然还在 但是已经停止运行了 呵呵

通过查找 目前已经解决了从外部调用指定程序了 但是其它的怎么写 就查不到了 汗。。。

有劳各位高手了!!
谢谢!请不吝赐教!
...全文
251 21 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
firewoods 2008-03-29
  • 打赏
  • 举报
回复
......刚才看了一下 似乎又有20分 汗 有多少算多少
反正偶不蒙你就是了 o(∩_∩)o
firewoods 2008-03-29
  • 打赏
  • 举报
回复
偶然溜达回来了
原来这里忘了结贴了
不好意思
感谢诸位朋友了!
我手里只有3分了 就送给【jennyvenus】老兄吧
偶实在不知道该咋挣分数 回帖啥的都不加分 晕死了
汗啊
嗷嗷叫的老马 2008-03-13
  • 打赏
  • 举报
回复
两种语言有一定的"语法相似"性....

但本质不同了....

不过貌似都比较容易入门.

相对来说,VB.NET貌似很多地方要优于VB6...
firewoods 2008-03-13
  • 打赏
  • 举报
回复
谢谢楼上的诸位老大了!
学生在此作揖了 o(∩_∩)o
祝各位开心顺利!
用户 昵称 2008-03-12
  • 打赏
  • 举报
回复
发往.net技术区。
firewoods 2008-03-12
  • 打赏
  • 举报
回复
请问 有关VB.net的求助 应该发在这个区 还是别的区?
用户 昵称 2008-03-11
  • 打赏
  • 举报
回复
-窗体代码

Option Explicit

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Declare Function CreateProcess Lib "kernel32" _
Alias "CreateProcessA" _
(ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As Any, _
lpThreadAttributes As Any, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long

Private Declare Function OpenProcess Lib "kernel32.dll" _
(ByVal dwAccess As Long, _
ByVal fInherit As Integer, _
ByVal hObject As Long) As Long

Private Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Const SYNCHRONIZE = 1048576
Const NORMAL_PRIORITY_CLASS = &H20&
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long




Private Sub Command1_Click()
Dim pInfo As PROCESS_INFORMATION
Dim sInfo As STARTUPINFO
Dim sNull As String
Dim lSuccess As Long
Dim lRetValue As Long


sInfo.cb = Len(sInfo)
lSuccess = CreateProcess(sNull, _
"c:\windows\system32\notepad.exe", _
ByVal 0&, _
ByVal 0&, _
1&, _
NORMAL_PRIORITY_CLASS, _
ByVal 0&, _
sNull, _
sInfo, _
pInfo)

Dim s As Double
s = Timer
Do
DoEvents
Loop While Timer - s < 5

start = 0

EnumThreadWindows pInfo.dwThreadId, AddressOf EnumThreadWndProc, 0

'Debug.Print h
Debug.Print Hex$(thehwnd)

SetWindowPos thehwnd, 0, 0, 0, 100, 100, 0

'pinfo.

'MsgBox "Calculator has been launched!"

'lRetValue = TerminateProcess(pInfo.hProcess, 0&)
'lRetValue = CloseHandle(pInfo.hThread)
'lRetValue = CloseHandle(pInfo.hProcess)

'MsgBox "Calculator has terminated!"
End Sub


模块代码
Option Explicit
'In a module
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function EnumThreadWindows Lib "user32" (ByVal dwThreadId As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
'variable used to list all the classnames
Public sClasses As String
Public start As Long
Public thehwnd As Long


Public Function EnumThreadWndProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim Ret As Long, sText As String

If start = 0 Then
thehwnd = hwnd
End If
start = start + 1
'create a string-buffer
sText = Space(255)
'get the classname of the window handle
Ret = GetClassName(hwnd, sText, 255)
'cut off the unnecessary part of Chr$(0)'s
sText = Left$(sText, Ret)
'add this classname to the list of classnames
sClasses = sClasses + sText + vbCrLf
'continue the enumeration
EnumThreadWndProc = 1
End Function
用户 昵称 2008-03-11
  • 打赏
  • 举报
回复
用createprocess api,其中的参数startupinfo 的参数也许可以设置。
firewoods 2008-03-11
  • 打赏
  • 举报
回复
汗。。。。
偶买的书就是VB2005的
卖书的人说 这个最新 偶就买了
看来偶上了贼船下不去了 哭啊!

无论如何 也是要感谢您的!
用户 昵称 2008-03-11
  • 打赏
  • 举报
回复
vb.net俺也不会,你找找别人吧。
firewoods 2008-03-11
  • 打赏
  • 举报
回复
有两个error偶不会改 汗
.
.
.
.

第一个是:“as any”is not supported in “declare”statements.

查了MSDN “as any”是VB6的代码 偶的VB2005不支持了 MSDN给出的意见是
To correct this error
Declare parameters of the specific type you want to use; for example.

Visual Basic 코드 복사
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" ( _
ByVal lpBuffer As String, _
ByRef nSize As Integer) _
As Integer

Use the MarshalAsAttribute attribute to specify As Any when Void* is expected by the procedure being called.

Visual Basic 코드 복사
Declare Sub SetData Lib "..\LIB\UnmgdLib.dll" ( _
ByVal x As Short, _
<System.Runtime.InteropServices.MarshalAsAttribute( _
System.Runtime.InteropServices.UnmanagedType.AsAny)> _
ByVal o As Object)
.
.
.
.
第二个是"addressof" expression cannot be coverted to "integer" because "integer" is not a delegate type.
A statement attempts to convert an AddressOf expression to a type that is not a delegate type.

The AddressOf operator creates a procedure delegate instance that references a specific procedure. AddressOf can be used as the operand of a delegate constructor, or it can be used in a context in which the type of the delegate can be determined by the compiler.

Error ID: BC30581

To correct this error
Change the target type to a delegate type.
这个更不会改了
.
实在不好意思 麻烦各位老师了!
firewoods 2008-03-11
  • 打赏
  • 举报
回复
谢谢您!
我先试试
主要是我的基础太差了

我才学了不到一周 而且是断断续续的
汗。。。。
用户 昵称 2008-03-11
  • 打赏
  • 举报
回复
谢谢,您太客气了,我几乎的代码都是在网上找的,只不过整理了一下。
firewoods 2008-03-11
  • 打赏
  • 举报
回复
实在太感谢了!

【 jennyvenus 】兄
我是天津人
如果你离天津不太远的话
可否赏光 让我请您饭饭?
用户 昵称 2008-03-11
  • 打赏
  • 举报
回复
当然,我前面贴的就是代码,发exe还有什么必要。
firewoods 2008-03-11
  • 打赏
  • 举报
回复
汗。。。。
我的邮箱是xiao_sk@163.com

【 jennyvenus 】兄
麻烦您能否别把完成后的工程发布生成“.exe”文件
偶想看看您是怎么做的 我学学
有些地方也许我还会做一些改动

实在惭愧

万分感谢!
用户 昵称 2008-03-11
  • 打赏
  • 举报
回复
启动VB,选择标准exe

在窗口上加一个按钮command1

再建一个模块,不是类模块

将对应的代码加入到对应的代码中,前一部分加入窗口的代码中,后一部分加入模块中

你有没有邮箱,我将工程发给你得了。
firewoods 2008-03-11
  • 打赏
  • 举报
回复
万分感谢【 jennyvenus 】兄

我尝试这把上诉代码复制到“Public Class Form1”当中
可是报出来一堆错
主要是“declatation expected”代码没有声明?

汗。。。。我的基础太差了
可是这东东又有急用 汗啊
firewoods 2008-03-11
  • 打赏
  • 举报
回复
不充一下 偶是新学VB2005的 从前没基础 (VB6等没有接触过)
谢谢了!
firewoods 2008-03-11
  • 打赏
  • 举报
回复
万分感谢【 jennyvenus 】兄的指导!
实在惭愧 这些代码偶都不知道该放在哪里
汗啊!
加载更多回复(1)

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧