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

公告

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

統(tǒng)計(jì)

  • 隨筆 - 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 閱讀(542) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發(fā)表評論。
網(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>
            久久亚洲色图| 亚洲高清视频中文字幕| 亚洲欧美日韩久久精品 | 欧美xxx在线观看| 亚洲一区免费看| 欧美日韩在线播放| 久久精品天堂| 一区二区三区免费网站| 免费成人毛片| 久久精品免费电影| 国内精品伊人久久久久av影院| 亚洲欧美清纯在线制服| 亚洲欧洲精品一区二区| 欧美金8天国| 一区二区三区成人精品| 亚洲日本成人女熟在线观看| 欧美激情亚洲| 亚洲五月六月| 亚洲性图久久| 国产情人综合久久777777| 久久高清国产| 久久久福利视频| 亚洲欧洲一区二区天堂久久| 欧美国产一区二区| 欧美激情第1页| 亚洲一区二区三区高清不卡| 亚洲图片在区色| 国产性色一区二区| 久色成人在线| 欧美精品日韩精品| 性欧美xxxx视频在线观看| 亚洲欧美日韩直播| 尹人成人综合网| 亚洲国产婷婷| 国产精品看片资源| 免费试看一区| 欧美视频一区二区三区四区| 欧美在线视频不卡| 另类激情亚洲| 午夜免费日韩视频| 久久午夜电影| 亚洲免费在线视频| 久久久久久亚洲精品中文字幕| 欧美国产一区二区| 欧美精品一区二区视频 | 91久久精品一区二区三区| 欧美视频久久| 久久综合久色欧美综合狠狠| 欧美另类专区| 久久综合国产精品台湾中文娱乐网 | 亚洲午夜激情在线| 狠狠干狠狠久久| 99国产精品私拍| 国产一区欧美日韩| 一区二区三区高清| 亚洲成色www8888| 亚洲综合色网站| 99精品福利视频| 久久久久久穴| 欧美专区第一页| 欧美深夜福利| 亚洲第一黄色网| 黄色成人av| 午夜激情亚洲| 校园激情久久| 欧美亚洲视频| 亚洲精品久久久久久久久久久| 一区二区三区久久精品| 亚洲电影专区| 欧美一区二区三区喷汁尤物| 一区二区免费在线观看| 久久免费精品日本久久中文字幕| 亚洲影视九九影院在线观看| 另类成人小视频在线| 久久精品视频va| 国产精品伦子伦免费视频| 亚洲人成7777| 91久久国产自产拍夜夜嗨| 久久精品国产99| 久久国产免费| 国产精品一区二区欧美| 一本久久综合亚洲鲁鲁| 一本色道久久综合狠狠躁篇的优点 | 亚洲国产一区二区三区高清| 午夜精品www| 欧美亚洲在线播放| 国产精品国色综合久久| 亚洲久久成人| 亚洲午夜精品在线| 欧美日韩一区二区三区| 亚洲精品乱码久久久久久| 日韩午夜一区| 欧美日韩午夜在线| 夜色激情一区二区| 午夜精品在线看| 国产日韩欧美综合| 久久成人羞羞网站| 久久久综合免费视频| 亚洲欧美另类中文字幕| 亚洲在线观看| 国产精品一区二区你懂得| 午夜精品福利视频| 久久久av网站| 在线观看日韩专区| 欧美高清视频在线| 99国产精品99久久久久久| 亚洲影院高清在线| 国产精品一区二区女厕厕| 欧美一区二区三区免费视| 玖玖视频精品| 亚洲精品欧美精品| 欧美日韩一区在线视频| 亚洲欧美成人精品| 欧美成人一品| 一区二区三区日韩欧美精品| 国产精品一二三视频| 久久在线免费观看| 亚洲美女在线一区| 久久精品日韩欧美| 亚洲精品一级| 国产精品一区二区久久久久| 久久先锋资源| 中文国产成人精品| 男人的天堂亚洲| 亚洲永久免费精品| 韩日视频一区| 欧美视频一区二区三区在线观看| 欧美在线地址| 亚洲另类自拍| 久久躁狠狠躁夜夜爽| 在线视频欧美精品| 久久高清免费观看| 亚洲激情在线观看| 性亚洲最疯狂xxxx高清| 亚洲国产成人在线| 欧美日韩综合视频网址| 欧美一区亚洲二区| 亚洲精品欧美精品| 久久精品国产一区二区三区免费看| 亚洲国产精品久久久久婷婷老年 | 亚洲图片在线观看| 欧美成人中文| 欧美中文在线字幕| 亚洲日本中文| 国产欧美日韩综合精品二区| 欧美福利视频在线观看| 久久精品日韩一区二区三区| 99视频超级精品| 欧美国产高潮xxxx1819| 久久精品国产77777蜜臀| 亚洲视频欧美在线| 亚洲精品国产精品国自产在线| 国产视频欧美| 国产精品国产三级国产专区53 | 免费久久精品视频| 香蕉av福利精品导航| 99视频国产精品免费观看| 在线免费观看成人网| 国产人成一区二区三区影院| 国产精品高潮呻吟久久av黑人| 欧美国产第一页| 美女尤物久久精品| 久久深夜福利| 久久综合九色综合欧美就去吻| 欧美一区二视频在线免费观看| 亚洲字幕一区二区| 亚洲一区在线看| 亚洲影院免费| 午夜国产一区| 久久av红桃一区二区小说| 亚洲欧美日韩精品久久| 亚洲调教视频在线观看| 亚洲午夜久久久久久尤物| 一区二区三区不卡视频在线观看 | 99精品视频免费观看视频| 亚洲国产视频一区二区| 在线成人av| 亚洲激情视频在线观看| 亚洲欧洲日本专区| 日韩视频亚洲视频| 一本色道久久综合狠狠躁篇的优点 | 亚洲人成在线观看| 亚洲精品极品| 亚洲毛片在线看| 99国内精品| 亚洲欧洲精品一区| 蜜乳av另类精品一区二区| 久久嫩草精品久久久精品一| 久久久久久久97| 免费av成人在线| 欧美精品日韩一区| 欧美日韩国产麻豆| 国产精品黄色在线观看| 国产毛片一区二区| 含羞草久久爱69一区| 亚洲国产精品成人综合| 999亚洲国产精| 香蕉成人伊视频在线观看| 久久亚洲精品一区二区| 亚洲国产欧美在线|