Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21190

VB6 win32 API Control Other App Print

$
0
0
Hi,
I have a VB6 app that needs to control another app. Operating systems are XP, Vista, and Win7.
I can make successful API calls to do everything, but there are some issues.
1. I need to tell the other application to print to file. I installed Generic / Text to the FILE port, so when I click on the Print button, I get the "Print to File" popup asking for the name of the file. It works as expected when I do it with a mouse. When I do it with API calls, everything works fine up until the popup is supposed to ask for the name of the file. The only way I can get the popup to appear, receive the name of the file through SendDlgItemMessage, and then accept the BN_CLICK into the OK button is to install a MsgBox after all the SendMessage commands. Without the MsgBox, the app I am controlling crashes, and my app locks up.
SendMessage or PostMessage. It doesn't matter. I use SendMessage to keep my control program from getting too far ahead.

Here is the code:

' prior code found these handles
lRet = SendMessage(hWndPrint, WM_ACTIVATE, 1, 0&)
lRet = SetComboText(hWndSelectPrinter, "Generic") ' my function - it works just fine
lRet = SendMessage(hWndSelect, WM_LBUTTONDOWN, ByVal CLng(MK_LBUTTON), ByVal packed)
lRet = SendMessage(hWndSelect, WM_LBUTTONUP, ByVal CLng(MK_LBUTTON), ByVal packed)
lRet = SendMessage(hWndLandscape, BN_CLICK, ByVal CLng(0), ByVal CLng(0))
lRet = SendMessage(hWndOK, BN_CLICK, ByVal CLng(0), ByVal CLng(0))

' function calls to get hWndPrintToFile, editID, and okID
lRet = SendMessage(hWndPrintToFile, WM_ACTIVATE, 1, 0&)
lRet = SendMessage(hWndPrintToFile, WM_SHOWWINDOW, 0, 0&)
ResultFile = "C:\foo\bar\xyz.txt"
lRet = SendDlgItemMessage(hWndPrintToFile, editID, WM_SETTEXT, 0, ByVal ResultFile)
MsgBox "I have to put this here, or everything crashes"
' On Win7, without the MsgBox, the Print to File popup shows up with no edit text
lRet = SendDlgItemMessage(hWndPrintToFile, okID, BN_CLICK, ByVal CLng(0), ByVal CLng(0))

With the MsgBox, it all works. I can run it over and over, and all is good.

Viewing all articles
Browse latest Browse all 21190

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>