Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use the Internet Explorer's preview to view a report

COM and Automation

How to use the Internet Explorer's preview to view a report

by  Mike Gagnon  Posted    (Edited  )
Code:
*Constants for ExecWB first parameter
#DEFINE OLECMDID_OPEN 1
#DEFINE OLECMDID_NEW 2
#DEFINE OLECMDID_SAVE 3
#DEFINE OLECMDID_SAVEAS 4
#DEFINE OLECMDID_SAVECOPYAS 5
#DEFINE OLECMDID_PRINT 6
#DEFINE OLECMDID_PRINTPREVIEW 7
#DEFINE OLECMDID_PAGESETUP 8
#DEFINE OLECMDID_SPELL 9
#DEFINE OLECMDID_PROPERTIES 10
#DEFINE OLECMDID_CUT 11
#DEFINE OLECMDID_COPY 12
#DEFINE OLECMDID_PASTE 13
#DEFINE OLECMDID_PASTESPECIAL 14
#DEFINE OLECMDID_UNDO 15
#DEFINE OLECMDID_REDO 16
#DEFINE OLECMDID_SELECTALL 17
#DEFINE OLECMDID_CLEARSELECTION 18
#DEFINE OLECMDID_ZOOM 19
#DEFINE OLECMDID_GETZOOMRANGE 20
#DEFINE OLECMDID_UPDATECOMMANDS 21
#DEFINE OLECMDID_REFRESH 22
#DEFINE OLECMDID_STOP 23
#DEFINE OLECMDID_HIDETOOLBARS 24
#DEFINE OLECMDID_SETPROGRESSMAX 25
#DEFINE OLECMDID_SETPROGRESSPOS 26
#DEFINE OLECMDID_SETPROGRESSTEXT 27
#DEFINE OLECMDID_SETTITLE 28
#DEFINE OLECMDID_SETDOWNLOADSTATE 29
#DEFINE OLECMDID_STOPDOWNLOAD 30

*Constants for ExecWB second parameter
#DEFINE OLECMDEXECOPT_DODEFAULT 0 
#DEFINE OLECMDEXECOPT_PROMPTUSER 1
#DEFINE LECMDEXECOPT_DONTPROMPTUSER 2
#DEFINE OLECMDEXECOPT_SHOWHELP 3 

*Constants for QueryStatusWB return values
#DEFINE OLECMDF_SUPPORTED 1 &&Command is supported by this object.
#DEFINE OLECMDF_ENABLED 2 &&Command is available and enabled.
#DEFINE OLECMDF_LATCHED 4 &&Command is an on-off toggle and is currently on.
#DEFINE OLECMDF_NINCHED 8 &&Reserved for future use.

*Constants for ShowWindow second paramter
#DEFINE SW_NORMAL    1
#DEFINE SW_MAXIMIZE  3
#DEFINE SW_MINIMIZE  6

*Constants for SendMessage second parameter
#DEFINE WM_GETICON 0x7F
#DEFINE WM_SETICON 0x80

*Constants for SendMessage third parameter
#DEFINE ICON_SMALL 0
#DEFINE ICON_BIG 1

DECLARE Long FindWindow in Win32API String, String
DECLARE Long BringWindowToTop in Win32API Long
DECLARE Long ShowWindow in Win32API Long, Long
DECLARE INTEGER SetWindowText IN user32 INTEGER hWnd, STRING lpString 
DECLARE INTEGER ExtractIcon IN shell32 INTEGER hInst, STRING  lpszExeFileName, INTEGER lpiIcon 
DECLARE INTEGER SendMessage IN user32 INTEGER hWnd, INTEGER Msg, INTEGER wParam, INTEGER lParam 

Public oBrowser
Local sTempPath, lnHWND, lcTitle, lnIcon

PUSH Key

ON KEY LABEL ALT+X Cancel && Just in case we get stuck in Do Loop

CREATE CURSOR myCursor (name c(20),address c(20))
INSERT INTO myCursor (name, address) VALUES ("Mike","123")
INSERT INTO myCursor (name, address) VALUES ("Paul","321")
INSERT INTO myCursor (name, address) VALUES ("John","345")
INSERT INTO myCursor (name, address) VALUES ("Ringo","567")
INSERT INTO myCursor (name, address) VALUES ("Georges","987")
GO top
sTempPath = ADDBS(SYS(2023))
IF !FILE(sTempPath + "someSheet.htm")
    SET TEXTMERGE TO memvar lcHTML noshow
    SET TEXTMERGE on
    \\<HTML><BODY><TABLE>
    SCAN
     \<tr>
      FOr lnField = 1 to AFIELDS(laFields)
         \\<td><<EVALUATE(FIELD(m.lnField))>><td>
      ENDFOR
      \</tr>
    ENDSCAN
    \</table></body></html>
    SET TEXTMERGE OFF
    SET TEXTMERGE TO
    STRTOFILE(lcHTML,sTempPath + "someSheet.htm") 
ENDIF

oBrowser=CREATEOBJECT("internetexplorer.application")
oBrowser.navigate(sTempPath+"someSheet.htm")

DO WHILE oBrowser.QueryStatusWB(OLECMDID_PRINTPREVIEW) != (OLECMDF_SUPPORTED + OLECMDF_ENABLED)
    DOEVENTS
ENDDO
oBrowser.ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER)

lcTitle = "Print Preview"
lnHWND = 0
DO WHILE lnHWND = 0 &&Seems to take ExecWB a second to create the window so we wait
    DOEVENTS
    lnHWND = FindWindow(null,lcTitle)
enddo
lnIcon =    ExtractIcon (0,HOME()+"GRAPHICS\ICONS\WRITING\NOTE11.ICO",0)  && I am assuming this icon exists on your system
SetWindowText(lnHWND, "FISCAL STATISTICS REPORT")
SendMessage(lnHWND, WM_SETICON, ICON_SMALL, lnIcon)
*!* SendMessage(lnHWND, WM_SETICON, ICON_BIG, lnIcon)
BringWindowToTop(lnHWND)
ShowWindow(lnHWND, SW_MAXIMIZE)
CLEAR DLLS "FindWindow", "BringWindowToTop", "ShowWindow", "SetWindowText", "ExtractIcon", "SendMessage"
POP KEY All

A special thanks to Mike Lewis and slighthaze for the extra code.
Mike Gagnon
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top