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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hide other app within vfp

Status
Not open for further replies.

cdvalera

Programmer
Aug 5, 2008
6
EC
Hi experts.

I have an application that runs a c# exe within a vfp form.
At some point i would like to hide this c# app. How can i do this?

Thanks in advance...
Christian
 
Take a look at this FAQ:

Minimize All Windows (Show Desktop)
faq184-4263

You could probably modify it to minimize only your C# app.

Also, here's a portion of code you may be able to use to hide an app. No guarantee, but you can do some experimenting:
Code:
PARAMETERS p1, p2, p3, p4, p5
LOCAL laApp, lnHandle, lnCount, lcTitle, lnI, lnHFox

STORE '' TO cParms
IF PCOUNT() > 0
   FOR zzz = 1 TO PCOUNT()
      STORE 'p' + ALLTRIM(STR(zzz)) TO cparmx
      cParms = cParms + "'" + EVALUATE(cparmx) + "' "
   NEXT
ENDIF

DIMENSION laApp[1]
lnHFox=0

#DEFINE SW_HIDE             0
#DEFINE SW_SHOWNORMAL       1
#DEFINE SW_NORMAL           1
#DEFINE SW_SHOWMINIMIZED    2
#DEFINE SW_SHOWMAXIMIZED    3
#DEFINE SW_MAXIMIZE         3
#DEFINE SW_SHOWNOACTIVATE   4
#DEFINE SW_SHOW             5
#DEFINE SW_MINIMIZE         6
#DEFINE SW_SHOWMINNOACTIVE  7
#DEFINE SW_SHOWNA           8
#DEFINE SW_RESTORE          9
#DEFINE SW_SHOWDEFAULT      10
#DEFINE SW_FORCEMINIMIZE    11
#DEFINE SW_MAX              11

DECLARE INTEGER FindWindow ;
   IN win32api ;
   INTEGER nullpointer, ;
   STRING cwindow_name

DECLARE INTEGER GetWindow ;
   IN win32api ;
   INTEGER ncurr_window_handle, ;
   INTEGER ndirection

DECLARE INTEGER GetWindowText ;
   IN win32api ;
   INTEGER n_win_handle, ;
   STRING @ cwindow_title, ;
   INTEGER ntitle_length

DECLARE LONG BringWindowToTop IN Win32API LONG

DECLARE INTEGER GetCurrentThreadId;
   IN kernel32

DECLARE INTEGER GetWindowThreadProcessId IN user32;
   INTEGER   HWND,;
   INTEGER @ lpdwProcId

DECLARE INTEGER GetCurrentThreadId;
   IN kernel32

DECLARE INTEGER AttachThreadInput IN user32 ;
   INTEGER idAttach, ;
   INTEGER idAttachTo, ;
   INTEGER fAttach

DECLARE INTEGER GetForegroundWindow IN user32

DECLARE Long ShowWindow In Win32API Long, Long

DECLARE INTEGER ShellExecute IN shell32.DLL ;
   INTEGER hndWin, ;
   STRING cAction, ;
   STRING cFileName, ;
   STRING cParams, ;
   STRING cDir, ;
   INTEGER nShowWin

STORE .F. TO lFoundIt
lnHFox = FindWindow(0,_SCREEN.CAPTION)
lnHandle = lnHFox && GetWindow(lnHFox,0)
lnCount = 0

DO WHILE lnHandle > 0
   lcTitle=SPACE(255)
   lnI=GetWindowText(lnHandle, @lcTitle,LEN(lcTitle))
   IF lnI>0
      lcTitle=STRTRAN(TRIM(lcTitle),CHR(0),"")
   ELSE
      lcTitle=""
   ENDIF
   IF lnHandle > 0 .AND.  !EMPTY(lcTitle)
      IF 'YourAppName' $ lcTitle
         STORE lnHandle TO nYourAppHandle
         lFoundIt = .T.
      ENDIF
   ENDIF
   lnHandle = GetWindow(lnHandle,2)
ENDDO
IF lFoundIt
   =ForceHide(nYourAppHandle)
ENDIF

RETURN


FUNCTION ForceHide(lnHWND)

   LOCAL nForeThread, nAppThread

   nForeThread = GetWindowThreadProcessId(GetForegroundWindow(), 0)
   nAppThread = GetCurrentThreadId()

   IF nForeThread != nAppThread
      AttachThreadInput(nForeThread, nAppThread, .T.)
      BringWindowToTop(lnHWND)
      SHOWWINDOW(lnHWND, SW_SHOWMINIMIZED)
      AttachThreadInput(nForeThread, nAppThread, .F.)
   ELSE
      BringWindowToTop(lnHWND)
      SHOWWINDOW(lnHWND, SW_SHOWMINIMIZED)
   ENDIF

ENDFUNC


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Hi Christian,

You could do the following:

Code:
oWSH = CREATEOBJECT("wscript.shell")
oWSH.Run("MyApp.EXE", 0)

This will run MyApp invisibly. Of course, you need a way for the app to terminate itself, as the user will have no way of doing that.

Alternatively, if you just want to run the app minimised, as Dave suggested (as opposed to hiding it completely), use ShellExecute(), passing 1 as the last parameter.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thank you guys for yor help.
I´m going to try to experiment with all this possibilities and see how it goes.

Thank you again...
 
Do you have source code to the C# app? If so, you can modify and have lots of control using the Forms Interop Toolkit. The one from Microsoft is for VB, but there are others for C# if you search for them. There's an article on my web site that shows how to use the one from Microsoft.

Craig Berntson
MCSD, Visual FoxPro MVP,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top