Brass Plugins: Mime Developers Guide
This page shows you how to create an application
with win32 & C++, then with MFC that can easily integrate with
Mime. If your app is written in another language then the principles
still apply but you'll be on your own to implement them.
Creating an application - Win32
& C++
Download
the VC6 workspace & code for this sample application
We'll start by making the most basic app we can with the VC6 AppWizard.
I selected the "Win32 Application" wizard and named it
"TestApp". I selected "A simple 'Hello World' application
and let the wizard create my project.
This gives me a standard win32 C++ app that puts a window on screen
with a File-Exit and Help-About options in the menu. When you select
"Help - About" a skeleton dialog is shown with a bit of
text in it.

Our task is going to be to add gesture support to this application
so the user can access the "Help - About" dialog with
a gesture.
First thing to do is to add a custom message handler to the application.
Open the TestApp.cpp file and add a #define for a new message.

In this case I've defined MIME_GESTURE_SHOWABOUTBOX
to be WM_USER
+ 1. You can of course use WM_DATA
+ 1 if you choose.
Next we need to edit the messageproc/wndproc and add a handler
for our new message. Scroll down the file until you find the message
loop handler, then add a line of code to display the "Help
- About" dialog when we receive the MIME_GESTURE_SHOWABOUTBOX
message.

As you can see, I've simply duplicated the line of code that handles
the "Help - About" menu selection and put it in the MIME_GESTURE_SHOWABOUTBOX
handler. Build the app, save the executable and we're done.
Yes, that really is all we need to do! You can move on to the next
stage now - creating
the criteria plugin.
Creating an application - MFC
& C++
Download
the VC6 workspace & code for this sample application
Just as with the win32 version, we'll start with the most basic
application. In this case we're going to create a dialog-based application
that shows the about box on a gesture.
Start the VC6 appwizard and create an MFC executable. I selected
the standard dialog based, no ActiveX controls, with an About Box,
MFC as a shared DLL with source comments options. I called it TestAppMFC.
This gives me a standard MFC dialog application. Clicking on the
system menu and selecting "About" displays the skeleton
about box.

First thing to do is to add a custom message handler to the application.
Open the TestAppMFCDlg.h file and add a #define for a new message
at the top.

In this case I've defined MIME_GESTURE_SHOWABOUTBOX
to be WM_USER
+ 1. You can of course use WM_DATA
+ 1 if you choose.
Next we need to add a custom message handler to the message map.
If you've never done this before, don't worry - it's easy. First
we need to add our function prototype to the map. Open TestAppMFCDlg.h,
scroll to the bottom and find the AFX_MSG code at the bottom of
the class.

In the above screenshot I've added a manual entry to the map for
a function called OnMimeGestureShowAboutBox().
Note the position of this declaration very carefully - it's after
the //}AFX_MSG
line but before the DECLARE_MESSAGE_MAP
line. There are lots of great tutorials out there on manually adding
messages to the MFC map so I won't go into this in detail.
Next we need to add a handler for our message to the message map,
and map it to this function. Open TestAppMFCDlg.cpp and locate the
message map for CTestAppMFCDlg. Be sure you have the right one because
the CAboutDlg class will also have one in this file.

Add an entry to the map for our Mime gesture message, linking it
to the function we just prototyped. Your code should look like the
screenshot above. Again, take note of where the code has been added,
after the //}AFX_MSG_MAP
line but before the END_MESSAGE_MAP
line.
The last thing we need to do is add a handler for this message
to our code. Scroll to the end of the CTestAppMFCDlg.cpp file and
add the following code:

It's pretty self-explanatory: when the message is sent to the application,
this handler displays the About dialog. One note, missing from the
screenshot should be a return
0; command. Build the app, save the executable and we're
done.
Yes, that really is all we need to do! You can move on to the next
stage now - creating
the criteria plugin.
|