AnnSaveMemory example for C++ 4.0 and later
Note: This topic is for Document/Medical only.
This example lets you save the current annotations to a file in memory, and lets you load the annotations that were saved.
1. Start with the project that you created in Creating and Using Annotations.
2. Edit TUTORDLG.H and insert the following lines in the definition of CTutorDlg after DECLARE_MESSAGE_MAP():
HGLOBAL m_hMem;
long m_iSize;
3. At the top of your main form, add two command buttons and name them as follows:
Name Caption
AnnSaveMem Save In Memory
AnnLoadMem Load From Memory
4. Code the AnnSaveMem button's Click procedure as follows:
void CMfc40Dlg::OnAnnSaveMem()
{
m_hMem = NULL;
if (m_Lead1.AnnSaveMemory((long FAR *)&m_hMem,
ANNFMT_NATIVE, FALSE, &m_iSize, SAVE_OVERWRITE, 0) != 0)
AfxMessageBox("Error calling AnnSaveMemory");
}
5. Code the AnnLoadMem button's Click procedure as follows:
void CMfc40Dlg::OnAnnLoadMem()
{
//Load the annotations from the memory-resident file.
if (m_Lead1.AnnLoadMemory ((OLE_HANDLE)m_hMem, m_iSize, 1) != 0)
AfxMessageBox("Error calling AnnLoadMemory");
else
AfxMessageBox("AnnLoadMemory succeeded");
::GlobalFree(m_hMem);
m_Lead1.ForceRepaint();
}
6. Run your program to test it.