Page 2 of 3

Posted: Thu Dec 16, 2004 12:00 am
by TerryHough

Code: Select all

If OpenWindow(1,300,400,400,100,#PB_Window_SystemMenu,"AppThatClosesTheOther")
  CreateGadgetList(WindowID())
  ButtonGadget(0,10,10,100,25,"Close other")
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_Event_Gadget
      PostMessage_(FindWindow_(0,"AppToBeClosed"),#WM_CLOSE,0,0)
    EndIf
  Until ev=#PB_Event_CloseWindow
EndIf
@PB

Found myself needing something similar today. Is there any way to
force a DOS Window to close automatically? Your routine tries to
close a DOS window but Windows prompts for a user reply to force the
close on the DOS window. Maybe there is a way to force the whole thing?

Terry

Posted: Thu Dec 16, 2004 2:14 pm
by cecilcheah
Anyone can answer my question?

Hi there

The 2 easy questions are resolved. Thanks for the help.

However after downloading the ownGadget_Example.pb, i run into an error when compiling the example.

Code: Select all

Procedure paint(gadget) 
  GetWindowRect_(gadget,rc.rect) 
  x=GetGadgetItemState(0,#OG_HPosition) 
  y=GetGadgetItemState(0,#OG_VPosition) 
  DrawingMode(0) 
  Box(0,0,rc\right,rc\bottom,RGB(255,0,100)) 
  LineXY(0,y,rc\right,y,RGB(0,255,0)) 
  LineXY(x,0,x,rc\bottom,RGB(0,255,0)) 
EndProcedure 



Error: Constant not found: #OG_HPosition

What is the constant value for #OG_HPosition?

Cecil[/code]

Posted: Thu Dec 16, 2004 3:12 pm
by TerryHough
@Cecil

I wasn't familiar with this library, so I just downloaded, unzipped, and
installed it. Seems the example compiles and work fine on PB v3.92.

Perhaps you didn't get the library installed correctly.

The file OWNGADGET should be placed in the
\purebasic\purelibraries\userlibraries folder

The file OWNGADGET.res should be placed in the
\purebasic\residents folder.

Then restart PB and try the example. Works for me.

Terry

Posted: Thu Dec 16, 2004 3:20 pm
by cecilcheah
That is it, thanks

Your quiestion: Can you not use KillWindowProcess to close the dos prompt?

Cecil

Posted: Thu Dec 16, 2004 4:02 pm
by GedB
cecil,

Did you copy OwnGadget into purebasic\PureLibraries\UserLibraries and OwnGadget.RES into purebasic\Residents?

Posted: Thu Dec 16, 2004 6:23 pm
by cecilcheah
Yes, i did copy them to the folders, but it is still giving me the error, the same error.

??

Cecil

Posted: Thu Dec 16, 2004 7:43 pm
by PB
> Windows prompts for a user reply to force the close on the DOS window

There is no such prompt on Windows XP -- the DOS window just closes as
expected. Which version of Windows are you running?

> Maybe there is a way to force the whole thing?

Two things I can think of:

(1) Send a keystroke to confirm the prompt, eg. if the prompt requires a Yes
response then send a Y keystroke when the prompt appears. Messy. :)

(2) Terminate the DOS window process, as mentioned by Cecil.

Posted: Thu Dec 16, 2004 7:53 pm
by cecilcheah
yes, just try it with some code. MS Dos window close with WM_Close with no problem and no prompt.

Do you want some code?

Cecil

Posted: Thu Dec 16, 2004 10:59 pm
by GedB
Works OK here.

It looks like the problem is with the residency file. Don't know whats going wrong.

Try adding the following at the top, so you can at least get an idea of what it does.

Code: Select all

#OG_HPosition = 9
#OG_VPosition = 4

Posted: Thu Dec 16, 2004 11:25 pm
by TerryHough
PB wrote:> Windows prompts for a user reply to force the close on the DOS window

There is no such prompt on Windows XP -- the DOS window just closes as
expected. Which version of Windows are you running?
@PB

Win98SE - don't be mad at me, I am forced to live with it for important reasons.

@cecilcheah
Yes, I would love to see your code. If you know it works with DOS windows on Win98SE, that is even better. Or I can just try it.

Thanks everyone,
Terry

Posted: Sat Dec 18, 2004 8:56 am
by cecilcheah
Hi there

Here is the code. Be careful, it will close all DOS Window. So maybe you have to look for Window Text with "MS Dos Prompt" to close the right DOS window.

Code: Select all

window = OpenWindow (0, 0, 0, 320, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Close all DOS window") 
If CreateGadgetList(WindowID()) 
   ButtonGadget(1, 50,30, 128,22,"Close DOS") 
    

 Repeat 
   event=WaitWindowEvent() 
      Select EventGadgetID() 
        Case 1;Post Message 
            hWnd = FindWindow_(0, "MS-Dos Prompt")
            PostMessage_(hWnd ,#wm_close,0,0)   
      EndSelect 
Until event=#pb_event_Closewindow 

Endif
Someone may help you more here.

Cecil

Posted: Sat Dec 18, 2004 5:04 pm
by TerryHough
cecilcheah wrote:Here is the code. Be careful, it will close all DOS Window. So maybe you have to look for Window Text with "MS Dos Prompt" to close the right DOS window.

Cecil
Thanks Cecil. You code is very similar to that posted above. And they
both work to close a "MS-DOS Prompt" job on WinXP and Win98SE. But
if DOS box is actually running a program, Win98SE responds differently
from WinXP.

If that "MS-DOS Prompt" is actually running some sort of DOS program
then it does not work under Win98SE. It does attempt to close the
MS-DOS job, but then Windows gives you a message saying something
like this one.

Code: Select all

PostMessage_(FindWindow_(0,"MS-DOS Prompt - Main"),#WM_CLOSE,0,0) 
results in

Image

I can't find a way to pass that message box a Y to force the close.

Oddly, WinXP does this differently since it never shows the MS-DOS Prompt - part of the job name. The command there is

Code: Select all

PostMessage_(FindWindow_(0,"Main"),#WM_CLOSE,0,0) 
and it successfully closes the job.

So, I am still searching. Thanks for your help.

Terry

Posted: Sun Dec 19, 2004 12:43 am
by PB
> I can't find a way to pass that message box a Y to force the close

This works (when the message box has the focus):

Code: Select all

keybd_event_(#VK_Y,0,0,0) : keybd_event_(#VK_Y,0,#KEYEVENTF_KEYUP,0)
Is there a DOS app that comes native with Win98 that I can run and test?
I'll find a way for you to do it, but I need a DOS app to run under Win98.

Posted: Sun Dec 19, 2004 6:38 am
by cecilcheah
Can we try to ping an IP address, when it is still running, you can test it?

I am still having problems with the Own Gadget application. I put the constants in as written, now it says the structure does not exist.

Code: Select all


If CreateGadgetList(WindowID())
 owngadget\.owngadgetstruct
 owngadget\name="TEST"
 owngadget\vmin=0
 owngadget\vmax=191
 owngadget\vpage=10
 owngadget\vpos=95
 owngadget\hmin=0
 owngadget\hmax=191
 owngadget\hpage=10
 owngadget\hpos=95
 owngadget\PaintProc=@paint()
 ;owngadget\Size=@size()
 ;owngadget\HScrollProc=@hscroll()
 ;owngadget\VScrollProc=@vscroll()
 owngadget\MouseProc=@mouse()
 owngadget\posawaremouse=#True
 owngadget\backcolor=RGB(255,0,100)
 owngadget\cursor=0;#IDC_SIZEALL
Error:
Structure not found: .owngadgetstruct
I thought the structure should be owngadget, not owngadgetstruct?

When i replace .owngadgetstruct with \owngadgetstruct

another error:
The variable does not have a 'Strucutre'
With this line marked:
owngadget\.owngadgetstruct

Also, when i install the IE Tool, install runs ok. But when i try to click the Pure Basic button in IE Explorer, i got this error:
can't find 'confid.dat'
???

Cecil[/code]

Posted: Sun Dec 19, 2004 12:10 pm
by GedB
cecil,

the structure looks like this:

Code: Select all

Structure owngadgetstruct
  name.s
  backcolor.l
  cursor.l
  flags.l
  hmin.l
  hmax.l
  hpage.l
  hpos.l
  vmin.l
  vmax.l
  vpage.l
  vpos.l
  hscrollproc.l
  vscrollproc.l
  sizeproc.l
  PaintProc.l
  MouseProc.l
  posawaremouse.l
EndStructure
You really need to look into why the compiler isn't picking up the OwnGadget.res.