3
Answers

Postmessage API seem to success but do nothing

Juncheng Zhang

Juncheng Zhang

14y
8.3k
1

I am developing an application that call another application in the same machine, I use Windows API
PostMessage() method,
the code seems return true, but the receive application has no response. Anyone can help, I really appreciated.
the following is the code:
public void CallPPICApp()
{
try
{

#region
try block
IntPtr hwnd_main = new IntPtr(0);
IntPtr hwnd_btn = new IntPtr(0);
const int BtnClick = 0x00F5;
string btnHandl = "WindowsForms10.BUTTON.app.0.378734a";
bool bwinFound = false;
hwnd_main = FindWindow(
"WindowsForms10.Window.8.app.0.378734a", "PPICApp");
if (!hwnd_main.Equals(IntPtr.Zero))
{
bwinFound =
true;
}
if (bwinFound) //window found
{
hwnd_btn = FindWindowEx(hwnd_main, (
IntPtr)0, btnHandl, "HidenZoomTo");
if (!hwnd_btn.Equals(IntPtr.Zero))
{
try
{
//MessageBox.Show("Zoom To button Found"); //this will pops up
Message msg = Message.Create(hwnd_btn, BtnClick,
new IntPtr(0), new IntPtr(0));
IntPtr bSucc = PostMessage(msg.HWnd, msg.Msg, msg.WParam, msg.LParam);
MessageBox.Show("bSucc = " + bSucc); 

//another try
bSucc = PostMessage(hwnd_btn, BtnClick, (
IntPtr)0, (IntPtr)0);
MessageBox.Show(
"bSucc? = " + bSucc);
//In both calls to PostMessage the return value are 1. but there is no response to PPICApp

}
catch (Exception ex) { MessageBox.Show(ex.Message, "Office Add-in fails to fire button click event"); }
}
}

#endregion

}
catch (Exception e) { MessageBox.Show("Err: " + e.Message, "PPIC Office Add in"); }
}

 
Regards.
Dave
 
 

Answers (3)