咨询一个对话框回调函数的有关问题
咨询一个对话框回调函数的问题
老MSDN上这么定义:
BOOL CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);
对应的返回值是:
Except in response to the WM_INITDIALOG message, the dialog box procedure should return nonzero if it processes the message, and zero if it does not. In response to a WM_INITDIALOG message, the dialog box procedure should return zero if it calls the SetFocus function to set the focus to one of the controls in the dialog box. Otherwise, it should return nonzero, in which case the system sets the focus to the first control in the dialog box that can be given the focus.
而新MSDN上这么定义:
INT_PTR CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);
对应返回值:
Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not. If the dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response to the message.
发现好像采取窗口过程这样的方式也可以:
LRESULT CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);
=====================================
问题一:我用VC2003,那我应该采取哪种方式最好?BOOL?INT_PTR?LRESULT?
问题二:新版MSDN,为何INT_PTR,对应的返回值却是TRUE/FALSE,而老版MSDN中,为何BOOL对应的返回值却是zero/nonzero ?
------解决方案--------------------
用BOOL较好,我一直在用。简单,易操作
至于返回值,我觉得新版本的好一些,
旧的没用过.
------解决方案--------------------
新的没有试过,但是还是习惯用LRESULT。返回值感觉倒无所谓
------解决方案--------------------
1.两种方法都可以
2.是新版的对老板的改进。
老板是zero/nonzero,即0或非0;
新版做了严格的规定,即TRUE和FALSE两个值
------解决方案--------------------
问题二,
bool型也就是年int型,它们占用的字节数相同.都是4个字节.0就是False,1就是True.
------解决方案--------------------
BOOL?INT_PTR?LRESULT?
BOOL和LRESULT应该是一样的。INT_PTR我没用过,不过这些类型可能都是同一个类型,都是DWORD,在一些头文件用#define 从新定义了一下。尤其注意:BOOL和bool不是一回事,TRUE和true也不是一回事,你没事时看一些编译器自带的头文件就明白了。
------解决方案--------------------
没什么严格要求,你会发现头文件对什么LREUSLT BOOL INT_PTR的定义都是一样的,虽然说留有扩展的余地,其实我看微软很难有天翻地覆的扩展。
------解决方案--------------------
这些不过是一些宏定义而已,又不是什么新的类型,用什么都行。看一下头文件就明白。
老MSDN上这么定义:
BOOL CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);
对应的返回值是:
Except in response to the WM_INITDIALOG message, the dialog box procedure should return nonzero if it processes the message, and zero if it does not. In response to a WM_INITDIALOG message, the dialog box procedure should return zero if it calls the SetFocus function to set the focus to one of the controls in the dialog box. Otherwise, it should return nonzero, in which case the system sets the focus to the first control in the dialog box that can be given the focus.
而新MSDN上这么定义:
INT_PTR CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);
对应返回值:
Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not. If the dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response to the message.
发现好像采取窗口过程这样的方式也可以:
LRESULT CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);
=====================================
问题一:我用VC2003,那我应该采取哪种方式最好?BOOL?INT_PTR?LRESULT?
问题二:新版MSDN,为何INT_PTR,对应的返回值却是TRUE/FALSE,而老版MSDN中,为何BOOL对应的返回值却是zero/nonzero ?
------解决方案--------------------
用BOOL较好,我一直在用。简单,易操作
至于返回值,我觉得新版本的好一些,
旧的没用过.
------解决方案--------------------
新的没有试过,但是还是习惯用LRESULT。返回值感觉倒无所谓
------解决方案--------------------
1.两种方法都可以
2.是新版的对老板的改进。
老板是zero/nonzero,即0或非0;
新版做了严格的规定,即TRUE和FALSE两个值
------解决方案--------------------
问题二,
bool型也就是年int型,它们占用的字节数相同.都是4个字节.0就是False,1就是True.
------解决方案--------------------
BOOL?INT_PTR?LRESULT?
BOOL和LRESULT应该是一样的。INT_PTR我没用过,不过这些类型可能都是同一个类型,都是DWORD,在一些头文件用#define 从新定义了一下。尤其注意:BOOL和bool不是一回事,TRUE和true也不是一回事,你没事时看一些编译器自带的头文件就明白了。
------解决方案--------------------
没什么严格要求,你会发现头文件对什么LREUSLT BOOL INT_PTR的定义都是一样的,虽然说留有扩展的余地,其实我看微软很难有天翻地覆的扩展。
------解决方案--------------------
这些不过是一些宏定义而已,又不是什么新的类型,用什么都行。看一下头文件就明白。