正确使用GetClipRgn? [英] correct usage of GetClipRgn?

查看:139
本文介绍了正确使用GetClipRgn?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个函数,需要在DC上设置剪切区域,但是在DC上还原任何现有的剪切区域。

I want to write a function that needs to set the clipping region on a DC but restore any existing clipping region on the DC when it is done.

找到 GetClipRgn 听起来像我想要的,但似乎混乱。我找不到任何使用它的例子,Petzold没有提供任何东西。

So I found GetClipRgn which sounds like exactly what I want but seems confusing. I couldn't find any examples of using it and Petzold had nothing to offer.

我想出的是:

void DrawStuff( HDC hDC )
{
    HRGN restoreRegion = CreateRectRgn( 0, 0, 0, 0 );
    if (GetClipRgn( hDC, restoreRegion ) != 1)
    {
        DeleteObject( restoreRegion );
        restoreRegion = NULL;
    }

    // 
    // Set new region, do drawing
    //

    SelectClipRgn( hDC, restoreRegion );
    if (restoreRegion != NULL)
    {
        DeleteObject( restoreRegion );
    }
}

看起来很奇怪,我需要创建一个区域以获得当前区域。

It just seems weird that I need to create a region in order to get the current region.

这是否是正确的用法?

相同的效果?

推荐答案

对于正确答案最接近的事情是Hans Passant的评论:

Well the closest thing to a correct answer is Hans Passant's comment:


是的,这是一个奇怪的函数。您的代码看起来不错。

Yeah, it's a weird function. Your code looks okay.

这篇关于正确使用GetClipRgn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆