Window API in QTP

In my previous post, I talk about How to use windows API send click message to an “ok” button of IE alert dialog. The code used c#. I’d like to transmit them to QTP. It’ll more stable and efficient than QTP built-in Function.

In QTP, if we want to do some action on a dialog, we should add a dialog object to repository.QTP can use their properties to find the dialog then execute command. But the problem is that some dialog’s properties are dynamic. Such as the title of Download Dialog.It lead to QTP couldn’t find exactly object. That’s why our automation script sometimes is slow and broken.

To avoid these tricky, QTP provide us external object. It can be used to call external function. Windows API is good experience. We can use Windows API in QTP. It’s terrific, right? We can using API do everything efficiently.

Following is the script segment to click “OK” button of IE pop dialog.

extern.Declare micHwnd,"FindWindowEx", "user32.dll","FindWindowEx",micHwnd,micHwnd,micString,micString

extern.Declare micLong, "PostMessage", "user32.dll", "PostMessageA", micHwnd, micLong, micLong, micLong

extern.Declare micHwnd,"SetActiveWindow","user32.dll","SetActiveWindow",micHwnd

extern.Declare micInteger,"SetForegroundWindow","user32.dll","SetForegroundWindow",micHwnd

hwndP = extern.FindWindowEx (0,0,"#32770", null)

hwndButton = extern.FindWindowEx (hwndP,0,"Button","OK")

extern.SetForegroundWindow hwndP

extern.SetActiveWindow hwndP

extern.PostMessage hwndButton,&H0F5,0,0

 

Enjoy QTP; enjoy your auto-life!

转载于:https://www.cnblogs.com/gyhanonline/archive/2010/05/01/1725621.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值