Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Postmessage function in QTP for simulating Printscreen key does not work
#1
Not Solved
I am using the following code to simulate a PrintScreen button press to capture the image of a Internet Explorer window. I have assigned Printscreen as a Hotkey in Greenshot tool to capture the image of the full page in one go without having to scroll.

Code:
Extern.Declare micLong, "PostMessage", "user32.dll", "PostMessageA", micHwnd, micLong, micLong, micLong

Const WM_KEYDOWN = 273
Const VK_SNAPSHOT = 44

iResult = Extern.PostMessage( Hwnd, WM_KEYDOWN, VK_SNAPSHOT, 0)
But somehow the value of iResult is always 1. Hwnd is the actual window handle of the Internet explorer window which is passed to the Postmessage function. The reason why I am using this approach is because the screenshot capturing process needs to be automated completely and should run when the system is locked as well. SendKeys does not work when system is locked and so I had to move to Post Message.

Could someone please help me out with this.
Reply
#2
Not Solved
Please ensure to include your code between [code] tags while asking or replying to questions. I have done this for you for this time.
Reply
#3
Not Solved
Did you try with CaptureBitmap? Its syntax is

Code:
object.CaptureBitmap  FullFilename, [OverrideExisting]

Also avoid locking of a screen while running QTP scripts. You can take help of a tool like caffeine
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#4
Not Solved
instead of using this method i will send u the function and how to use that but this code i posted in the articles in the forum if u did not get it i will send u again

Code:
Public Sub CaptureScreenshot( ByRef Sender, ByVal micStatus, ByVal descriptionStr )  
Dim dateTimeNow, fileNameStr, divDesc, caption
Dim dicMetaDescription, qtp
dateTimeNow = DotNetFactory.CreateInstance( "System.DateTime" ).Now.ToString( "ddMMyyHHmmss" )    
fileNameStr = Reporter.ReportPath & "\" & dateTimeNow & ".png"    
Set qtp = CreateObject( "QuickTest.Application" )  
qtp.Visible = False
Wait 0, 500    
If IsObject( sender ) Then      
Sender.CaptureBitmap fileNameStr, True      
caption = Sender.ToString & " - Capture Bitmap"    
Else      
Desktop.CaptureBitmap fileNameStr, True      
caption = "Desktop - Capture Bitmap"    
End If
qtp.Visible = True
divDesc = "<table align='center' border='5' cellpadding='1' cellspacing='1' width='100%' title='" & fileNameStr & "' frame='hsides'>" & _              
               "<caption>" & caption & "</caption>" & _              
  "<thead><tr><th>Application Exception Description</th></tr></thead>" & _              
  "<tfoot><tr><td align='center'><img border='2px' src='" & fileNameStr & "' /></td></tr></tfoot>" & _              
  "<tbody><tr><td>" & descriptionStr & "</td></tr></tbody></table>"    
Set dicMetaDescription = CreateObject( "Scripting.Dictionary" )    
dicMetaDescription( "Status" ) = micStatus    
dicMetaDescription( "PlainTextNodeName" ) = "ApplicationException"    
dicMetaDescription( "StepHtmlInfo" ) = "<DIV align=center>" & divDesc & "</DIV>"  
dicMetaDescription( "DllIconIndex" ) = 205    
dicMetaDescription( "DllIconSelIndex" ) = 205
dicMetaDescription( "DllPAth" ) = EnVironment( "ProductDir" ) & "\bin\ContextManager.dll"  
Call Reporter.LogEvent( "User", dicMetaDescription, Reporter.GetContext )
End Sub
to use it in the script just keep the below lines at the top of your script
Code:
RegisterUserFunc "Page", "CaptureScreenshot", "CaptureScreenshot"
RegisterUserFunc "Browser", "CaptureScreenshot", "CaptureScreenshot"
RegisterUserFunc "Frame", "CaptureScreenshot", "CaptureScreenshot"
RegisterUserFunc "Dialog", "CaptureScreenshot", "CaptureScreenshot"
RegisterUserFunc "swfWindow", "CaptureScreenshot", "CaptureScreenshot"
just place this line where you want to capture the screenshot
Code:
Browser("micclass:=Browser").Page("micclass:=Page").CaptureScreenshot micPass, "<h4 align = ""Center"">Page SuccessFully Displayed</h4>"

write the function which i have written above in a library function and add it to the script
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question what is the shortcut key used to switch between keyword view and expert view in qtp. shaileshanand86 5 11,256 02-13-2019, 03:58 AM
Last Post: zia003
  Calling a Function in Function Library when function is defined in an Action jitenderkkr 0 2,769 11-27-2014, 12:53 PM
Last Post: jitenderkkr
  Facing issue with Java Table to press Enter Key from Keyboard Nasir Ahmed 0 4,386 05-23-2014, 08:05 PM
Last Post: Nasir Ahmed
  unable to click webelement by holding shift key tanyamrz 1 3,356 09-14-2012, 05:21 AM
Last Post: kcn
  Send key method does not set value on webEdit object. sandeep arora 1 14,379 04-05-2012, 05:27 PM
Last Post: verma.vik6

Forum Jump:


Users browsing this thread: 1 Guest(s)