on 08-07-2015 11:50 AM
Hi, everybody.
Our team is working on an SDK add-on which will print a PLD Report linked to the Inventory Transfer Screen in SAP B1.
We have successfully done the following steps using UI API (i.e ActivateMenuItem)
This opens the Windows Dialog. We must now press "ENTER" to print the PLD Report.
How to do this?
-------------
We found the answer here. It is exactly our problem.
Answer provided by:
It seems to work for the person who asked the question, but it does not work for us.
We have no idea what went wrong. Any suggestions to help us find what's wrong?
Where must we put this 3rd section in our VB.NET Program?
--------------
' // Now implement the timer eventhandler (thread safe, you can send any keys like ENTER which closes the print dialog box and ESC when you would like to cancel
Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs)
Dim lHwnd As Integer = GetForegroundWindow
If lCurHwnd = lHwnd Then Exit Sub
' Send enter key to Commit the dialog window
System.Windows.Forms.SendKeys.SendWait("{ENTER}")
'Stop timer
_timer.Enabled = False
End Sub
--------------
Thanks
Leon
Added:
If there is another way to print the PLD Report without popping up the Windows Print Dialog, this will simplify my coding:
I am thinking of the following alternatives:
Could anyone give me the SDK coding to effect these (or give me an indication how to do these)
Thanks
Leon
======================================================================
For convenience, we copy the full solution provided by Janos Nagy below
======================================================================
Logic:
You should implement a multi-threaded program, which is looking for the operating system actual window, and compares with the SAP B1 Window ID. If differs, then you can send an enter key. (click on default button).
You can build up thread safe procedure with custom code, but i have used there a timer, which starts when you send the printing, and stops when enter has been sent.
Add the following code to your addon variables declare section:
Private Declare Function GetForegroundWindow Lib "user32.dll" () As IntPtr
Dim _timer As New System.Timers.Timer
Dim lCurHwnd As Integer
When you activating the Print Menu, add the following code
' SAP B1 Window ID via Windows API Call
lCurHwnd = GetForegroundWindow()
_timer.Interval = 100
AddHandler _timer.Elapsed, New System.Timers.ElapsedEventHandler(AddressOf Me.Timer1_Elapsed)
_timer.Enabled = True
'RockAndRoll
SBO_Application.ActivateMenuItem("520")
Now impement the timer eventhandler (thread safe, you can send any keys like ENTER which closes the print dialog box and ESC when you would like to cancel
Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs)
Dim lHwnd As Integer = GetForegroundWindow
If lCurHwnd = lHwnd Then Exit Sub
' Send enter key to Commit the dialog window
System.Windows.Forms.SendKeys.SendWait("{ENTER}")
'Stop timer
_timer.Enabled = False
End Sub
======================================================================
Dear Leon Lai Kan
try this
System.Windows.Forms.SendKeys.Send("{^}{+}(p)")
System.Windows.Forms.SendKeys.Send("{ENTER}")
Regards,
Nadeemkhan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.