API question

B

Bill

In persuing a solution to suppressing Outlook
warning messages when employing the Outlook
object model from within VBA, a suggestion
was made to trap the warning dialogs and
simply close them from some API code. Has
anyone already done this type of approach
to the problem? If so, some sample code
would be nice.
Thanks,
Bill
 
B

Bill

Thanks Tom,
I'm waiting to hear from my client as to how many
systems will be hosting the application. If it's more
than a couple, then there's the drawback of having
to install Redemption on several systems.
Bill
 
M

MikeB

Bill,
I did this about a year ago but my code is in Delphi. It is not difficult
to follow the logic used and port it to VBA or VB. The most important part
of the code is the cursor position over the checkbox and the triggering of
the mouse event. If the event is not triggered, the workaround won't work
(as I found out after whacking around with it for several hours).
Sorry there isn't any commenting in the code, as I only did it for a onetime
demonstration at a conference, but you are welcome to work it out if you
wish...

Here goes:

Note: The function KillSecurity is called from a timer that is disabled upon
finding the Warning Window. The polling rate and so on you will have to
fine tune for your particular use.

//Begin Delphi Code
// The Clss variable is the Window Class, Capt is the Window Caption for the
Warning Window.
// If you don't know the Class, you can find Mike D. Sutton's WndInf13.exe
utility in the wild with a little checking that will be helpful.

function KillSecurity(Clss : PChar; Capt : PChar) : Boolean; Stdcall;
var
hWndParent :Integer;
hWndTmp :Integer;
hWndChild :Integer;
hWndCheck :Integer;
hWndCombo :Integer;
comboItems :Integer;
mousepos :TPOINT;
lpRect :TRECT;
begin;
Result := False;
hWndParent := 0;
hWndChild := 0;
hWndCombo := 0;
hWndCheck := 0;
// Get parent window handle;
if (Strlen(Clss) = 0) then
begin
hWndParent := FindWindow(nil, Capt);
end
else
begin
hWndParent := FindWindow(Clss, Capt);
end;
// If we found a handle;
If (hWndParent > 0) Then
begin
SetActiveWindow(hWndParent);
// Find the //Yes// button and other things in the security box;
hWndChild := FindWindowEx(hWndParent, 0, 'Button', 'Yes');
If (hWndChild = 0) Then
begin
hWndChild := FindWindowEx(hWndParent, 0, 'Button', 'Yes');
End;
hWndCombo := FindWindowEx(hWndParent, 0, 'ComboBox', '');
hWndCheck := FindWindowEx(hWndParent, 0, 'Button', '&Allow
access for');
If (hWndChild > 0) And (hWndCheck > 0) And (hWndCombo > 0) Then
begin
GetCursorPos(mousepos);
GetWindowRect(hWndParent, lpRect);
SetCursorPos(lpRect.Left + 10, lpRect.Top + 10);
{the OL Dialog has to receive the mouse event with
mouse position within the RECT of the button}
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Sleep(0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
SetCursorPos(mousepos.X, mousepos.Y);
if not (SendMessage(hWndCheck, BM_GETSTATE, 0, 0) =
BST_CHECKED) then
begin
SendMessage(hWndCheck, BM_SETCHECK, 1, 0);
// Get number of drop down items;
Sleep(5);
comboItems := SendMessage(hWndCombo, CB_GETCOUNT, 0, 0);
// Set minutes to number of drop down items (0 based);
SendMessage(hWndCombo, CB_SETCURSEL, comboItems - 1,
0);
// Click //Yes//;
end;
GetWindowRect(hWndChild, lpRect);
SetCursorPos(lpRect.Left + 10, lpRect.Top + 10);
SendMessage(hWndChild, WM_ACTIVATE, MA_ACTIVATE, 0);
SendMessage(hWndChild, BM_CLICK, 0, 0);
hWndTmp := hWndParent;
if (Strlen(Clss) = 0) then
begin
hWndParent := FindWindow(nil, Capt);
end
else
begin
hWndParent := FindWindow(Clss, Capt);
end;
if (hWndParent = 0) and (hWndTmp > 0) then
begin
Result := True;
end;
End;
End;
End;
// End Delphi Code
 
B

Bill

Thanks Mike. I'm still waiting for some feedback
from my client before spending any more time on
this caper.
Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top