Monday, December 29, 2003

Adobe Illustrator 10 SDK - Jpeg export of the page

How to actually do a Jpeg export.

After having found out which is the correct format name you could use this piece of code:

 

AIErr   error   = kNoErr;
AIActionParamValueRef valueParameterBlock = NULL;
ActionDialogStatus dialogStatus  = kDialogOff;
TCHAR   pszPath[255];
   
error = sAIActionManager->AINewActionParamValue(&valueParameterBlock);
ASSERT(!error );
ASSERT(valueParameterBlock);

error = sAIActionManager->AIActionSetString(valueParameterBlock, kAIExportDocumentNameKey, W2A(pszPath));
ASSERT(!error);

const char* szJPEGFileFormat = "JPEG file format";
error = sAIActionManager->AIActionSetString(valueParameterBlock, kAIExportDocumentFormatKey, szJPEGFileFormat);
ASSERT(!error);
error = sAIActionManager->AIActionSetString(valueParameterBlock, kAIExportDocumentExtensionKey, "jpg");
ASSERT(!error);

error = sAIActionManager->PlayActionEvent( kAIExportDocumentAction, dialogStatus, valueParameterBlock );
ASSERT(!error);

 

 

Adobe Illustrator 10 SDK beauties

How to find out which is the name of a particular file format.

You have to acquire the sAIFileFormat suite and then do something like this:

 

 if( sAIFileFormat )
 {
  long count = 0;
  AIErr er = sAIFileFormat->CountFileFormats(&count);
  if( !er )
  {
   for(long i = 0; i < count; i++)
   {
    AIFileFormatHandle fh = NULL;
    er = sAIFileFormat->GetNthFileFormat(i, &fh);
    if( !er )
    {
     char szName[255];

     ZeroMemory(&szName, 255);
     er = sAIFileFormat->GetFileFormatExtension(fh, szName);
     if( !er )
     {
      OutputDebugStringA(szName);
      OutputDebugStringA("\n");
     }
     if( strcmp(szName, "jpg") == 0 )
     {
      char* szNames = NULL;

      er = sAIFileFormat->GetFileFormatName(fh, &szNames);
      if( !er )
      {
       OutputDebugStringA(szNames);
       OutputDebugStringA("\n");
      }
     }
    }
   }
  }
 }

in this case I was interested in the jpeg file format (extension jpg).

 

Friday, December 19, 2003

WTL Control - message reflection

If you have a wtl control (like a CListViewCtrl or a CTreeViewCtrl) and you want to handle notify messages into that class, you should have something like this in you message map:

BEGIN_MSG_MAP(CDeriveListViewCtrl)

        REFLECTED_NOTIFY_CODE_HANDLER(LVN_COLUMNCLICK, OnColumnClick)

        DEFAULT_REFLECTION_HANDLER()

END_MSG_MAP()

LRESULT OnColumnClick(int idCtrl, LPNMHDR pNmh, BOOL& bHandled);

 

it is important that you didn't specify REFLECT_NOTIFICATIONS, otherwise messages will be sent to the wrong window.

 

Wednesday, December 17, 2003

WTL list control

I always had refresh problem with the list control, now I think I had the solution:

LRESULT CEMRecycleBinListCtrl::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)

{

// we shouldn't use begin paint to obtain the HDC,

// otherwise we will loose the update region for the parent

WTL::CDC dc = GetDC();

WTL::CRgn rgn = CreateRectRgn(0,0,0,0);

if( GetUpdateRgn(rgn) != ERROR )

{

CRect headerRC;

CRect listRC;

WTL::CBrush hbrBkgnd = CreateSolidBrush(dc.GetBkColor());

CHeaderCtrl header = GetHeader();

header.GetClientRect(&headerRC);

LVHITTESTINFO htInfo;

ZeroMemory(&htInfo, sizeof(LVHITTESTINFO));

htInfo.pt.x = 1;

htInfo.pt.y = headerRC.bottom + 1;

int idx = HitTest(&htInfo);

if( idx >= 0 )

{

CRect rc;

int count = GetCountPerPage();

if( GetItemRect(idx+count, &rc, LVIR_BOUNDS) )

{

listRC.top = headerRC.bottom;

listRC.left = rc.left + 2;

listRC.bottom = rc.bottom;

listRC.right = rc.right;

WTL::CRgn headerRgn = CreateRectRgnIndirect(headerRC);

WTL::CRgn listRgn = CreateRectRgnIndirect(listRC);

rgn.CombineRgn(listRgn, RGN_DIFF);

rgn.CombineRgn(headerRgn, RGN_DIFF);

}

}

dc.FillRgn(rgn, hbrBkgnd);

}

ReleaseDC(dc);

// we should let the parent to draw himself

bHandled = FALSE;

return 0;

} // OnPaint

 

Monday, December 15, 2003

Atl COM Controls

When you are adding window support to a windowless control you have to remember to add

m_bWindowOnly = TRUE;

In the constructor if you want your CreateControlWindow virtual function to be called.