KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Proper method for launching an app

 
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic
View previous topic :: View next topic  
Author Message
gbarnas
KiXforms Regular
KiXforms Regular


Joined: 07 Mar 2003
Posts: 41
Location: Mahwah, NJ

PostPosted: Thu Jan 03, 2008 9:36 pm    Post subject: Proper method for launching an app Reply with quote

I'm trying to launch IE with some HTML. I have no problem instantiating IE and passing the data. However...

I have associated .KXW files to WKIX32.exe /I %1. When I launch my script (with a .kxw extension) it launches without a console window. I run the command and IE appears with the correct data, but it appears behind the command window where I launched my script from. If I launch the script from Explorer, the script is in the foreground (as usual) but when IE loads, it moves behind Explorer. Bottom line the IE window moves behind the window that launched the script. I'm probably missing something fundamental, but I sure can't see what it is.

Here's some snippets of the code where I'm having problems. It illustrates how I'm defining KF, running the Execute, and the function that launches and loads IE.

Thanks!,

Glenn
Code:

; create the form
$System = CreateObject("Kixtart.System")
$frmMain = $System.Form()

; define the form fields - code omitted

; run the form
$frmMain.Show
While $frmMain.Visible
 $Exec = Execute($System.Application.DoEvents)
Loop


; There's lots of code that follows, but basically, I define a single, large
; $txtHTML field, call the File-Open, read the html file,
; and load it into the $txtHTML.Text field. When the load is complete, I call
; the DoPreview() shown below

Function DoPreview()

  Dim $_objIE      ; IE Application object pointer
  Dim $_Doc      ; document reference

  ; Instantiate IE without any navigation options
  $_objIE = createobject("internetexplorer.application")
  $_objIE.Addressbar   = 0
  $_objIE.Menubar   = 0
  $_objIE.Toolbar   = 0
  $_objIE.Statusbar   = 0
  $_objIE.Navigate("about:blank")

; copy the HTML from the text field to IE
  $_Doc = $_objIE.document
  $_Doc.Write('<html><head><title>Document Preview</title></head>' + $txtHTML.Text + '</html>')
  ; Hide the main form until the preview window is closed.
  $frmMain.Hide
  While $_objIE.visible Sleep 0.08 Loop
  $frmMain.Show

EndFunction
Back to top
View user's profile Send private message Visit poster's website
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Fri Jan 04, 2008 12:16 am    Post subject: Reply with quote

By no means am I the expert around here but my thought would be...

While $_objIE.visible Sleep 0.08 Loop

is stealing the focus from IE.

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
gbarnas
KiXforms Regular
KiXforms Regular


Joined: 07 Mar 2003
Posts: 41
Location: Mahwah, NJ

PostPosted: Fri Jan 04, 2008 3:04 am    Post subject: Reply with quote

Well, if I don't do the $frmMain.Hide, the explorer window appears under the active form window. In fact, it still does until the Hide happens. I added the While loop to let the form stay hidden while the explorer window was open. Once it closes, it no longer has focus, and the loop ends, triggering the $frmMain.Show.

The problem isn't that the IE window is behind the form window, it's that it is behind the application (CMD prompt or Explorer) that launched the KF app. ???

Prior to the Hide/Show, I also tried $objIE.TopMost, and other things to set focus to the IE window - all to no avail.

I'm also trying to use the RichText.HTML form object, but something's wacky with CRLFs, BRs, or Ps. I can't control the line breaks there as expected. That would be preferred, actually, as it keeps the preview in the same form window (just a different tab).

Glenn
Back to top
View user's profile Send private message Visit poster's website
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Fri Jan 04, 2008 3:25 am    Post subject: Reply with quote

Hi Glenn,

is this what you are looking for?
Code:

; create the form
$System = CreateObject("Kixtart.System")

$frmMain = $System.Form()

; define the form fields - code omitted

$Btn = $frmMain.Controls.Button()
$Btn.Center
$Btn.OnClick = "DoPreview()"
$Btn.Text = "Preview"

; run the form
$frmMain.Show

While $frmMain.Visible
; $Exec = Execute($System.Application.DoEvents())
 $Exec = Execute($System.DoEvents())
Loop

; There's lots of code that follows, but basically, I define a single, large
; $txtHTML field, call the File-Open, read the html file,
; and load it into the $txtHTML.Text field. When the load is complete, I call
; the DoPreview() shown below

Function DoPreview()

  Dim $_objIE      ; IE Application object pointer
  Dim $_Doc      ; document reference

  ; Instantiate IE without any navigation options
  $_objIE = CreateObject("internetexplorer.application")
  $_objIE.Addressbar   = 0
  $_objIE.Menubar   = 0
  $_objIE.Toolbar   = 0
  $_objIE.Statusbar   = 0
  $_objIE.Navigate("about:blank")

; copy the HTML from the text field to IE
  $_Doc = $_objIE.document
  $_Doc.Write('<html><head><title>Document Preview</title></head>' + "Bla, Bla, Bla" + '</html>')
 
  $_objIE.visible=1
 
  ; Hide the main form until the preview window is closed.
  $frmMain.Hide
  While $_objIE.visible Sleep 0.08 Loop
  $frmMain.Show

EndFunction

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
gbarnas
KiXforms Regular
KiXforms Regular


Joined: 07 Mar 2003
Posts: 41
Location: Mahwah, NJ

PostPosted: Fri Jan 04, 2008 3:52 am    Post subject: Reply with quote

OK - figured out the RichText.HTML issue -
I'm trying to load some text that's preformatted. Lines of text in CW font (courier) that has spaces to allow the columns to line up. It starts with a "pre" tag, which the RichText.HTML doesn't support. I tried changing the spaces to non-breaking space tags, but it doesn't support those either. (Grrr!)
Any ideas?

Glenn
Back to top
View user's profile Send private message Visit poster's website
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Fri Jan 04, 2008 9:13 am    Post subject: Reply with quote

Tsk Tsk tsk ... PostPrep Previews...

Try stealing from my original Postprep posts (Should be available on korg)

Wink

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
gbarnas
KiXforms Regular
KiXforms Regular


Joined: 07 Mar 2003
Posts: 41
Location: Mahwah, NJ

PostPosted: Fri Jan 04, 2008 12:01 pm    Post subject: been there, stole that! Reply with quote

Jochen,

"tsk tsk" - indeed! Wink

I've been maintaining PostPrep since you guys gave up 3+ years ago, so it was the first place I looked to "recycle" code from. It's giving me the same problem, both in this project, and the PP version getting rewritten for the latest KF release. Did not seem to be a problem in the 41 release, that's why I thought it was something in how I was instantiating the form.

Glenn
Back to top
View user's profile Send private message Visit poster's website
gbarnas
KiXforms Regular
KiXforms Regular


Joined: 07 Mar 2003
Posts: 41
Location: Mahwah, NJ

PostPosted: Fri Jan 04, 2008 12:50 pm    Post subject: Solved! Reply with quote

"WindowState" was the solution - minimizing the KF app instead of hiding it allowed the IE application to remain in front and prevented the app that launched the KF window from raising to the top. Minimizing the IE window does not raise the KF app, but closing IE does. If I want to raise the KF app if IE is minimized, I'd have to monitor the Focus attribute of the IE app instead of the Visible attribute.

Glenn

Code:

; display a preview window
Function OnPreviewClick()

  Dim $_objIE               ; IE Application object pointer
  Dim $_Doc               ; document reference

  ; Instantiate IE without any navigation options
  $_objIE = createobject("internetexplorer.application")
  $_objIE.Addressbar   = 0
  $_objIE.Menubar   = 0
  $_objIE.Toolbar   = 0
  $_objIE.Statusbar   = 0
  $_objIE.Navigate("about:blank")

  ; send data to the IE app and make it visible
  $_Doc = $_objIE.document
  $_Doc.Write('<html><head><title>Document Preview</title></head>' + $txtHTML.Text + '</html>')
  $_objIE.Visible   = 1

  ; minimize the KF app while IE is active - restore KF app after IE closes
  $frmMain.WindowState   = 1
  While $_objIE.visible Sleep 0.08 Loop
  $frmMain.WindowState   = 0

EndFunction
Back to top
View user's profile Send private message Visit poster's website
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Fri Jan 04, 2008 1:16 pm    Post subject: Reply with quote

Fine,

glad your Issue is solved Smile

Back to 'Kixanoid' then (Yeah, I will not call it KixBreakOut, as this sounds lame)

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group