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

call windows media player in vfp

Status
Not open for further replies.

Johnweida

MIS
Apr 29, 2003
91
CN
Hi,

How to call Wmplayer.exe by API instead of using run/N command ? Thanks.

John Satellite
 


Code:
DECLARE INTEGER ShellExecute IN "Shell32.dll" ;
    INTEGER hwnd, ;
    STRING lpVerb, ;
    STRING lpFile, ;
    STRING lpParameters, ;
    STRING lpDirectory, ;
    LONG nShowCmd

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Dear Mike,

Thanks for your help. But would you show me the details about it ? I know few about API you know. Thank you.

John Satellite
 
Johnweida

Sorry,

Code:
DECLARE INTEGER ShellExecute IN shell32.dll ; 
  INTEGER hndWin, ; 
  STRING cAction, ; 
  STRING cFileName, ; 
  STRING cParams, ;  
  STRING cDir, ; 
  INTEGER nShowWin
cFileName = "c:\Program Files\Windows Media Player\Wmplayer.exe" 
cAction = "open" 
ShellExecute(0,cAction,cFileName,"","",1)

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Dear Mike,

Your code is wonderful ! Thanks a lot !!!

John Satellite
 
Dear Mike,

Would you tell me how to shutdown the wmplayer.exe when it is running by API? Thanks.

John Satellite
 
Johnwieda

I'm not sure I understand your question. When I use the above suggested code, in XP it brings up the Windows Media Player, do you need to shutdown automatically after a certain period? Isn't the "X" in the corner present?

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Dear Mike,

Yes! It is I want to do. (to shutdown automatically after a certain period by API code. Not the "X" in the corner present).Please help me ! Thank you very much.

John Satellite
 
John

In concept, my suggestion would be to:
[ol][li] start the player[/li]
[li]Use a timer to determine the time left before closing[/li]
[li]Use another API call to detect the process running[/li]
[li] Kill the process[/li]

But I have a feelling this isn't what you want. Are you playing a .wav file or a .mov file?

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Dear Mike,

In fact. I have used your wonderful code to start Windows Media Player in an OA system programmed by myself and I want to close WMPlayer.exe by code when I close the OA system at the same time. It will be well done by API code I think, isn't it? Please help me. Hope you can understand me.(you sent me the code to start WMP, I hope that you can send me API code to close WMP) Thanks a lot.

John Satellite
 
John

Here is a link that might help you complete the task:
[ignore][/ignore].
Unfortunately I do not have your complete solution, so of the programming work will have to come from you. ;-)

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Dear Mike,

My meaning is to Close other applications such as Windows Media Player from within VFP app. I'm sure that you can help me. Please give me a kindly help,it is very urgent for me.

John Satellite


 
Hi John,

The following code closes Windows Media Player:

Code:
#DEFINE WM_SYSCOMMAND   0x112
#DEFINE SC_CLOSE        0xF060

DECLARE INTEGER FindWindow IN user32;
	INTEGER lpClassName, STRING lpWindowName

DECLARE SHORT PostMessage IN user32;
	INTEGER hWnd, INTEGER Msg, INTEGER wParam,;
	INTEGER lParam

LOCAL hWindow

hWindow = FindWindow(0, "Windows Media Player")

IF hWindow <> 0
	= PostMessage(hWindow, WM_SYSCOMMAND, SC_CLOSE, 0)
ENDIF
This is how it works:

The FindWindow API function returns a handle to the Media Player's window. This function uses Media Player's title as a parameter. Usually the title is &quot;Windows Media Player&quot;. If the Media Player is inactive or its title is different, the FindWindow returns zero.

Another API function, PostMessage, uses this handle to send a message to the Media Player's window. The second and third parameters with the PostMessage form a request to this application to close. Properly written Windows application responds to this request by closing itself.
 
Mr.tek2tips,

I tried your code. It close WMPlayer.exe immediately.But how can I close Wordpad with API code? Please help me. Thank you very much.

John Satellite
 
John

But how can I close Wordpad with API code?

How does this question relate to your original question?

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
You'll need to look at all the open windows for one that has &quot; - WordPad&quot; in the title bar.

We use this routine to look for other instances of our application already running. (We always start the window title with a consistant name, but most of it may be different.) You could alter this to find any text in any window caption (along with some additional changes).
Code:
** SAMPLE Use **
IF !FINDTITL(&quot;MyAppWindowTitle&quot;, .F., .T.)
    * fire up the external app
ENDIF
* ....

** FINDTITL.PRG
PARAMETERS zcTitle, zlExact, zlUpper

** Checks to see if the Title sent in (zcTitle) matches the title
**  of any active desktop window.
** The second parameter (zlExact) tells us to check the
**  beginning of the title for an exact match or check
**  anywhere in the title for zcTitle.
**  zcTitle is CASE SENSITIVE unless zlUpper is .T.

** If the title is found then that window is brought forward
** and .T. is returned.

IF TYPE(&quot;ZCTITLE&quot;) != &quot;C&quot; OR TYPE(&quot;ZLEXACT&quot;) != &quot;L&quot; ;
    OR TYPE(&quot;ZLUPPER&quot;) !=&quot;L&quot;
 ** Bad parameter(s).
 RETURN .F.
ENDIF

IF zlUpper
 zcTitle = UPPER(zcTitle)
ENDIF

#DEFINE GW_HWNDNEXT              2
#DEFINE GW_CHILD                 5
#DEFINE SW_RESTORE               9

DECLARE INTEGER GetWindow IN USER32 INTEGER, INTEGER
DECLARE INTEGER GetDesktopWindow IN USER32
DECLARE INTEGER GetWindowText IN USER32 INTEGER, STRING @, INTEGER
DECLARE INTEGER IsIconic IN USER32 INTEGER
DECLARE INTEGER SetActiveWindow IN USER32 INTEGER
DECLARE INTEGER ShowWindow IN USER32 INTEGER, INTEGER

PRIVATE qnHwnd, qlReturn
qlReturn = .F.
** Get the handle of the first window on the Desktop.
qnHwnd = GetWindow(GetDesktopWindow(), GW_CHILD)

** Loop through all active windows.
DO WHILE qnHwnd > 0

 PRIVATE qcTitle, qnLen
 qcTitle = REPL(CHR(0), 128)
 qnLen = GetWindowText(qnHwnd, @qcTitle, 128)
 qnLen = MIN(qnLen, 128)
 qcTitle = SUBSTR(qcTitle, 1, qnLen)
 IF zlUpper
  qcTitle = UPPER(qcTitle)
 ENDIF
 IF ! EMPTY(qcTitle)
  IF zlExact AND zcTitle == SUBSTR(qcTitle, 1, LEN(zcTitle))
   qlReturn = .T.
   EXIT
  ENDIF
  IF ! zlExact AND zcTitle $ qcTitle
   qlReturn = .T.
   EXIT
  ENDIF
 ENDIF

 ** Get the next window handle.
 qnHwnd = GetWindow(qnHwnd, GW_HWNDNEXT)

ENDDO
IF qlReturn
 ** Attempt to bring the found window forward.
 IF IsIconic(qnHwnd) > 0
  =ShowWindow(qnHwnd, SW_RESTORE)
 ENDIF
 =SetActiveWindow(qnHwnd)
ENDIF

RETURN qlReturn
* ----
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top