Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 3rd, 2004, 07:22 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default My application is hung when I send WM_COMMAND

Hello everybody,
I want to work on Media Player through Win API,
suppose Media Player! is open and playing a music
now for example I want to do this... selecting File menu then Properties ...
when I do that,Properties window will open
now I want to implement it in my application exactly
I did as below(with help of this link http://www.codeproject.com/csharp/wmp_pinvoke.asp)
this is my code
Code:
 
public const int WM_COMMAND = 0x111;//declared in Form1 class 
[DllImport("User32.dll")] 
public static extern int SendMessage( 
nt hWnd, // handle to destination window 
int Msg, // message 
int wParam, // first message parameter 
int lParam // second message parameter 
); 
private void button1_Click(object sender, System.EventArgs e) 
{ 
//retrieve the handle of Media Player 
int hwnd=Form1.FindWindow(null,"Windows Media Player"); 
//send the command for showing the Properties window in Media Player 
Form1.SendMessage(hwnd, Form1.WM_COMMAND,0x0000495b,0x00000000); 
//I figured out these numbers by Spy++
/* 
in above line my program is hung(it doesnt respond)although if in Properties window of Media Player I click 
a button(like Cancel)my program again works correctly 
every code I put here is not compiled for example I cant find the handle of Properties Window 
*/ 

int hwndOfPropertiesWindow=Form1.FindWindow(null,"Properties"); //this line doesnt work because my applicaytion is hung. 

}
Hope someone could help me.

--------------------------------------------
Mehdi.:)
__________________
_____________
<font color=\"teal\"><font size=\"1\"><b>Mehdi.
software student.</b></font id=\"size1\"></font id=\"teal\">
 
Old October 4th, 2004, 03:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

What are you trying to do.
 
Old October 4th, 2004, 01:05 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,
Thanks for your checking,
I just want my application to open Properties Window in MediaPlayer correctly,
(I mean,selecting File menu--->clicking Properties---->then Properties Window will open)
I get the handle of Media Player and then send WMP a WM_COMMAND message for opening Properties
Window(0x0000495b,I send this number as wParam,I got it when I open Properties Window manually by
Spy++)
but when I send WM_COMMAND to my application the Properties Window will open but my app is hung(it doesnt respond)and all lines
after sending WM_COMMAND doesnt not run,
(because,I think SendMessage could not return any value to my application...)

--------------------------------------------
Mehdi.:)
 
Old October 5th, 2004, 02:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

You are right, and thats because media Player's Property dialog is a model dialog.
 
Old October 6th, 2004, 03:58 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thank you very much you are right,its a dialog window
I used PostMessage instead of SendMessage,and my application is
not hung anymore,
Code:
public const int WM_COMMAND = 0x111;
[DllImport("User32.dll")]
publicstaticexternbool PostMessage(
int hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
privatevoid button1_Click(object sender, System.EventArgs e)
{
//retrive the handle of Media Player
int hwnd=Form1.FindWindow(null,"Windows Media Player");
//show the Properties Window(a modal dialog window)
Form1.PostMessage(hwnd, Form1.WM_COMMAND,0x0000495b,0x00000000);
//retriving the Handle of the Properties Window
textBox1.Text=Form1.FindWindow(null,"Properties").ToString();
//but in above line I recieve zero(that means it cant find the dialog window)
}
if I could find the handle of Properties Window after its opening,
there will be no problem anymore,
I tried this EnumChildWindows functions but I didnt get any result.
(it seems such functions cant find Properties Window)
I dont know exactly what I can do in this point
Thanks for your help.

--------------------------------------------
Mehdi.:)
 
Old October 6th, 2004, 05:43 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,
I figured out,
I used FindWindow in a loop for checking a no NULL handle several times,
and once returned, I verified it whether could be valid...
Code:
privatevoid button1_Click(object sender, System.EventArgs e)
{
Form1.PostMessage(hwnd, Form1.WM_COMMAND,0x0000495b,0x00000000);
int r=Form1.FindWindow(null,"Properties");
while((r==0) || (r==null))
r=Form1.FindWindow(null,"Properties");
textBox1.Text=r.ToString();
}
--------------------------------------------
Mehdi.:)




Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to send Email using Uploaded Application hellowahab .NET Framework 1.x 2 February 1st, 2007 05:08 AM
send email desktop application vipinpaliwal1980 VB.NET 2002/2003 Basics 0 April 19th, 2006 10:54 PM
Create a Report on my web application and send to marvz ASP.NET 1.x and 2.0 Application Design 0 July 7th, 2005 12:31 AM
How to send an email within a forms application xuqiong VS.NET 2002/2003 1 July 22nd, 2003 01:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.