Using Non automated Annotations in Run Mode:

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.

1.

Start with the program you created in Implementing a Non-automated Annotation Program.

2.

Add a menu resource to the project. If you are familiar with this process, you can skip to the next step.

 

a.

From the Insert menu, select Resource. Highlight Menu and click on OK.

 

b.

The IDR_MENU will appear. Right click on IDR_MENU, select Properties and change the name to MAIN_MENU1.

 

c.

Right click on the menu entry (the outlined rectangle), and select Properties.

 

d.

In the Caption box enter User Mode. Make sure Pop-up is selected and press Enter.

 

e.

Another rectangle appears under the User Mode button on the menu. Right click on that box and select Properties.

 

f.

Set the ID to IDM_DESIGN and the Caption to Design Mode. Make sure Checked has been selected. Press Enter.

 

g.

Another rectangle appears under the Design Mode button on the menu. Right click on that box and select Properties.

 

h.

Set the ID to IDM_RUN and the Caption to Run Mode. Press Enter. Save the resource.

 

i.

Within the resource.h file in the EZNON directory, check the values listed for IDM_DESIGN and IDM_RUN. You can either change these values or leave them as they are, but you must define IDM_DESIGN and IDM_RUN in EZFUNC.H using the same values.

3.

In InitApplication, change the line:

wcWindowClass.lpszMenuName = NULL; to

wcWindowClass.lpszMenuName = "MAIN_MENU1";

4.

In InitInstance, change the menu parameter in CreateWindow from NULL to:

LoadMenu(hInstance, MAKEINTRESOURCE(MAIN_MENU1)).

5.

In the MainWndProc procedure, add the following code to the switch statement:

case WM_COMMAND:
switch(LOWORD(wParam))
{
   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;
}
return 0;

6.

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);

7.

Add the following declarations to MainWndProc:

int xPos, yPos;
HANNOBJECT hCurrentObject;
L_UINT uCurrentObjectType;

8.

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);

/* Get the dimensions of the container’s rectangle. */
   L_AnnGetRect(hContainer, &ContainerRect);

/* 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);
   L_AnnDraw(hdc, &rAnnBounds, MyAudio);

/* Remove the queued paint message. */
   ValidateRect(hWnd, &rAnnBounds);
   return;
}

9.

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);
   /* 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);
   L_AnnDraw(hWindowDC, &rAnnBounds, MyButton);
   /* Remove the queued paint message */
   ValidateRect(hWnd, &rAnnBounds);
   return;
}

10.

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);
   /* Update the caller's object variable */
   if (TestResult == ANNHIT_NONE)
      *phAnnObject = 0;
   else
      *phAnnObject = ThisObject;     
   return;

11.

Code the WM_LBUTTONDOWN message as follows:

case WM_LBUTTONDOWN:
   if (nAnnUserMode == ANNUSER_RUN)
   {
     xPos = LOWORD(lParam);
     yPos = HIWORD(lParam);
     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;
     }
   }
   return 0;

12.

Code the WM_LTANNEVENT message as follows:

case WM_LTANNEVENT:

switch((int)wParam)

{

case LTANNEVENT_ACTIVATE:

if ((int)lParam == ANNTOOL_AUDIO)

L_AnnSetActiveState(MyAudio, ANNACTIVE_ENABLED);

if ((int)lParam == ANNTOOL_BUTTON)

{

#ifdef UNICODE

_wsystem(TEXT("c:\\Windows\\calc"));

#else

system("c:\\Windows\\calc");

#endif

}

break;

}

  return 0;

13.

Comment out the TestCreateNoteAnn(hWnd) line in WM_CREATE and add the following lines:

TestCreateAudioAnn(hWnd);
TestCreateButtonAnn(hWnd);

14.

Build Ezfunc32.exe.

15.

Run Ezfunc32.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.