利用 GetDlgItemInt 函数如何得到 Edit Box 中的负数?

zaodt 2007-08-27 03:58:07
Edit Box 控件的 ID 为 IDC_NUMBER

Edit Box 控件中的数字为 - 100

请问,我如何获得这个 -100 ?

因为 GetDlgItemInt 的返回值为 UINT ,我不知道该如何获得?
...全文
610 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
mufc92 2011-12-17
  • 打赏
  • 举报
回复
UINT 和 int 表示范围不同,但在机器内都是补码表示。

赋值的左操作数,类型是int ,就把结果转成int;类型是UINT,结果就会转成UINT。
mufc92 2011-12-17
  • 打赏
  • 举报
回复
UINT 只是特定条件下的返回值类型,跟接收负数有关系吗?

接受负数——这个怎么理解?函数参数里也没负数呀?

MSDN看看函数说明……
mufc92 2011-12-17
  • 打赏
  • 举报
回复
上面几位有没有仔细看函数说明:

If bSigned is TRUE, GetDlgItemInt checks for a minus sign (–) at the beginning of the text and translates the text into a signed number. Otherwise, it creates an unsigned value.

是可以返回有符号的整数的。
Cricketol 2007-08-27
  • 打赏
  • 举报
回复
同意楼上两位
liuxiuk 2007-08-27
  • 打赏
  • 举报
回复
是的
计算机不认得什么数不数的
统统都是二进制
至于你怎么输出
完全在于你的控制嘛..
jasonshark 2007-08-27
  • 打赏
  • 举报
回复
呵呵,对计算机来说,这两个数没什么区别,反正它看到的最高位为1,that's enough.
你有没有在一个返回值定义为UINT的函数里返回过-1呢? 反正我经常这样写 :)
return (UINT)-1;
zaodt 2007-08-27
  • 打赏
  • 举报
回复
没有!

我就是搞不明白 为什么返回值为 UINT ,还能接收负数?

大家不要给我介绍用 GetDlgItemText + atoi 好不好?

我问的是为什么 UINT 还能接收负数的问题?
xiaoQ008 2007-08-27
  • 打赏
  • 举报
回复
问题貌似解决了!
Cricketol 2007-08-27
  • 打赏
  • 举报
回复
用getDlgItemText
然后atoi
zaodt 2007-08-27
  • 打赏
  • 举报
回复
Up
zaodt 2007-08-27
  • 打赏
  • 举报
回复
各位朋友,不好意思啊!

我就是搞不明白 为什么返回值为 UINT ,还能接收负数?
cayido 2007-08-27
  • 打赏
  • 举报
回复
getDlgItemText
atoi函数转下既可
MFC可以用CSTRING取出来再FORMAT一下
sterrys 2007-08-27
  • 打赏
  • 举报
回复
当作字符串读出来,再转成整数
livedeal 2007-08-27
  • 打赏
  • 举报
回复
CWnd::GetDlgItemInt
UINT GetDlgItemInt( int nID, BOOL* lpTrans = NULL, BOOL bSigned = TRUE ) const;

Return Value

Specifies the translated value of the dialog-box item text. Since 0 is a valid return value, lpTrans must be used to detect errors. If a signed return value is desired, cast it as an int type.

The function returns 0 if the translated number is greater than 32,767 (for signed numbers) or 65,535 (for unsigned).

When errors occur, such as encountering nonnumeric characters and exceeding the above maximum, GetDlgItemInt copies 0 to the location pointed to by lpTrans. If there are no errors, lpTrans receives a nonzero value. If lpTrans is NULL, GetDlgItemInt does not warn about errors.

Parameters

nID

Specifies the integer identifier of the dialog-box control to be translated.

lpTrans

Points to the Boolean variable that is to receive the translated flag.

bSigned

Specifies whether the value to be retrieved is signed.

Remarks

Retrieves the text of the control identified by nID. It translates the text of the specified control in the given dialog box into an integer value by stripping any extra spaces at the beginning of the text and converting decimal digits. It stops the translation when it reaches the end of the text or encounters any nonnumeric character.

If bSigned is TRUE, GetDlgItemInt checks for a minus sign (–) at the beginning of the text and translates the text into a signed number. Otherwise, it creates an unsigned value.

16,548

社区成员

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

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

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