|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Mon Apr 21, 2014 12:07 pm Post subject: External Program Launching from Within CLEARWIN |
|
|
Is it possible to launch an external program (e.g. Windows Paint) directly from within CLEARWIN and open a file with it under CLEARWIN command (i.e. via a button or menu ) ? |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7916 Location: Salford, UK
|
Posted: Mon Apr 21, 2014 12:22 pm Post subject: |
|
|
Yes. Possible calls are start_process@, start_pprocess@ or the Windows API WinExec. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Mon Apr 21, 2014 12:27 pm Post subject: |
|
|
Gere's a callback function for launching Notepad with START_PPROCESS@. Paint is similar.
Code: | INTEGER FUNCTION Launch1_FN()
C -------------------------------
C
C Launch Notepad as file editor
C
C -----------------------------------------------------------------
INTEGER START_PPROCESS@
IA = START_PPROCESS@('Notepad.EXE',' ')
IF (IA .NE. 0) CALL POP('Failed to start Notepad')
Launch1_FN = 1
END |
POP is my routine (not part of CW) to display the error message in a pop-up box, with a standard warning symbol).
Eddie |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7916 Location: Salford, UK
|
Posted: Mon Apr 21, 2014 1:52 pm Post subject: |
|
|
The callback Launch1_FN should probably return 2 rather than 1. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Mon Apr 21, 2014 2:56 pm Post subject: |
|
|
Hi Paul,
Yes, I did think about that when I posted it as I vaguely remember something in a previous post, but 1 seems to work fine.
I'm almost self-taught, and lots of the documentation states that returning 1 is fine. For example, if I search in FTN95.CHM for 'WINIO@' I get an example where the callbacks return 1. If I look in CWPLUS.ENH, then the callbacks return 1 in para 31, para 55, and several other places
To be honest, I don't understand para 90 in CWPLUS.ENH and from then on, I read of callbacks returning all sorts of numbers.
A lot of the Clearwin+ standard functions appear to return either 0 or 1.
Do you think it would be possible to clarify this by explaining why 2 is preferable to 1, and indeed, what other valid callback return values there are from user-supplied callback functions please?
Eddie |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7916 Location: Salford, UK
|
Posted: Mon Apr 21, 2014 3:38 pm Post subject: |
|
|
A return value of zero closes the main window.
A return value of 1 updates the screen for when a displayed value is changed.
A return value of 2 does nothing.
Higher values are sometimes used for specific format codes (e.g. %mg). |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Mon Apr 21, 2014 6:32 pm Post subject: |
|
|
Hi Paul,
Many thanks for the clarification. In this case my window is so simple that a screen refresh doesn't matter. It's also a callback from a menu item, and the menu springs back anyway. I can see the point if the callback was attached to a button or an icon.
But I will think as to whether 1 or 2 is more appropriate in future.
Eddie |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Mon Apr 21, 2014 7:17 pm Post subject: |
|
|
That all seems straight forward.
If I wanted to open a file directly on opening the program I assume that I would include the filename in the PARAMS list thus for example:
IA = START_PPROCESS@('Notepad.EXE','test.txt ') ?
Also Eddie, I note that in your code you have
IF (IA .NE. 0) CALL POP('Failed to start Notepad')
but the manual says -
"Return value
Returns 0 or a positive value if successful. A return value of -1 indicates an error condition"
so shouldn't your error test be:
IF (IA .EQ. -1) ..... etc ? |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Tue Apr 22, 2014 10:49 am Post subject: |
|
|
Probably. It seems to work as I wrote it. Maybe you could run some tests.
I didn't include POP because my recollection was that it was fairly obvious, but on looking, I saw that it contained some fancy stuff, so that when it pops up, it goes to the same place it was 'parked' by the user last time it was invoked. I have several classes of window that remember where they were last left - potentially 80 of them although I don't use all 80, and this is type 75. However, there is a problem with multiple windows remembering their settings the way I coded it. I call this 'if a popup meets a popup coming through the rye' and no doubt someone smarter than me could untangle it, but I got it working by saving the window handles as in the attached code. Plus, the last position is saved by the callback for the %cc closure control (which is probably where my procedures get confused) and I've added this too. It contains checks so that the next time a popup is displayed it will be somewhere visible on the screen - but this is crudely done.
Initial popup coordinates need to be set somewhere, and the monitor resolution somewhere else before the first time this is used.
Code: | SUBROUTINE POP(TEXT)
C --------------------
C Pops up the text message sent as a parameter with an "Oops"
C caption, denoting some sort of error. The box will pop up where
C the previous POP or POPOK box was.
C -----------------------------------------------------------------
INCLUDE <WINDOWS.INS>
INTEGER, EXTERNAL :: GET_POSITION_FN
CHARACTER*(*) TEXT
COMMON/STICKY_PLACE/ IWINDPOS_X(80), IWINDPOS_Y(80), NPOS, KHAND
NSAVE = NPOS
KSAVE = KHAND
NPOS = 75 ! POP warning/info boxes are window type 75 for me
IA=WINIO@('%ca[Oops!]&')
IA=WINIO@('%bg[white]&')
IA=WINIO@('%sp&', IWINDPOS_X(NPOS), IWINDPOS_Y(NPOS))
IA=WINIO@('%hw%cc&', KHAND, GET_POSITION_FN)
CALL SET_FONT_AND_APPEARANCE ! Clearwin code here ...
IA=WINIO@('%cn%si!'//TEXT//'&')
IA=WINIO@('%2nl%cn%`7bt[OK]')
KHAND = KSAVE
NPOS = NSAVE
RETURN
END
INTEGER FUNCTION GET_POSITION_FN()
C ----------------------------------
C .. called on closure control %cc of a sticky window to get final
C position, so window can be restored there when next opened.
C -----------------------------------------------------------------
INCLUDE <WINDOWS.INS>
COMMON/STICKY_PLACE/ IWINDPOS_X(80), IWINDPOS_Y(80), NPOS, KHAND
COMMON/SCREEN_SIZE/ IXSCRN, IYSCRN
CALL GET_WINDOW_LOCATION@ (KHAND, IX, IY, IWID, IHT)
IF (NPOS .GT. 0 .AND. NPOS .LE. 80) THEN
IF (IX .GE. 1 .AND. IX .LE. IXSCRN-100) THEN
IWINDPOS_X(NPOS) = IX; ELSE
IWINDPOS_X(NPOS) = 100; ENDIF
IF (IY .GE. 1 .AND. IY .LE. IYSCRN-100) THEN
IWINDPOS_Y(NPOS) = IY; ELSE
IWINDPOS_Y(NPOS) = 100; ENDIF
ENDIF
GET_POSITION_FN = 0 ! Guarantees continue to exit
RETURN
END |
|
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2813 Location: South Pole, Antarctica
|
Posted: Tue Apr 22, 2014 12:26 pm Post subject: |
|
|
Thanks for sharing another nice trick, Eddie. |
|
Back to top |
|
|
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
|