您的位置:程序门 -> vb -> 基础类



大家好,如何用vb写虚拟鼠标点击执行具体路径的exe 谢谢!!加分 100


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


大家好,如何用vb写虚拟鼠标点击执行具体路径的exe 谢谢!!加分 100
发表于:2008-01-18 00:29:53 楼主
具体写法加分100
发表于:2008-01-18 09:08:161楼 得分:0
在鼠标点击事件中调用shell来启动程序就好了
发表于:2008-01-18 09:53:532楼 得分:0
帮顶
发表于:2008-01-19 13:33:413楼 得分:0
vbscript code
shell (path_get & "/" & filename) '就是这个样子一行,path_get是你得到的路径,filename是文件名,好久不用vb了,自己稍稍修剪一下了。添加到你需要的事件里面。
发表于:2008-01-19 21:00:414楼 得分:0
这个问题我不是让你下了我上传的代码了吗。
发表于:2008-01-19 21:09:485楼 得分:0
虚拟鼠标点击和shell有什么关系?
发表于:2008-01-19 21:34:496楼 得分:0
看看能有多长时间才结帖
发表于:2008-01-19 22:16:247楼 得分:0
myjian     能有什么提议?
发表于:2008-01-19 22:17:348楼 得分:0
caofusheng     你给的代码   只是在具体的某个坐标的点击   没有   给出具体路径的点击   谢谢
发表于:2008-01-19 22:26:339楼 得分:0
个人觉得你这个想法有问题,既然是模拟点击,应该仍然是点击某个坐标,所以,与要打开文件的路径无关,而与其在屏幕位置有关,因为好象双击文件夹,它并非是在一个固定位置打开。

当然,也并不是你这个想法不能实现,只不过实现起来非常困难,应该涉及到屏幕取词。


发表于:2008-01-19 22:30:0110楼 得分:0
这么说吧   我的vb写的   里面多层调用,可是问题是     写出来后的exe   双击exe可以运行   但是用其他的exe调用就不能运行   是不是兼容性的问题     如果是在解决不了兼容性的问题     有什么办法能让他   通过其他的exe调用   能执行我这个exe   谢谢
发表于:2008-01-19 22:33:1811楼 得分:0
我怀疑是   我调用的资源文件有问题     但是手动双击就可以执行     用其他exe调用就不行了     为什么啊    
发表于:2008-01-19 22:33:5812楼 得分:0
再补充下   有的exe可以调用     有的exe就不能调用   他
发表于:2008-01-19 22:34:1413楼 得分:0
如果是exe调用exe的话shell   应该没有问题的。
发表于:2008-01-19 22:36:0014楼 得分:0
哥们   你能给我   发个私信么     加q   或者msn聊下   具体说下问题行么
发表于:2008-01-19 22:41:0615楼 得分:0
严重赞同caofusheng的说法,如果是exe调用exe的话shell最佳。
发表于:2008-01-19 22:50:0016楼 得分:0
或者我有一种想法,我还是想用虚拟鼠标来执行exe,由于坐标的问题   所以我有一些怪异的想法。
希望大家能多提出想法和宝贵意见   谢谢
以1024x768   分辨率的屏幕为例     第一步   运行exe后由于资源文件无法运行   但是其他的文件可以执行   所以把桌面的分成n个坐标点   每个ico   在一个坐标中  
第二步:   复制这个exe   在桌面   系统会自动把这个exe放在桌面最后一个位置  
第三步:由于之前已经划分出每个ico的坐标   以桌面上的ico最后一个位置的   坐标虚拟双击运行  
  不知道   大家怎么想的   谢谢
发表于:2008-01-20 12:12:4217楼 得分:0
可是问题是           写出来后的exe       双击exe可以运行       但是用其他的exe调用就不能运行  
//
有的exe可以调用           有的exe就不能调用
//

可能是你的问题了.

按你的描述,我能想到的原因是------------初始化路径(也就是快捷方式属性窗口里的那个"起始位置").

拿createprocess这个api来举例.它的原型如下:

c/c++ code
bool createprocess( lpctstr lpapplicationname, // pointer to name of EXECutable module lptstr lpcommandline, // pointer to command line string lpsecurity_attributes lpprocessattributes, // process security attributes lpsecurity_attributes lpthreadattributes, // thread security attributes bool binherithandles, // handle inheritance flag dword dwcreationflags, // creation flags lpvoid lpenvironment, // pointer to new environment block lpctstr lpcurrentdirectory, // pointer to current directory name lpstartupinfo lpstartupinfo, // pointer to startupinfo lpprocess_information lpprocessinformation // pointer to process_information );


lpcurrentdirectory这个参数,就是指定了程序启动时的初始路径.

如果你的程序里使用了相对路径,而这个相对路径却没有使用app.path来指定的话,就会有这情况.

为此我写了一个小小的测试程序,如下:

vbscript code
'这个框里的代码所需要的条件: '新建一个exe工程; '在默认的窗体上添加两个按钮,名称不变,为command1与command2; '然后把这里所有的代码复制到窗体的代码窗口里面去,并生成一个exe备用.我是生成了名为"testinitdir.exe"的文件. option explicit private sub command1_click() '不使用定位 if dir("1.txt") <> "" then msgbox "true" '找到文件,就弹出true else msgbox "false" '没找到,就弹出false end if end sub private sub command2_click() '使用自定位 if dir(addstrtostr(app.path, "\") & "1.txt") <> "" then msgbox "true" '找到文件,就弹出true else msgbox "false" '没找到,就弹出false end if end sub private function addstrtostr(byval str1 as string, byval str2 as string) as string '自动添加字符串到目标字符串结尾 if lcaseright(str1, len(str2))) = lcase(str2) then addstrtostr = str1 else addstrtostr = str1 & str2 end if end function


以上是一个工作程序,是模拟你的exe用的.

下面这个是模拟其它的exe调用你的exe的情况.

vbscript code
'这个框里的代码所需要的条件: '新建一个exe工程; '在默认的窗体上添加两个按钮,名称不变,为command1与command2; '然后把这里所有的代码复制到窗体的代码窗口里面去.可以不生成exe而直接在ide里调用. option explicit const infinite = &hffff const startf_useshowwindow = &h1 private enum ensw sw_hide = 0 sw_normal = 1 sw_maximize = 3 sw_minimize = 6 end enum 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 byte hstdinput as long hstdoutput as long hstderror as long end type private type security_attributes nlength as long lpsecuritydescriptor as long binherithandle as long end type private enum enpriority_class normal_priority_class = &h20 idle_priority_class = &h40 high_priority_class = &h80 end enum private declare function createprocess lib "kernel32" alias "createprocessa" (byval lpapplicationname as string, byval lpcommandline as string, lpprocessattributes as security_attributes, lpthreadattributes as security_attributes, 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 waitforsingleobject lib "kernel32" (byval hhandle as long, byval dwmilliseconds as long) as long private function supershell(byval app as string, byval workdir as string, dwmilliseconds as long, byval start_size as ensw, byval priority_class as enpriority_class) as boolean '增强的shell dim pclass as long dim sinfo as startupinfo dim pinfo as process_information dim sec1 as security_attributes dim sec2 as security_attributes sec1.nlength = len(sec1) sec2.nlength = len(sec2) with sinfo .cb = len(sinfo) .dwflags = startf_useshowwindow .wshowwindow = start_size end with pclass = priority_class if createprocess(vbnullstring, app, sec1, sec2, false, pclass, _ 0&, workdir, sinfo, pinfo) then waitforsingleobject pinfo.hprocess, dwmilliseconds supershell = true else supershell = false end if end function private sub command1_click() '模拟"指定了错误的初始目录"的情况 supershell "d:\temp\testinitdir.exe", vbnullstring, -1, sw_normal, normal_priority_class end sub private sub command2_click() '模拟"指定了正确的初始目录"的情况 supershell "d:\temp\testinitdir.exe", "d:\temp\", -1, sw_normal, normal_priority_class end sub


以上工作完成后,按如下过程来测试:

首先在第一个exe也就是testinitdir.exe所在的目录下放一个1.txt,这个文件是模拟你exe所使用的一些文件;

手工双击这个exe,看看两个按钮点下去所得到的结果是不是都是true?如果是,那就继续:

现在关了那个exe,使用第二个工程来启动它.

当然,第二个工程的那几个路径你得改成你机器上testinitdir.exe实际的路径~~

好.

使用第一个按钮来启动testinitdir.exe时,出现什么了?

你点点testinitdir.exe的第一个按钮?再点点第二个按钮?

关了这个testinitdir.exe,返回~~~

然后用第二个按钮来启动testinitdir.exe再试下?

明白了没?

如果你的程序真的是这个原因造成的,那么解决就非常简单-------在需要使用一个相对的资源时,使用app.path来进行自定位就ok了.

本来没必要写这么多,但是本着"学习why而不是学习how"的想法,把原因也写了一下.....于是才啰嗦了这么大一堆:)

希望这些能帮到你.

当然也希望你的问题就是这个原因~~嘿嘿

不然就是牛头不对马嘴啦.....
发表于:2008-01-22 13:22:2518楼 得分:0
呵呵     谢谢你的办法     我先测试下     万分感谢
发表于:2008-01-22 14:47:4919楼 得分:0
老马嗷的真好


快速检索

最新资讯
热门点击