Take the following steps to add code to the existing project that will let you create an audio annotation and a button annotation, set the user mode through a menu, and activate the annotations by left clicking on the annotation.
Start with the program you created in Implementing a Non-automated Annotation Program.
Add a menu resource to the project.
Add the following line at the top of Color.rc after #include "Windows.h".
#include "Color.h"
Add the following code to the to Color.rc
MENU_MAIN MENU
BEGIN
POPUP "User Mode"
BEGIN
MENUITEM "Design", IDM_DESIGN, CHECKED
MENUITEM "Run", IDM_RUN
END
END
Open Color.h, and add the following lines to the top.
#define IDM_DESIGN 200
#define IDM_RUN 300
#define MENU_MAIN 400
In InitApplication, change the line:
wcWindowClass.lpszMenuName = NULL;
To
wcWindowClass.lpszMenuName = TEXT("MENU_MAIN");
In InitInstance, change the menu parameter in CreateWindow from NULL to:
LoadMenu(hInstance, MAKEINTRESOURCE(MENU_MAIN))
In the Window_OnCommand procedure, add the following code to the switch statement:
case IDM_RUN: /* set the user mode to run mode */
L_AnnSetUserMode(hContainer, ANNUSER_RUN);
CheckMenuItem(GetMenu(hWnd), IDM_DESIGN, MF_UNCHECKED);
CheckMenuItem(GetMenu(hWnd), IDM_RUN, MF_CHECKED);
nAnnUserMode = ANNUSER_RUN;
break;
case IDM_DESIGN: /* set the user mode to design mode */
L_AnnSetUserMode(hContainer, ANNUSER_DESIGN);
CheckMenuItem(GetMenu(hWnd), IDM_RUN, MF_UNCHECKED);
CheckMenuItem(GetMenu(hWnd), IDM_DESIGN, MF_CHECKED);
nAnnUserMode = ANNUSER_DESIGN;
break;
Declare the following global variables:
HANNOBJECT MyAudio; /* audio annotation object */
HANNOBJECT MyButton; /* button annotation object */
L_INT nAnnUserMode = ANNUSER_DESIGN;
and the following functions:
void TestCreateAudioAnn(HWND hWnd);
void TestCreateButtonAnn(HWND hWnd);
void TestAnnHit(int xFromWindow, int yFromWindow, pHANNOBJECT phAnnObject);
Add the following code:
void TestCreateAudioAnn(HWND hWnd)
{
/* This code creates the audio annotation and associates a .wav file with the annotation. */
HDC hdc;
ANNRECT ContainerRect;
ANNRECT MyAudioRect;
RECT rAnnBounds;
hdc = GetDC(hWnd);
/* Create the audio annotation object */
L_AnnCreate(ANNOBJECT_AUDIO, &MyAudio);
/* Insert the audio annotation in the container created in TestCreateAnn. */
L_AnnInsert(hContainer, MyAudio, FALSE);
/* Make the annotation visible. */
L_AnnSetVisible(MyAudio, TRUE, 0, NULL);
/* Get the dimensions of the container's rectangle. */
L_AnnGetRect(hContainer, &ContainerRect, NULL);
/* Set the placement of the audio annotation. */
MyAudioRect.left = ContainerRect.right * 5/8;
MyAudioRect.top = ContainerRect.bottom * 5/8;
MyAudioRect.right = ContainerRect.right * 3/4;
MyAudioRect.bottom = ContainerRect.bottom * 3/4;
L_AnnSetRect(MyAudio, &MyAudioRect);
/* Set the name of the .wav file to associate with this annotation. This .wav file will play when you click on the annotation in run mode. Change the path and filename to suit your system */
L_AnnSetText(MyAudio, TEXT("tada.wav"), 0);
/* Display the annotation. */
L_AnnGetBoundingRect(MyAudio, &rAnnBounds, NULL);
L_AnnDraw(hdc, &rAnnBounds, MyAudio);
/* Remove the queued paint message. */
ValidateRect(hWnd, &rAnnBounds);
return;
}
Add the following code:
void TestCreateButtonAnn(HWND hWnd)
{
/* This function creates a button annotation. */
HDC hWindowDC; /* Device context of the current window */
ANNRECT ContainerRect; /* Root container's rectangle */
ANNRECT MyButtonRect; /* Rectangle for the button object */
RECT rAnnBounds; /* Bounding rectangle used to draw the object */
/* Get the device context of the current window */
hWindowDC = GetDC (hWnd);
/* Get the container's rectangle */
L_AnnGetRect(hContainer, &ContainerRect, NULL);
/* Create the button annotation */
L_AnnCreateItem(hContainer, ANNOBJECT_BUTTON, TRUE, &MyButton);
/* Size and position the button */
MyButtonRect.left = ContainerRect.right / 8;
MyButtonRect.top = ContainerRect.bottom / 2;
MyButtonRect.right = ContainerRect.right / 2;
MyButtonRect.bottom = ContainerRect.bottom * 5/8 ;
L_AnnSetRect(MyButton, &MyButtonRect);
/* Set the text of the button */
L_AnnSetText(MyButton, TEXT("This is a No. 3 button"), 0);
/* Enable the button */
L_AnnSetActiveState(MyButton, ANNACTIVE_ENABLED);
/* Set the tag to 3. You can base actions on the tag number */
L_AnnSetTag(MyButton, 3, 0);
/* Display the button */
L_AnnGetBoundingRect(MyButton, &rAnnBounds, NULL);
L_AnnDraw(hWindowDC, &rAnnBounds, MyButton);
/* Remove the queued paint message */
ValidateRect(hWnd, &rAnnBounds);
return;
}
Add the following code:
void TestAnnHit(int xFromWindow, int yFromWindow, pHANNOBJECT phAnnObject)
{
/* This function determines which annotation object you have clicked. */
HANNOBJECT ThisObject; /* Local variable for the annotation object */
POINT PointToTest; /* The point in the window's client area to test */
L_UINT TestResult; /* Result of the test */
/* Use incoming coordinates to specify the point to test */
PointToTest.x = xFromWindow;
PointToTest.y = yFromWindow;
/* Get the object at the specified point */
L_AnnHitTest(hContainer, &PointToTest, &TestResult, &ThisObject, NULL, sizeof(ANNHITTESTINFO));
/* Update the caller's object variable */
if (TestResult == ANNHIT_NONE)
*phAnnObject = 0;
else
*phAnnObject = ThisObject;
return;
}
Add the following message handlers to MainWndProc:
HANDLE_MSG (hWnd, WM_LTANNEVENT, Window_AnnEvent);
HANDLE_MSG (hWnd, WM_LBUTTONDOWN, Window_OnLButtonDown);
Add the following code for Window_OnLButtonDown:
void Window_OnLButtonDown(HWND hWnd, BOOL fDoubleClick, int xPos, int yPos, UINT keyFlags)
{
UNREFERENCED_PARAMETER(keyFlags);
UNREFERENCED_PARAMETER(fDoubleClick);
if (nAnnUserMode == ANNUSER_RUN)
{
HANNOBJECT hCurrentObject = 0;
L_UINT uCurrentObjectType = ANNOBJECT_LAST;
TestAnnHit(xPos, yPos, &hCurrentObject);
L_AnnGetType (hCurrentObject, &uCurrentObjectType);
switch (uCurrentObjectType)
{
case ANNOBJECT_AUDIO:
SendMessage(hWnd, WM_LTANNEVENT, LTANNEVENT_ACTIVATE, ANNTOOL_AUDIO);
break;
case ANNOBJECT_BUTTON:
SendMessage(hWnd, WM_LTANNEVENT, LTANNEVENT_ACTIVATE, ANNTOOL_BUTTON);
break;
}
}
}
Add the following code for Window_AnnEvent:
LRESULT Window_AnnEvent(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(hWnd);
switch(wParam)
{
case LTANNEVENT_ACTIVATE:
if ((int)lParam == ANNTOOL_AUDIO)
L_AnnSetActiveState(MyAudio, ANNACTIVE_ENABLED);
if ((int)lParam == ANNTOOL_BUTTON)
{
_wsystem(TEXT("calc"));
}
break;
}
return 0;
}
Comment out the TestCreateNoteAnn(hWnd) line in Window_OnCreate and add the following lines:
TestCreateAudioAnn(hWnd);
TestCreateButtonAnn(hWnd);
Build Color.exe.
Run Color.exe. Click on the audio and button annotations. Since the User Mode is Design Mode, nothing happens. Under the User Mode menu, select Run Mode then click on each annotation. Save this project for testing Annotation code samples.
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document