AnnEncryptApply example for C++ 5 and later
// This example takes a handle to an annotation object that is an encryptor, and does the following
//' 1. Verifies that it is an encryptor that is associated with a bitmap
//' 2. changes the key to 123
//' 3. Applies the encryptor so that it changes state to a decryptor
//' 4. Prompts the user to continue
//' 5. Removes the scrambling by applying the decryptor
void CTutorDlg::ExampleEncrypter(long hObject)
{
AnnObjectType ObjectType;
L_INT nRet;
m_pRasterAnn->AnnGetType(hObject);
ObjectType = m_pRasterAnn->GetAnnType();
if (ObjectType != ANN_OBJECT_ENCRYPT)
MessageBox (TEXT("This Object is not an Encrypt Object"));
m_pRasterAnn->AnnEncryptOptions->Flags = ANN_ENCRYPT_ALL;
m_pRasterAnn->AnnGetEncryptOptions (hObject);
if (m_pRasterAnn->AnnEncryptOptions->EncryptRaster == NULL)
{
MessageBox(TEXT("The encrypt object is not associated with a bitmap."));
Return ;
}
if (m_pRasterAnn->AnnEncryptOptions->EnableEncryptor == FALSE)
MessageBox(TEXT("This object is a decryptor"));
m_pRasterAnn->AnnEncryptOptions->Key = 123;
m_pRasterAnn->AnnEncryptOptions->Flags = ANN_ENCRYPT_KEY;
m_pRasterAnn->AnnEncryptOptions->EnableSaveDecryptorKey = TRUE;
m_pRasterAnn->AnnEncryptOptions->EnableSaveEncryptorKey = TRUE;
m_pRasterAnn->AnnEncryptOptions->EnableClearDecryptorKey = TRUE;
m_pRasterAnn->AnnEncryptOptions->EnableClearEncryptorKey = TRUE;
m_pRasterAnn->AnnEncryptOptions->EnableNeverEncrypted = FALSE;
m_pRasterAnn->Flags = 0;
m_pRasterAnn->AnnSetEncryptOptions(hObject);
m_pRasterAnn->AnnEncryptApply(hObject, ANN_ENCRYPTAPPLY_ENCRYPTOR);
nRet = MessageBox(TEXT("Encryptor has been applied-> Would you like to remove the encryption?"), TEXT(""), MB_YESNO);
if (nRet == IDYES)
m_pRasterAnn->AnnEncryptApply (hObject, ANN_ENCRYPTAPPLY_DECRYPTOR);
}