回 帖 发 新 帖 刷新版面

主题:WM_NOTIFY的通知消息UDN_DELTAPOS怎么使用?

UDN_DELTAPOS
    lpnmud = (LPNMUPDOWN) lParam;

Sent by the operating system to the parent window of an up-down control when the position of the control is about to change. This happens when the user requests a change in the value by pressing the control's up or down arrow. The UDN_DELTAPOS message is sent in the form of a WM_NOTIFY message.

Return nonzero to prevent the change in the control's position, or zero to allow the change.
lpnmud
Address of an NMUPDOWN structure that contains information about the position change.
The iPos member of this structure contains the current position of the control. The iDelta member of the structure is a signed integer that contains the proposed change in position. If the user has clicked the up button, this is a positive value. If the user has clicked the down button, this is a negative value.

The UDN_DELTAPOS notification is sent before theWM_VSCROLL orWM_HSCROLL message, which actually changes the control's position. This lets you examine, allow, modify, or disallow the change.

以上是引用于MSDN帮助文件,上面说到了“This lets you examine, allow, modify, or disallow the change”和“Return nonzero to prevent the change in the control's position, or zero to allow the change”,为什么我处理UDN_DELTAPOS 通知消息时返回TRUE,值还是没有变化,没能阻止它的变化。

LPNMHDR          lpnmh;
LPNMUPDOWN     lpnmud;

……

case WM_NOTIFY:
    lpnmh = (LPNMHDR)lParam;
    switch(lpnmh->code)
    {
     case UDN_DELTAPOS:
          lpnmud = (LPNMUPDOWN)lParam;
          if(lpnmud->iPos > 20 )
              return TRUE;
          else
              return FALSE;
     }
     break;

……
各位大侠帮帮我吧,我困惑好长时间了。
[em18]

回复列表 (共5个回复)

沙发

“值还是没有变化,没能阻止它的变化。”
你这话到底在说什么?没有变==没能阻止变化?
你到底要干什么?

Return

[nonzero] ==== TRUE is nonzero, so 你应该是阻止了变化,即没有变化,不是吗?

to prevent the change in the control's position, or zero to allow the change

板凳

我的意思是:
假设上下控件的取值范围为1-100,当收到UDN_DELTAPOS通知消息时,我想取值在某个值,例如20时,再按下右箭头时控件的值不再变化,但是按上面的信息编写代码,按下右箭头时控件的值仍然在变化。

上下控件像滚动条,也会发送滚动条消息,但是上下控件的位置会自动增减,不像滚动条那样,位置要用户自己设置,不然的话拖动了滚动条或者按下了上下箭头键位置也不会变化。我想在使用上下控件能够检查位置的变化。

3 楼

那你干脆把这个控件的取值范围设成1-20不就得了?你不就是这个意思吗?

4 楼

范围是动态变化的

5 楼

问题终于搞定,修改的代码如下:

case WM_NOTIFY:
    lpnmh = (LPNMHDR)lParam;
    switch(lpnmh->code)
    {
        case UDN_DELTAPOS:
        lpnmud = (LPNMUPDOWN)lParam;
        if(lpnmud->iPos+lpnmud->iDelta>= 20 )//不能改为lpnmud->iPos
        {
            SetWindowLong(hwnd,DWL_MSGRESULT,TRUE);//必须加这句
            return TRUE;
        }
        else
       {
           return FALSE;
       }
    }
    break;

经过这次我明白了在对话框中返回TRUE或FALSE只代表是否用户处理该消息,并不代表消息的返回值,对于有返回值的消息,要用函数SetWindowLong(hwnd,DWL_MSGRESULT,value);a其中value用来设置消息返回值。

我来回复

您尚未登录,请登录后再回复。点此登录或注册