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

公告

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

統計

  • 隨筆 - 9
  • 文章 - 13
  • 評論 - 3
  • 引用 - 0

常用鏈接

留言簿(1)

隨筆分類

隨筆檔案

文章分類

文章檔案

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

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) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   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>
            亚洲一区久久久| 欧美一区二区三区视频免费| 免费亚洲电影在线| 亚洲国产精品尤物yw在线观看| 久久久亚洲一区| 久久久www成人免费毛片麻豆| 精品av久久久久电影| 欧美 日韩 国产一区二区在线视频| 久久婷婷综合激情| 日韩午夜一区| 亚洲一区网站| 136国产福利精品导航网址应用 | 玉米视频成人免费看| 欧美激情一区二区三区在线视频观看 | 亚洲精品乱码久久久久久久久| 欧美福利在线观看| 欧美日本在线一区| 欧美一级视频精品观看| 久久国产精品一区二区| 亚洲精品你懂的| 亚洲欧美一区二区激情| 亚洲国产视频直播| 99精品视频免费全部在线| 国产一区二区在线观看免费| 亚洲国产精品专区久久| 国产精品久久久爽爽爽麻豆色哟哟| 久久美女性网| 欧美日韩免费在线| 久久一区二区三区av| 欧美日韩国产综合网| 久久久xxx| 国产精品第一区| 欧美激情亚洲| 国产一区二区欧美| 夜夜夜久久久| 亚洲卡通欧美制服中文| 久久av二区| 欧美亚洲三级| 欧美日韩亚洲激情| 欧美激情亚洲| 在线观看欧美一区| 欧美一区二区啪啪| 亚洲天堂第二页| 欧美高清视频www夜色资源网| 欧美在线观看一区二区| 欧美日韩午夜精品| 亚洲成人资源网| 午夜一区在线| 欧美福利电影网| 欧美成人一二三| 国产一区在线看| 亚洲欧美日韩天堂一区二区| 99亚洲视频| 欧美黄色一区二区| 欧美成人精品在线观看| 国内免费精品永久在线视频| 亚洲一区二区三区视频| 亚洲一区二区三区四区中文| 欧美屁股在线| 亚洲精品在线三区| 亚洲精品精选| 欧美理论电影网| 日韩亚洲精品在线| 亚洲视频一区在线| 国产精品大片wwwwww| 中文久久精品| 性色av一区二区三区在线观看 | 欧美一区二区三区播放老司机 | 亚洲乱码国产乱码精品精98午夜| 久久一区二区精品| 免费av成人在线| 亚洲国产老妈| 欧美精彩视频一区二区三区| 亚洲国产精品黑人久久久| 亚洲精品乱码久久久久久日本蜜臀| 老司机一区二区三区| 亚洲国产精品高清久久久| 亚洲免费大片| 国产精品成人在线| 欧美一区二区三区在线免费观看 | 亚洲国产专区校园欧美| 欧美电影打屁股sp| 一本色道久久综合| 欧美一二三视频| 一区在线观看| 欧美国产丝袜视频| 亚洲视频自拍偷拍| 久久久久久婷| 亚洲国产美国国产综合一区二区| 欧美精品成人| 午夜精品视频| 亚洲欧洲美洲综合色网| 亚洲主播在线| 影音先锋亚洲视频| 欧美日韩国产免费| 性欧美精品高清| 亚洲国产精品小视频| 亚洲影院色无极综合| 狠狠噜噜久久| 国产精品va在线播放| 欧美一区日韩一区| 亚洲精品乱码| 久久久欧美一区二区| 99精品99久久久久久宅男| 国产日韩欧美不卡| 欧美高清视频一区二区| 欧美亚洲日本一区| 亚洲国内欧美| 久热国产精品| 小处雏高清一区二区三区| 亚洲国产精品国自产拍av秋霞| 国产精品久久久久9999吃药| 蜜乳av另类精品一区二区| 亚洲小视频在线| 亚洲国产乱码最新视频| 久久精品电影| 午夜日韩在线| 中文欧美日韩| 亚洲黄色在线| 韩国成人理伦片免费播放| 国产精品扒开腿做爽爽爽视频| 久久午夜羞羞影院免费观看| 午夜精品久久久久久久| 一级成人国产| 亚洲精品专区| 亚洲欧洲一区二区在线播放 | 亚洲视频精选在线| 亚洲精品影院| 亚洲电影一级黄| 国产一区二区三区免费观看| 国产精品久久久久久五月尺| 欧美激情黄色片| 欧美成人精品高清在线播放| 久久免费国产| 久久国产色av| 久久精品国产精品亚洲综合| 亚洲午夜激情网页| 亚洲一区二区黄| 亚洲视屏一区| 亚洲综合电影| 午夜精品久久久久久久久久久久久 | 亚洲无线一线二线三线区别av| 亚洲欧洲日本国产| 亚洲欧洲另类国产综合| 亚洲国产老妈| 亚洲美女黄色| 99综合在线| 亚洲一区二区成人在线观看| 亚洲视频网站在线观看| 亚洲一区在线播放| 先锋亚洲精品| 久久久噜噜噜久久中文字幕色伊伊| 欧美在线视屏| 美女视频黄免费的久久| 欧美成人免费一级人片100| 欧美国产视频日韩| 亚洲精品视频免费| 99精品热视频| 午夜国产精品影院在线观看| 欧美中文字幕在线播放| 久久免费一区| 欧美精品18+| 欧美日韩视频在线| 国产欧美日韩综合精品二区| 精品av久久707| 亚洲精品资源| 欧美一区在线视频| 欧美成人一区二区三区| 亚洲精品国产视频| 午夜欧美精品| 欧美福利视频在线| 国产精品美女www爽爽爽| 国产亚洲午夜| 99国产精品私拍| 久久久国产成人精品| 亚洲电影下载| 欧美亚洲一区二区三区| 欧美fxxxxxx另类| 国产美女扒开尿口久久久| 亚洲承认在线| 亚洲网在线观看| 久久精品一区二区| 亚洲精选91| 久久精品国产第一区二区三区最新章节 | 免费人成精品欧美精品| 国产精品对白刺激久久久| 黄网站免费久久| 亚洲欧美激情四射在线日| 欧美成人午夜激情在线| 亚洲视频1区| 欧美久久久久免费| 精品电影在线观看| 欧美夜福利tv在线| 亚洲精品美女在线| 久久天天躁狠狠躁夜夜爽蜜月| 国产精品成人观看视频免费 | 午夜精品久久久久久久99黑人| 欧美成人dvd在线视频| 亚洲欧美日韩第一区| 欧美日韩国产一区二区|