为什么找不到GetRandomRgn的定义?

Sime507 2004-05-12 10:20:16
我写的程序编译错误提示:
E:\PROGRAME\WORK\SY\Sy1\Sy1View.cpp(64) : error C2065: 'GetRandomRgn' : undeclared identifier
E:\PROGRAME\WORK\SY\Sy1\Sy1View.cpp(64) : error C2065: 'SYSRGN' : undeclared identifier

我已经在源代码中包含了"windows.h"文件。
...全文
138 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sime507 2004-05-13
  • 打赏
  • 举报
回复
谢谢 happyparrot(快乐鹦鹉) 、Mackz(在相互) ,问题已经解决了,VC6里面的WinGdi.h文件没有这个函数,在线升级SDK,升级程序没有将新的SDK目录添加到VC工程里面,所以事实上使用的还是老版本的WinGdi.h,手工添加并调整顺序就可以了!

结贴!
Sime507 2004-05-13
  • 打赏
  • 举报
回复
我电脑上不行! 我用VC向导生成单文档程序,然后把OnDraw改成:
void CSy1View::OnDraw(CDC* pDC)
{
CSy1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
HRGN hrgn;
GetRandomRgn(GetDC()->GetSafeHdc(), hrgn, SYSRGN);
}

编译结果:
--------------------Configuration: Sy1 - Win32 Debug--------------------
Compiling...
Sy1View.cpp
E:\PROGRAME\WORK\SY\Sy1\Sy1View.cpp(66) : error C2065: 'GetRandomRgn' : undeclared identifier
E:\PROGRAME\WORK\SY\Sy1\Sy1View.cpp(66) : error C2065: 'SYSRGN' : undeclared identifier
Error executing cl.exe.

Sy1.exe - 2 error(s), 0 warning(s)
Sime507 2004-05-12
  • 打赏
  • 举报
回复
MSDN里面也有:

GetRandomRgn
The GetRandomRgn function copies the system clipping region of a specified device context to a specific region.

int GetRandomRgn(
HDC hdc, // handle to DC
HRGN hrgn, // handle to region
INT iNum // must be SYSRGN
);
Parameters
hdc
[in] Handle to the device context.
hrgn
[in] Handle to a region. Before the function is called, this identifies an existing region. After the function returns, this identifies a copy of the current system region. The old region identified by hrgn is overwritten.
iNum
[in] This parameter must be SYSRGN.
Return Values
If the function succeeds, the return value is 1. If the function fails, the return value is –1. If the region to be retrieved is NULL, the return value is 0.

Remarks
When using the SYSRGN flag, note that the system clipping region might not be current because of window movements. Nonetheless, it is safe to retrieve and use the system clipping region within the BeginPaint-EndPaint block during WM_PAINT processing. In this case, the system region is the intersection of the update region and the current visible area of the window. Any window movement following the return of GetRandomRgn and before EndPaint will result in a new WM_PAINT message. Any other use of the SYSRGN flag may result in painting errors in your application.

Windows NT/2000/XP: The region returned is in screen coordinates.

Windows 95/98/Me: The region returned is in window coordinates.

Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Wingdi.h; include Windows.h.
Library: Use Gdi32.lib.
Sime507 2004-05-12
  • 打赏
  • 举报
回复
《Windows图形编程》第5章的例子,程序名叫WinPaint。

void KMyCanvas::OnDraw(HDC hDC, const RECT * rcPaint)
{
RECT rect;

GetClientRect(m_hWnd, & rect);

GetRandomRgn(hDC, m_hRegion, SYSRGN);

POINT Origin;
GetDCOrgEx(hDC, & Origin);

if ( ((unsigned) hDC) & 0xFFFF0000 )
OffsetRgn(m_hRegion, - Origin.x, - Origin.y);

......................
}
快乐鹦鹉 2004-05-12
  • 打赏
  • 举报
回复
我找遍了也没有发现你说的这个函数。没写错吧?你把你找到的贴出来给我看看
Sime507 2004-05-12
  • 打赏
  • 举报
回复
Sime507 2004-05-12
  • 打赏
  • 举报
回复
哇,楼上的信誉值到了138,酷!
Sime507 2004-05-12
  • 打赏
  • 举报
回复
MSDN里面的资料:
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Wingdi.h; include Windows.h.
Library: Use Gdi32.lib.
快乐鹦鹉 2004-05-12
  • 打赏
  • 举报
回复
这个函数不是windows.h中定义的啊。我找了一下,这个函数是你自己定义的吗?
菜牛 2004-05-12
  • 打赏
  • 举报
回复
为了确认,我试了一下:
HRGN hrgn;
GetRandomRgn(GetDC()->GetSafeHdc(), hrgn, SYSRGN);
除了报hrgn没有初始化:
warning C4700: 使用的局部变量“hrgn”尚未初始化
生成: 1 已成功, 0 已失败, 0 已跳过
Sime507 2004-05-12
  • 打赏
  • 举报
回复
可是,我的问题还没解决啊!
PS:我已经在线升级了我的SDK,实在想不出还有什么问题!
555555~~~~~~
快乐鹦鹉 2004-05-12
  • 打赏
  • 举报
回复
哈哈,我也不知道是那一年的。反正没找到。你们找到也行啊。
Sime507 2004-05-12
  • 打赏
  • 举报
回复
呵呵,不至于吧!
菜牛 2004-05-12
  • 打赏
  • 举报
回复
快乐鹦鹉,你用的是91年的MSDN吧?


好像那时候还没有:)

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧