4 Replies - 1251 Views - Last Post: 31 May 2009 - 10:47 PM Rate Topic: -----

#1 dreambo8563  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-May 09

why the method didn't return after sendmessage

Posted 31 May 2009 - 06:56 PM

:crazy: I want to do the automation testing using win32 API. just have a try on it.

1. I create a method about select menu

[DllImport("user32.dll", EntryPoint = "GetMenu")]
		private static extern IntPtr GetMenu(IntPtr hWnd);

		[DllImport("user32.dll", EntryPoint = "GetSubMenu")]
		private static extern IntPtr GetSubMenu(IntPtr hMenu, int nPos);

		[DllImport("user32.dll", EntryPoint = "GetMenuItemID")]
		private static extern int GetMenuItemID(IntPtr hMenu, int nPos);

		[DllImport("user32.dll", EntryPoint = "SendMessage")]
		private static extern void SendMessage(IntPtr hWnd, uint Msg, int wParam, IntPtr lParam);

		public static void SelectMenu(IntPtr handleApplication, int mainIndex, int subIndex)
{
			IntPtr hMainMenu = GetMenu(handleApplication);
			IntPtr hTopItem = GetSubMenu(hMainMenu, mainIndex);
			int iSubItem = GetMenuItemID(hTopItem, subIndex);
			uint WM_COMMAND = 0x0111;
[color=red]	SendMessage(handleApplication, WM_COMMAND, iSubItem, IntPtr.Zero); [/color]
}





2. I want to invoke the method, I found that after the SendMessage(handleApplication, WM_COMMAND, iSubItem, IntPtr.Zero);
I can know it works form the UI. (I just manipulate the notepad.exe.)
The program is not finished.
Maybe it still works after that, but this is my last step.
What happend?

static void Main(string[] args)
		{
			#region MyRegion

			Process.Start("wordpad");

			Thread.Sleep(1000);

			#endregion
			
			#region Select Menu

			IntPtr WordPadClass = GetControls.MyFindWindow("WordPadClass", null);

			ControlEvent.SelectMenu(WordPadClass, 0, 1);

			#endregion
		}



Is This A Good Question/Topic? 0
  • +

Replies To: why the method didn't return after sendmessage

#2 bsaunders  Icon User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: why the method didn't return after sendmessage

Posted 31 May 2009 - 08:26 PM

Did you know SendMessage doesn't return until the message sent has been processed by the destination window procedure?
Was This Post Helpful? 0
  • +
  • -

#3 dreambo8563  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-May 09

Re: why the method didn't return after sendmessage

Posted 31 May 2009 - 09:45 PM

View Postbsaunders, on 31 May, 2009 - 07:26 PM, said:

Did you know SendMessage doesn't return until the message sent has been processed by the destination window procedure?



:) Thanks for your reply.
Yes, I know it.
How to judge the time?
I wait for more than 1 min....
Was This Post Helpful? 0
  • +
  • -

#4 bsaunders  Icon User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: why the method didn't return after sendmessage

Posted 31 May 2009 - 10:29 PM

Does it work if you use PostMessage instead?
Was This Post Helpful? 0
  • +
  • -

#5 dreambo8563  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-May 09

Re: why the method didn't return after sendmessage

Posted 31 May 2009 - 10:47 PM

View Postbsaunders, on 31 May, 2009 - 09:29 PM, said:

Does it work if you use PostMessage instead?



I have tried with the postmessage.
it works too.

what's the difference time for sendmessage and postmessage???

I found that when'click' btn, we usually use postmessage, right?

I found sth.
Because I manipulate the wordpad, I select the 'Open...' item, the open dialog is a mode-window.....
after select one file or close the dialog manually, the program will finish.

Is it the root reason?? --mode window?

This post has been edited by dreambo8563: 31 May 2009 - 10:57 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1