April 26, 2024, 11:43:36 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Calling Notepad

Started by Brian, July 22, 2017, 04:22:01 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

Hi,

I'm calling Notepad to edit a file from within a program, and after Notepad has closed I want to run some code, but only AFTER Notepad has closed the file. Any (simple) ideas?

Brian

Andy

July 22, 2017, 07:03:00 AM #1 Last Edit: July 22, 2017, 07:04:45 AM by Andy
In my Alternative task manager program (user offerings section) there is a sub routine that lists the running applications and the title of the window.

With notepad running, and looking at a file called 1.txt, it shows en entry like this:

1.txt - Notepad.

The sub routine is called Applications, and enumapps lists them - you could always use this to detect if notepad is running, and since you know the file name, the rest should be easy.

Here is the link to taskman.iwb
http://www.ionicwind.com/forums/index.php?topic=5422.msg40373#msg40373

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

The following sample opens notepad when a button is pressed and while notepad is open the parent window is non responsive until you close notepad (try the but or to close the parent while notepad is open)

You could hide the parent while notepad is open or change the window color or minimize it or whatever.  Just do it at the beginning of the sub and undo it at the end of the sub.

$INCLUDE "WINDOWSSDK.inc"
type SHELLEXECUTEINFO,4
   def cbSize:int
   def fMask:int
   def hwnd:int
   def lpVerb:pointer
   def lpFile:pointer
   def lpParameters:pointer
   def lpDirectory:pointer
   def nShow:int
   def hInstApp:int
   def lpIDList:int
   def lpClass:pointer
   def hkeyClass:INT
   def dwHotKey:int
   def hIcon:int
   def hProcess:int
endtype
CONST WAITTIMEOUT = 258
CONST SEE_MASK_NOCLOSEPROCESS = 0x40
WINDOW win

ENUM win_const
win_SYSBUTTON1 = 100
win_SYSBUTTON2
win_SYSBUTTON3
ENDENUM

OpenWindow win,0,0,408,327,@SIZE|@MINBOX|@MAXBOX|@CAPTION|@SYSMENU,0,"Form1",&win_handler
CONTROL win,@SysButton,"NotePad",30,25,60,25,0,win_SYSBUTTON1
CONTROL win,@SysButton,"Active Test",139,28,100,25,0,win_SYSBUTTON2
CONTROL win,@SysButton,"Close",324,257,60,25,0,win_SYSBUTTON3

WAITUNTIL ISWINDOWCLOSED(win)
END

SUB win_handler(), INT
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW win
/* Initialize any controls here */
CASE @IDCONTROL
SELECT @CONTROLID
CASE win_SYSBUTTON1
IF @NOTIFYCODE = 0
OpenNotePad()
ENDIF
CASE win_SYSBUTTON2
IF @NOTIFYCODE = 0
Messagebox(win,"Just to see if main window is active","Test Message",0)
ENDIF
CASE win_SYSBUTTON3
IF @NOTIFYCODE = 0
CLOSEWINDOW win
ENDIF
ENDSELECT
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
ENDSELECT
RETURN 0
END SUB

sub OpenNotePad()
ISTRING filename[261]
STRING filter
istring str1[1000]=""
def info:SHELLEXECUTEINFO
string itext$=""
'if filename<>""

info.cbSize = 15 * 4
info.fMask = SEE_MASK_NOCLOSEPROCESS
info.hwnd = 0
info.lpVerb = "Open"
info.nShow = @SWSHOW
info.hInstApp = 0
str1=filename
string f= "notepad.exe"
info.lpFile = f
info.lpParameters = str1
info.lpDirectory = itext$
ShellExecuteExA(info)
do
  int retxd2 = WaitForSingleObject(info.hprocess,0)
until retxd2 <> WAITTIMEOUT
'endif

return
endsub
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Larry,

Tried your code, thanks. I don't know what it has done to my settings, but all I got when I pressed the Notepad button was another Form1 window - no Notepad

So I went back to my program, and tried that, and instead of bringing the normal Notepad up, it shows your Form1 window

I can only get the proper Notepad if I Start > Windows Accessories > Notepad. You code has obviously written over a setting somewhere, forcing it to always show your Form1 program

Help!

Brian

Brian

Hi,

Well, changing my IWB call to notepad.exe from:

SYSTEM "notepad.exe",GETSTARTPATH+"bin\\sessions.ini"

to the full path of:

SYSTEM "c:\\windows\\system32\\notepad.exe",GETSTARTPATH+"bin\\sessions.ini"

has fixed the problem, but it worked OK before I tried Larry's code

Brian

Brian

Well, being an idiot doesn't help, does it? I called Larry's example notepad.iwb, and stuck the code in the same folder as my development program. And, of course, my program pulled up the nearest "notepad.exe" it could find, which was in the same folder. Duh!

Red faces all round - sorry, Larry!

Brian

LarryMc

you shouldn't call my program notepad.iwb anyway
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

I know now! Anyway, doing it properly works . . .