青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

公告

<2006年11月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

統(tǒng)計(jì)

  • 隨筆 - 9
  • 文章 - 13
  • 評(píng)論 - 3
  • 引用 - 0

常用鏈接

留言簿(1)

隨筆分類

隨筆檔案

文章分類

文章檔案

搜索

  •  

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

Getting an (ATL) ActiveX control to print from Office Applications
13 votes for this article.
Popularity: 4.73. Rating: 4.25 out of 5.

Introduction

Seeing as this is my first ever post to CodeProject, let me do a quick introduction as to who I am and what I do. I have been working in one form of C and C++ or another for as long as I can remember (among the other myriad of languages that I've run into). Nowadays, most of my development is focused on Microsoft Windows platforms, and is done in VC6, VC2002.NET. I am heavily entrenched in BI (Business Intelligence) development, and in my spare time develop little ActiveX controls and games etc...

The plot

Having learnt COM a while ago, I made the obvious progression to ATL to ease the development of boilerplate code, and to leverage off Microsoft's template library. As my experience grew, I ventured into creating ActiveX controls using the ATL framework ... and life was good. I could spew out a fairly useful (albeit not overly complex) control within a short period of time. Recently, I was asked to create a KPI (Key Performance Indicator) control that could be embedded in a web page and an Excel document. Obviously based on my experience (which was obviously not vast) I thought that this would be no problem and off I went, creating code that would meet the functional spec (we all work to these don't we :)).

A couple of days later the control was finished and the final tests were being run when someone asked me to print a hardcopy of an example spreadsheet with the embedded control. This is where my nightmares began. Not only did my control not print, but there was no clear indication as to why it didn't print. And so my exploration into this apparent mystery began.

Have you ever tried to include 3rd party ActiveX controls into an Office document? They sure seem to work fine, but most (apart from the Microsoft controls) don't seem to render themselves when you request a Print Preview or a simple Print of the worksheet or document. So, if any of you have ever had this problem, or have never dabbled with this, but think that you may be heading this way, take note of this, cos it might save you hours of frustration and frantic searching on MSDN and Google.

So what now?

The first thing one needs to realize is that even though we have been blessed with Office 2000 and Office XP, the printing architecture still uses the old Windows-format metafile for its printing operations. This metafile format was used in 16-bit Windows-based applications (thinks back to Win3.1). Now, this becomes a major problem for ActiveX developers who wish their controls to be printable from within Office applications, because this old metafile format only supported a limited set of GDI functionality. The list of supported GDI functions can be found here.

Now that you are armed with your limited function set, you cringe with the realization that you can no longer create memory DC's, you can no longer use your lovely DrawText() functions and you can definitely no longer call GetTextExtentPoint32() function. However, those realizations only hold true for the instance of when your control is being rendered to an old format metafile. So how do we empower our control to know that its being rendered to an old format metafile? Simple, we use the GetObjectType() function and check if the result is equal to OBJ_METADC (old metafile format):

HRESULT Cxxxxx::OnDraw(ATL_DRAWINFO& di)
{
    HDC hdc = di.hdcDraw;
    bool bMetaFile = false;

    //// lets check if we're drawing to an old// metafile format.. (like Office printing)//if ( GetObjectType(hdc) == OBJ_METADC )
        bOldMetaFile = true;

    //// the rest of your code...//
}

For interest, the opposite of OBJ_METADC is OBJ_ENHMETADC (refer to this MSDN document).

Now that we know if we're drawing to an old metafile format or not, we can write adaptive code to cater for each instance or we can just write all our drawing logic using the limited set of functionality that is supported by the old metafile DC.

What about fonts and text extents?

As any ATL ActiveX developer knows, using fonts in AX controls provides for limited amount of fun. The typical piece of code would probably look something like this:

																//
																// ... some code
																//
    CComQIPtr<IFont, &IID_IFont> pFont(m_pFont);
    TEXTMETRICOLE tm;if ( pFont != NULL )
    {
        pFont->get_hFont(&newFont);
        pFont->AddRefHfont(newFont);
        pFont->QueryTextMetrics(&tm);
        oldFont = (HFONT) SelectObject(dc, newFont);
    }

The Bolded lines of code are ones that I didn't use regularly, due to the fact that I didn't really need to know about the breakdown of my font's details because I had access to GetTextExtentPoint32() function. Unfortunately, in this scenario, we don't have access to that function to determine how wide (in pixels) our text is going to be. But there is another way to calculate this fairly accurately, as is demonstrated in the code below:

																//
																// assume that we have called QueryTextMetrics() and
																// have a filled TEXTMETRICOLE structure called tm
																//
CComBSTR strText(_T("Hello, world"));
SIZE sz;

sz.cx = strText.Length() * tm.tmAveCharWidth;
sz.cy = tm.tmHeight;

Having said this, there are many other functions that I use a lot that I can't use if I want my ActiveX control to be printable by Office, but as with GetTextExtentPoint32() and its respective replacement, there is always a way to replace these functions using Old-Metafile-Safe-Drawing-Code (OMSDC). *maybe that acronym will catch on*

Conclusion

When creating an ActiveX control that you know will be used inside Office applications, and will most probably be printed, remember to stick to these guidelines when developing your drawing logic. I was fairly shocked by how little information was available in the MSDN and online in general, while I was searching for information on how to enable my ActiveX control to print from within an Office application. There are hundreds of documents on ActiveX controls being printed from within Internet Explorer, but none address this particular issue. Perhaps I was looking in the wrong places. Hopefully this article will help one or more of you one day ;)

Acknowledgment

Many thanks to Igor Tandetnik for pointing me in the right direction on this.

About Peter Mares

posted on 2006-11-07 17:38 blues 閱讀(547) 評(píng)論(0)  編輯 收藏 引用


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            性欧美xxxx大乳国产app| 久久久.com| 亚洲国产一区二区三区青草影视| 欧美一区二区三区的| 国产日韩欧美在线看| 久久精品一本| 久久一区激情| 亚洲精品国产品国语在线app| 亚洲国产成人午夜在线一区| 欧美精品99| 亚洲欧美日韩视频一区| 欧美一区二区三区四区在线观看地址 | 欧美一区二区三区日韩| 国产日韩亚洲| 欧美国产一区在线| 欧美日韩在线视频一区| 欧美一区二区三区在线播放| 久久精品亚洲热| 亚洲日本中文| 亚洲欧美韩国| 在线观看成人小视频| 亚洲精品一区在线观看香蕉| 国产精品午夜国产小视频| 久久这里有精品15一区二区三区| 女人天堂亚洲aⅴ在线观看| 亚洲视频在线观看三级| 欧美亚洲系列| 一本到高清视频免费精品| 亚洲欧美日产图| 亚洲电影激情视频网站| aa级大片欧美| 在线观看日韩www视频免费| 亚洲精品在线观看视频| 国内精品久久久久国产盗摄免费观看完整版| 久久一日本道色综合久久| 欧美黄色成人网| 久久久国际精品| 欧美日韩精品是欧美日韩精品| 久久精品国产清高在天天线| 欧美激情视频在线免费观看 欧美视频免费一| 亚洲一区二区伦理| 久久亚洲综合色| 欧美一区深夜视频| 欧美色视频日本高清在线观看| 久久五月天婷婷| 国产精品久久久久久久久久免费| 欧美1区视频| 国产一区91| 亚洲欧美日韩国产一区二区三区| 亚洲精选中文字幕| 久久视频一区二区| 久久久久久久久久久成人| 国产精品久久精品日日| 亚洲福利视频网站| 一区在线视频| 久久精品国产96久久久香蕉| 午夜久久久久久久久久一区二区| 欧美另类99xxxxx| 亚洲电影第1页| 樱花yy私人影院亚洲| 性做久久久久久免费观看欧美| 亚洲图片激情小说| 欧美日韩p片| 亚洲精品久久久久久下一站| 亚洲国产精品一区二区尤物区 | 欧美激情网友自拍| 影音先锋一区| 久久尤物电影视频在线观看| 久久亚洲私人国产精品va媚药| 国产区二精品视| 羞羞色国产精品| 久久国产加勒比精品无码| 国产精品一区二区久久久| 国产精品99久久久久久宅男| 亚洲综合99| 国产精品一区2区| 亚洲一区一卡| 久久精品主播| 影音先锋久久久| 欧美chengren| 亚洲免费黄色| 亚洲一区二区在线免费观看视频| 欧美视频在线观看视频极品| 亚洲一区欧美| 久久精品99| 亚洲丁香婷深爱综合| 免费成人高清在线视频| 亚洲日本无吗高清不卡| 亚洲一区二区三区精品在线观看| 国产精品毛片大码女人| 久久国产乱子精品免费女| 欧美国产日本高清在线| 国产精品99久久久久久白浆小说| 国产精品欧美久久| 久久国产精品网站| 亚洲欧洲精品一区二区三区不卡 | 一本色道久久| 国产欧美在线播放| 美女国产精品| 亚洲手机成人高清视频| 久久综合婷婷| 亚洲免费久久| 国产亚洲欧美一区二区| 欧美大片免费久久精品三p| 一本色道久久| 欧美成人国产va精品日本一级| 一本到高清视频免费精品| 国产一区二区欧美日韩| 欧美精品成人| 欧美一区二区在线免费播放| 亚洲精品五月天| 久久久人成影片一区二区三区观看| 亚洲人成在线播放| 国产综合色在线视频区| 欧美日韩蜜桃| 久久亚洲精品网站| 亚洲午夜在线观看| 亚洲第一精品久久忘忧草社区| 欧美亚洲视频一区二区| 日韩午夜精品视频| 精品96久久久久久中文字幕无| 欧美视频一区二区三区…| 久久久久久一区| 欧美亚洲在线观看| 宅男噜噜噜66一区二区66| 欧美激情视频免费观看| 久久男女视频| 久久精品欧美| 午夜精品网站| 亚洲一区不卡| 99日韩精品| 亚洲人成网站精品片在线观看| 国产一区二区中文字幕免费看| 国产精品久久久久久久浪潮网站| 欧美极品影院| 女女同性女同一区二区三区91| 久久精品视频99| 午夜精品理论片| 亚洲专区在线视频| 亚洲一品av免费观看| 一本大道久久精品懂色aⅴ| 最新国产精品拍自在线播放| 欧美高清在线一区二区| 欧美xart系列在线观看| 欧美成人高清视频| 欧美激情视频在线免费观看 欧美视频免费一 | 久久精品一区二区三区不卡牛牛 | 欧美一区二区三区四区在线观看地址 | 国产一区二区视频在线观看| 国产精品免费一区豆花| 国产精品乱人伦一区二区| 国产精品久久久久高潮| 国产精品久久久久久久久免费桃花| 欧美日本韩国一区| 欧美日韩国产综合视频在线观看| 欧美成人综合一区| 欧美久久久久久| 欧美午夜三级| 国产精品无码永久免费888| 国产精品亚洲一区| 国产亚洲精品美女| 一区二区三区在线免费视频| 亚洲成人资源网| 亚洲美女精品一区| 亚洲网友自拍| 久久国产福利| 欧美丰满少妇xxxbbb| 亚洲精品一区久久久久久| 国产精品99久久久久久久vr| 午夜精品福利一区二区三区av| 久久久久99| 欧美理论电影在线播放| 国产精品久久一区二区三区| 韩国精品久久久999| 亚洲日韩成人| 欧美一级专区| 亚洲国产精品久久久久婷婷884| 亚洲精品婷婷| 欧美一区二区三区日韩| 欧美成人在线网站| 国产精品色在线| 亚洲国产成人不卡| 午夜欧美大尺度福利影院在线看| 久久精品一区二区| 亚洲精品在线三区| 久久精品一区二区三区四区| 欧美—级在线免费片| 国产亚洲女人久久久久毛片| 日韩午夜激情av| 久久一区二区三区国产精品 | 久久国产视频网站| 亚洲日本一区二区| 久久av一区| 欧美日韩免费一区二区三区| 国内外成人在线| 新片速递亚洲合集欧美合集| 亚洲国产欧美另类丝袜| 久久国产精品网站| 国产伦精品一区二区三区照片91| 亚洲久久一区|