GUI interface for my add-in

  • Thread starter Abdulla P.P via OfficeKB.com
  • Start date
A

Abdulla P.P via OfficeKB.com

(e-mail address removed)

Hi All,

I would like to add a GUI in my outlook 2k as an add-in.
Is it necessary to use MFC for this? ot do we have any other solution?
I heard about CWindow and CWindowImpl classes in ATL.
I want a form with two buttons,4 labels and 4 textboxes and i have to catch
their events.If any one can help me please help.

thanks,
Abdulla.P.P
 
D

Dmitry Streblechenko

There is absolutely no requirement to use MFC. Or VC++ for that matter.
Whatever you are most comfortable with should work just fine.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
A

Abdulla P.P via OfficeKB.com

Hi Dmitry,

Thanks for your reply.
But I have developed an addin in VC++ using ATL.And it is working without
any problem.Now I need some user inputs to set the behaviour of my add-in.
can you tell me how can i achieve this simply?

Thanks
Abdulla.P.P
 
D

Dmitry Streblechenko

I don't use VC++ and ATL, but I am not sure what is the exact problem you
are having. Did you try to use whatever framework/API you are most
confortable with?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
A

Abdulla P.P via OfficeKB.com

Hi Dmitry,

Thanks for your reply.
No.I just want know which is the right way to develope forms using VC++.
Thanks
Abdulla.P.P
 
C

Chris

God Dmitry are you doing it on purpose?

He is asking you how to do it. Not is it possible!
He wants an example or a hint on how to get started, NOT a "it is all up to
you"
*If you where not doing it on purpose sorry in advance!*

I too am looking for an answer to this question, I know how to do it in MFC
but it does not seem to work in ATL (yes my Addin supports MFC). But as soon
as I create the dialog Outlook crashes!

Chris
 
D

Dmitry Streblechenko

I really don't see a difference in whether you create a window in a
standalone app or in an Outlook COM addin. A window is a window is a window.
The only thing to keep in mind is that your favorite library might not have
all of its objects initialized unless your code is in an exe with a main
window properly created by that library.
Another thing to keep in mind is to supply the proper window parent handle
to all of your windows
I don't use either MFC or ATL - in Delphi/VCL or straight Windows API
creating your own windows is not any different form a standalone exe.
If you get a crash, surely you can see where it comes from, can't you?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
M

Mark Werner via OfficeKB.com

Chris,

You should have no problem using ATL to display a dialog in Outlook. You
must be doing something wrong (feel free to post code). I build my addins
using ATL; but, love MFC for the dialogs (other than the options page site
where it is 100% easier to use ATL).

On another note, when using modal dialogs from the addin you WILL want to
make the parent window to the dialog the Outlook application itself or else
they can be hidden behind the Outlook application! To do this you want to
get the Outlook window:

try
{
CComQIPtr<Outlook::_Application> pOutlookApp(pApplication);

IDispatch* pDispatch = NULL;

if (pOutlookApp)
{
pOutlookApp->ActiveWindow(&pDispatch);

if (pDispatch)
{
IOleWindow* pOleWindow;

pDispatch->QueryInterface(IID_IOleWindow, (void **) &pOleWindow)
;

if (pOleWindow)
{
pOleWindow->GetWindow(&hwndParent);
pOleWindow->Release();
}
}
}
}
catch(...)
{
hwndParent = NULL;
}

if (!hwndParent)
hwndParent = ::GetDesktopWindow();

Now you can temporarialy attatch this to a CWnd (MFC) or CWindow (ATL)
object so it can be passed to you dialog constructor. Don't forget to
detatch it when you destruct. You could also use FromHandle instead.

Now what gets really complicated is if you want these dialogs to have the
XP Theme (if activated) you need to use an activation context since this is
actually an inprocess DLL. The manifest file in the resource will not work
(although the manifest file in the application root will; but, this is a
bad practice since it will effect all addins). I'll throw this in as a
bonus becuase I am sure there are many developers pulling their hair out
trying to get themeing working for the dialogs.

CActivationContext g_ActivationContext;

CActivationContext::CActivationContext()
{
m_hModule = NULL;
m_hActCtx = INVALID_HANDLE_VALUE;
m_ulActivationCookie = 0;
}

CActivationContext::~CActivationContext()
{
Close();
}

typedef HANDLE (WINAPI* CREATEACTCTX_PROC)(PCACTCTXA);
void CActivationContext::Open()
{
Close();

m_hModule = LoadLibrary("kernel32.dll");

char szPath[MAX_PATH] = "";
GetModuleFileName(NULL, szPath, MAX_PATH);
ACTCTX act = {0};
act.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
act.lpResourceName = MAKEINTRESOURCE(2);

if (INVALID_HANDLE_VALUE == m_hActCtx)
{
act.cbSize = sizeof(act);
act.lpSource = szPath;

CREATEACTCTX_PROC pProc = (CREATEACTCTX_PROC) GetProcAddress
(m_hModule, "CreateActCtxA");
if (pProc)
m_hActCtx = pProc(&act);
}
}

typedef VOID (WINAPI* RELEASEACTCTX_PROC)(HANDLE);
void CActivationContext::Close()
{
if (!m_hModule)
return;

Deactivate();

if (INVALID_HANDLE_VALUE != m_hActCtx)
{
RELEASEACTCTX_PROC pProc = (RELEASEACTCTX_PROC) GetProcAddress
(m_hModule, "ReleaseActCtx");
if (pProc)
pProc(m_hActCtx);

m_hActCtx = INVALID_HANDLE_VALUE;
}

FreeLibrary(m_hModule);
m_hModule = NULL;
}

typedef BOOL (WINAPI* ACTIVATEACTCTX_PROC)(HANDLE, ULONG_PTR*);
void CActivationContext::Activate()
{
if (0 == m_ulActivationCookie)
{
ACTIVATEACTCTX_PROC pProc = (ACTIVATEACTCTX_PROC) GetProcAddress
(m_hModule, "ActivateActCtx");
if (pProc)
pProc(m_hActCtx, &m_ulActivationCookie);
}
}

typedef BOOL (WINAPI* DEACTIVATEACTCTX_PROC)(DWORD, ULONG_PTR);
void CActivationContext::Deactivate()
{
if (0 != m_ulActivationCookie)
{
DEACTIVATEACTCTX_PROC pProc = (DEACTIVATEACTCTX_PROC) GetProcAddress
(m_hModule, "DeactivateActCtx");
if (pProc)
pProc(0, m_ulActivationCookie);
}

m_ulActivationCookie = 0;
}

Mark
 
M

Mark Werner via OfficeKB.com

BTW - the GetDesktopWindow call in the previous post is just there in case
the Outlook thingy fails.
 

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