sudhakar_koundinya
asked on
PostMessage and SendMessage are not working on Button
Hi All,
Can anybody explain me why any of SendMessage or PostMessage functions are not working on Button??
Do I made any mistake??
if( YesWnd != 0)
{
h = YesWnd;
//SetWindowText(h,"Sudhaka r");
//AfxMessageBox("1");
// SendMessage(h, BN_CLICKED, 0, 0);
PostMessage(h, WM_LBUTTONDOWN, 0, 0);
PostMessage(h, WM_LBUTTONUP, 0, 0);
// SendMessage(h, WM_LBUTTONDOWN, 0, 0);
// SendMessage(h, WM_LBUTTONUP, 0, 0);
PostMessage(h, BM_CLICK, 0, 0);
PostMessage(h, BN_CLICKED, 0, 0);
// SendMessage(h, BM_CLICK, 0, 0);
AfxMessageBox("1");
ok=true;
}
Thanks
Sudhakar
P.S: I am able to set the window text for that button. But Mouse click events are not firing
Can anybody explain me why any of SendMessage or PostMessage functions are not working on Button??
Do I made any mistake??
if( YesWnd != 0)
{
h = YesWnd;
//SetWindowText(h,"Sudhaka
//AfxMessageBox("1");
// SendMessage(h, BN_CLICKED, 0, 0);
PostMessage(h, WM_LBUTTONDOWN, 0, 0);
PostMessage(h, WM_LBUTTONUP, 0, 0);
// SendMessage(h, WM_LBUTTONDOWN, 0, 0);
// SendMessage(h, WM_LBUTTONUP, 0, 0);
PostMessage(h, BM_CLICK, 0, 0);
PostMessage(h, BN_CLICKED, 0, 0);
// SendMessage(h, BM_CLICK, 0, 0);
AfxMessageBox("1");
ok=true;
}
Thanks
Sudhakar
P.S: I am able to set the window text for that button. But Mouse click events are not firing
ASKER
Yes I know that.
But my problem is with MS Outlook Security Warnings.
Actually I am developing a software for a recruiting company for which they are using MS Outlook for sending the mails to companies/consultants/cont act persons.
So for this, I am developing both plugin and standalone application for tracking the mails.
When I try to communicate the Outlook mails or trying to send the mails using Outlook or trying to access Outlook addressbook I am getting those warnings
This problem is started from MS Outlook 2002 (SP2). So MS Outlook 2003 and 2002 stops functioning until user interacts wiith such warning dialogs.
As an example
http://support.microsoft.com/?kbid=842945
To get rid of such warnings I am writing this code
By looking at application clickYes at http://www.snapfiles.com/get/clickyes.html, I got this Idea
Here is my initial startup code
bool clickYes()
{
HWND hwnd;
hwnd = FindWindow(NULL, "Microsoft Outlook");
if( hwnd == 0 )
return false;
//AfxMessageBox(GetWndText (hwnd));
CString str;
bool ok=false;
HWND h = GetWindow(hwnd, GW_CHILD);
HWND hButton=0;
HWND checkWnd =0;
HWND YesWnd =0;
HWND comboWnd =0;
while(true)
{
if( GetWndClass(h) == "ComboBox" )
{
comboWnd = h;
}
else if (GetWndClass(h) == "Button" )
{
if (GetWndText(h) == "Yes" )
{
YesWnd = h;
}
else if (GetWndText(h) == "&Allow access for" )
{
checkWnd = h;
}
}
h = GetWindow(h, GW_HWNDNEXT);
if(h==NULL)
break;
}
if (checkWnd != 0)
{
h = checkWnd;
if( SendMessage( (HWND) h, (UINT) BM_GETCHECK, (WPARAM) 0, (LPARAM) 0 )==BST_UNCHECKED)
{
PostMessage(h, WM_LBUTTONDOWN, 0, 0);
PostMessage(h, WM_LBUTTONUP, 0, 0);
}
}
else
return false;
if( comboWnd != 0)
{
h = comboWnd;
SendMessage(h,CB_SELECTSTR ING,-1,(WP ARAM)"10 minutes");
}
else
return false;
if( YesWnd != 0)
{
h = YesWnd;
//SetWindowText(h,"Sudhaka r");
//AfxMessageBox("1");
// SendMessage(h, BN_CLICKED, 0, 0);
PostMessage(h, WM_LBUTTONDOWN, 0, 0);
PostMessage(h, WM_LBUTTONUP, 0, 0);
// SendMessage(h, WM_LBUTTONDOWN, 0, 0);
// SendMessage(h, WM_LBUTTONUP, 0, 0);
PostMessage(h, BM_CLICK, 0, 0);
PostMessage(h, BN_CLICKED, 0, 0);
// SendMessage(h, BM_CLICK, 0, 0);
//AfxMessageBox("1");
ok=true;
}
else
return false;
h=hwnd;
PostMessage(h, WM_LBUTTONDOWN, 0, 0);
PostMessage(h, WM_LBUTTONUP, 0, 0);
PostMessage(h, BN_CLICKED, 0, 0);
return ok;
}
But my problem is with MS Outlook Security Warnings.
Actually I am developing a software for a recruiting company for which they are using MS Outlook for sending the mails to companies/consultants/cont
So for this, I am developing both plugin and standalone application for tracking the mails.
When I try to communicate the Outlook mails or trying to send the mails using Outlook or trying to access Outlook addressbook I am getting those warnings
This problem is started from MS Outlook 2002 (SP2). So MS Outlook 2003 and 2002 stops functioning until user interacts wiith such warning dialogs.
As an example
http://support.microsoft.com/?kbid=842945
To get rid of such warnings I am writing this code
By looking at application clickYes at http://www.snapfiles.com/get/clickyes.html, I got this Idea
Here is my initial startup code
bool clickYes()
{
HWND hwnd;
hwnd = FindWindow(NULL, "Microsoft Outlook");
if( hwnd == 0 )
return false;
//AfxMessageBox(GetWndText
CString str;
bool ok=false;
HWND h = GetWindow(hwnd, GW_CHILD);
HWND hButton=0;
HWND checkWnd =0;
HWND YesWnd =0;
HWND comboWnd =0;
while(true)
{
if( GetWndClass(h) == "ComboBox" )
{
comboWnd = h;
}
else if (GetWndClass(h) == "Button" )
{
if (GetWndText(h) == "Yes" )
{
YesWnd = h;
}
else if (GetWndText(h) == "&Allow access for" )
{
checkWnd = h;
}
}
h = GetWindow(h, GW_HWNDNEXT);
if(h==NULL)
break;
}
if (checkWnd != 0)
{
h = checkWnd;
if( SendMessage( (HWND) h, (UINT) BM_GETCHECK, (WPARAM) 0, (LPARAM) 0 )==BST_UNCHECKED)
{
PostMessage(h, WM_LBUTTONDOWN, 0, 0);
PostMessage(h, WM_LBUTTONUP, 0, 0);
}
}
else
return false;
if( comboWnd != 0)
{
h = comboWnd;
SendMessage(h,CB_SELECTSTR
}
else
return false;
if( YesWnd != 0)
{
h = YesWnd;
//SetWindowText(h,"Sudhaka
//AfxMessageBox("1");
// SendMessage(h, BN_CLICKED, 0, 0);
PostMessage(h, WM_LBUTTONDOWN, 0, 0);
PostMessage(h, WM_LBUTTONUP, 0, 0);
// SendMessage(h, WM_LBUTTONDOWN, 0, 0);
// SendMessage(h, WM_LBUTTONUP, 0, 0);
PostMessage(h, BM_CLICK, 0, 0);
PostMessage(h, BN_CLICKED, 0, 0);
// SendMessage(h, BM_CLICK, 0, 0);
//AfxMessageBox("1");
ok=true;
}
else
return false;
h=hwnd;
PostMessage(h, WM_LBUTTONDOWN, 0, 0);
PostMessage(h, WM_LBUTTONUP, 0, 0);
PostMessage(h, BN_CLICKED, 0, 0);
return ok;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
jaime_olivares,
I am afraid to say that, it does not help me
But what I have identified is once posting the messages to Button("Yes"), If I click on My application or some other applications then PostMessage is able to post the message to "Yes" button and Microsoft Outlook Dialog is getting destroyed and application is executing perfectly with no problem.
Taking this observation into consideration, I have followed all the below methods to remove the focus from Microsoft Outlook Dialog. But it does not help me.
PostMessage(AfxGetApp()->m _pMainWnd- >m_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(pt.x,pt.y));
PostMessage(AfxGetApp()->m _pMainWnd- >m_hWnd, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(pt.x,pt.y));
PostMessage(AfxGetApp()->m _pMainWnd- >m_hWnd, BN_CLICKED, MK_LBUTTON, MAKELPARAM(pt.x,pt.y));
SetFocus(AfxGetApp()->m_pM ainWnd->m_ hWnd);
Any Idea??
I am afraid to say that, it does not help me
But what I have identified is once posting the messages to Button("Yes"), If I click on My application or some other applications then PostMessage is able to post the message to "Yes" button and Microsoft Outlook Dialog is getting destroyed and application is executing perfectly with no problem.
Taking this observation into consideration, I have followed all the below methods to remove the focus from Microsoft Outlook Dialog. But it does not help me.
PostMessage(AfxGetApp()->m
PostMessage(AfxGetApp()->m
PostMessage(AfxGetApp()->m
SetFocus(AfxGetApp()->m_pM
Any Idea??
ASKER
And also what I have observed is MS Outlook dialog is Topmost window of all the desktop windows
Thanks
Sudhakar
Thanks
Sudhakar
I think we are confusing who to send the message. Let's try with:
::PostMessage(YesWnd , BM_CLICK, 0,0);
::PostMessage(YesWnd , BM_CLICK, 0,0);
ASKER
No, it doesn't help :-(
ASKER
BTW,
from the site http://www.outlookcode.com/d/sec.htm
It has below comment
Clicks the security dialog buttons automatically, but can be set to start in a suspended state. Developers can activate and suspend automatic clicking of the security dialogs programmatically. (HINT: Use &H2 instead of WM_CLOSE) Free.
Now what does &H2 mean??
from the site http://www.outlookcode.com/d/sec.htm
It has below comment
Clicks the security dialog buttons automatically, but can be set to start in a suspended state. Developers can activate and suspend automatic clicking of the security dialogs programmatically. (HINT: Use &H2 instead of WM_CLOSE) Free.
Now what does &H2 mean??
it refers to the ClickYes application, if you send a 0x02 (hex 2) message, but if don't know exact behaviour for this message (0x00 is for suspend and 0x01 is for resume).
ASKER
can you post me a solution in which I need to post/send BN_Clicked message using SendMessage or PostMessage methods
I have tried like this. But they are not working.
SendMessage(h, WM_COMMAND, 0, BN_CLICKED);
PostMessage(h, WM_COMMAND, 0, BN_CLICKED);
I have tried like this. But they are not working.
SendMessage(h, WM_COMMAND, 0, BN_CLICKED);
PostMessage(h, WM_COMMAND, 0, BN_CLICKED);
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i Did similarly
::SendMessage(hwnd, WM_COMMAND, MAKELONG(GetDlgCtrlID(h), BN_CLICKED), h);
or
::PostMessage(hwnd, WM_COMMAND, MAKELONG(GetDlgCtrlID(h), BN_CLICKED), h);
But I Get following error
StdAfx.cpp
error C2664: 'SendMessageA' : cannot convert parameter 4 from 'struct HWND__ *' to 'long'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
error C2664: 'PostMessageA' : cannot convert parameter 4 from 'struct HWND__ *' to 'long'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
::SendMessage(hwnd, WM_COMMAND, MAKELONG(GetDlgCtrlID(h), BN_CLICKED), h);
or
::PostMessage(hwnd, WM_COMMAND, MAKELONG(GetDlgCtrlID(h), BN_CLICKED), h);
But I Get following error
StdAfx.cpp
error C2664: 'SendMessageA' : cannot convert parameter 4 from 'struct HWND__ *' to 'long'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
error C2664: 'PostMessageA' : cannot convert parameter 4 from 'struct HWND__ *' to 'long'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think it is not a good practice to force a button to be pressed programatically.