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

公告

<2025年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

統計

  • 隨筆 - 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 閱讀(555) 評論(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>
            欧美午夜不卡视频| 国产乱码精品一区二区三区五月婷 | 欧美性猛交99久久久久99按摩| 国产欧美一区二区精品性色| 亚洲欧美日本日韩| 亚洲一区久久久| 国产情侣一区| 久久综合久久久久88| 久久综合色88| 亚洲精品美女在线观看播放| 欧美日韩精选| 亚洲午夜一区二区三区| 亚洲午夜女主播在线直播| 国产精品网站在线播放| 久久男女视频| 免费中文字幕日韩欧美| 亚洲视频狠狠| 久久国内精品自在自线400部| 伊人成人在线视频| 亚洲国产精品福利| 欧美人与禽猛交乱配视频| 亚洲欧美另类国产| 久久成人久久爱| 亚洲美女区一区| 亚洲一区欧美激情| 在线播放中文一区| 99视频在线精品国自产拍免费观看| 国产精品日韩二区| 欧美激情一区二区三区| 国产精品色午夜在线观看| 久久综合导航| 国产精品porn| 欧美成人中文字幕| 欧美性做爰毛片| 欧美大片免费| 国产精品一区二区三区免费观看| 欧美成人免费播放| 国产精品免费网站在线观看| 欧美激情精品久久久久久免费印度| 国产精品国产三级国产普通话三级| 麻豆91精品| 国产精品久久久久久超碰| 欧美jizz19hd性欧美| 国产精品视频xxx| 亚洲高清久久网| 国产一区二区三区在线观看视频| 亚洲人成网站影音先锋播放| 一区二区三区在线高清| 亚洲综合不卡| 在线亚洲国产精品网站| 免费h精品视频在线播放| 欧美呦呦网站| 国产精品xxxav免费视频| 欧美激情小视频| 极品少妇一区二区三区精品视频| 亚洲影视九九影院在线观看| 9色精品在线| 欧美国产精品劲爆| 欧美承认网站| 在线播放精品| 久久久www| 久久久青草婷婷精品综合日韩| 国产精品免费视频观看| 一区二区欧美亚洲| 一本色道久久加勒比精品| 男男成人高潮片免费网站| 久久在线视频在线| 韩国三级在线一区| 欧美在线免费| 老色批av在线精品| 国产专区一区| 久久久精彩视频| 美女视频网站黄色亚洲| 在线免费观看日本一区| 久久久久免费观看| 女生裸体视频一区二区三区| 亚洲国产黄色| 欧美fxxxxxx另类| 亚洲国产日韩一级| 9人人澡人人爽人人精品| 欧美日韩免费在线| 在线亚洲观看| 久久成人国产| 狠狠色伊人亚洲综合网站色| 久久久久国产精品麻豆ai换脸| 老司机精品导航| 亚洲欧洲日本mm| 欧美视频福利| 午夜精品福利在线观看| 麻豆国产精品777777在线 | 欧美a级片一区| 亚洲日本欧美天堂| 亚洲专区欧美专区| 国产一区二区三区日韩| 鲁大师成人一区二区三区 | 久久精品国产免费| 亚洲第一综合天堂另类专| 欧美精品激情| 亚洲午夜视频| 免费在线国产精品| 99国产精品久久久久久久| 国产精品久在线观看| 欧美在线一二三区| 亚洲国产美女| 欧美一区亚洲二区| 亚洲激情黄色| 国产毛片一区二区| 欧美xx69| 欧美影院在线| 亚洲精品一二区| 久久米奇亚洲| 亚洲一区二区免费| 精品不卡一区| 国产精品美腿一区在线看| 久久亚洲综合网| 亚洲无限av看| 亚洲国产毛片完整版| 久久精品午夜| 国产精品99久久久久久久女警| 国内成人在线| 国产精品久久久久77777| 嫩草影视亚洲| 久久精彩免费视频| 亚洲一区二区三区欧美 | 亚洲调教视频在线观看| 亚洲福利视频三区| 国产日韩精品综合网站| 欧美三级日韩三级国产三级| 久久这里只有| 欧美与黑人午夜性猛交久久久| 99精品视频一区| 亚洲国产你懂的| 免费国产一区二区| 久久久久久亚洲精品不卡4k岛国| 亚洲一区中文| 一本到12不卡视频在线dvd| 伊人久久大香线蕉综合热线| 国产日韩亚洲欧美综合| 国产精品美女| 欧美日韩一区二区精品| 欧美激情亚洲综合一区| 麻豆av一区二区三区久久| 久久久999精品免费| 久久er99精品| 欧美一区三区三区高中清蜜桃| 亚洲综合色在线| 亚洲一区在线免费| 亚洲一区二区精品| 国产精品99久久久久久人| 一本色道久久88综合亚洲精品ⅰ | 久久精品国产第一区二区三区| 香蕉国产精品偷在线观看不卡 | 国产一区二区丝袜高跟鞋图片| 国产日韩欧美亚洲| 国产欧美日韩在线观看| 国产一级揄自揄精品视频| 国产一区二区三区黄视频| 国产一区二区精品| 狠狠色综合网| 亚洲国产网站| 9久re热视频在线精品| 亚洲网站在线观看| 亚洲欧美在线另类| 久久精品人人爽| 久热精品视频在线观看一区| 美女视频黄免费的久久| 亚洲第一精品久久忘忧草社区| 最新日韩精品| 一区二区三区蜜桃网| 午夜欧美大尺度福利影院在线看| 久久精品国产亚洲5555| 老司机一区二区| 欧美日韩精选| 国产亚洲欧美日韩日本| 91久久久在线| 亚洲免费在线观看视频| 久久午夜av| 亚洲精品一区二区三| 亚洲欧美综合网| 久久综合色婷婷| 国产精品国内视频| 经典三级久久| 亚洲午夜精品| 免费在线欧美视频| 宅男精品视频| 乱人伦精品视频在线观看| 国产精品国产精品| 影音先锋久久久| 亚洲欧美激情一区二区| 免费欧美日韩国产三级电影| 99精品国产福利在线观看免费| 性色av一区二区三区红粉影视| 欧美好吊妞视频| 国产三级欧美三级| 日韩一级黄色片| 久久综合免费视频影院| 亚洲视频你懂的| 免费永久网站黄欧美| 国产一区二区按摩在线观看| 一级日韩一区在线观看|