带有菜单栏的顶级窗口的GetDlgCtrlID-返回值 [英] GetDlgCtrlID for top-level window with menu bar - return value

查看:152
本文介绍了带有菜单栏的顶级窗口的GetDlgCtrlID-返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSDN->"GetDlgCtrlID函数"->备注: "...如果hwndCtl是顶级窗口的句柄,则GetDlgCtrlID可能返回一个值,但是顶级窗口不能具有标识符,并且这样的返回值永远无效."

MSDN -> "GetDlgCtrlID function" -> Remarks: "... Although GetDlgCtrlID may return a value if hwndCtl is a handle to a top-level window, top-level windows cannot have identifiers and such a return value is never valid."

这似乎是错误的信息-永远无效".

It seems it is wrong information - "never valid".

至少对于Win2k ... Win8,此返回值只是指向hmenu(bar)的内核指针.

At least for Win2k...Win8 this return value is just kernel pointer to hmenu(bar).

我的问题是(主要针对MS内部人员):为什么MSDN在这里如此不准确?

And my question is (primarily to MS insiders): why MSDN so inaccurate here?

(屏幕截图: http://files.rsdn.ru/42164 /gwl(-1)_tagwnd.png )

已更新(tagWND):

Upd (tagWND):

还演示: http://files.rsdn.ru/42164 /gwl(-1)_tagwnd.zip

推荐答案

这并不准确.您使用CreateWindowEx()创建一个顶层窗口.看起来像这样:

It is not inaccurate. You create a top-level window with CreateWindowEx(). Which looks like this:

HWND WINAPI CreateWindowEx(
  _In_      DWORD dwExStyle,
  _In_opt_  LPCTSTR lpClassName,
  _In_opt_  LPCTSTR lpWindowName,
  _In_      DWORD dwStyle,
  _In_      int x,
  _In_      int y,
  _In_      int nWidth,
  _In_      int nHeight,
  _In_opt_  HWND hWndParent,
  _In_opt_  HMENU hMenu,
  _In_opt_  HINSTANCE hInstance,
  _In_opt_  LPVOID lpParam
);

请注意如何不在任何地方指定ID.但是精美的字样在hMenu参数的描述中:

Note how you don't specify the ID anywhere. But the fine print is in the description for the hMenu argument:

菜单句柄,或根据窗口样式指定子窗口标识符.对于重叠窗口或弹出窗口,hMenu标识要与该窗口一起使用的菜单;如果要使用类菜单,则可以为NULL.对于子窗口,hMenu指定子窗口标识符,该值是对话框控件用来通知其父项有关事件的整数值.应用程序确定子窗口标识符;对于具有相同父窗口的所有子窗口,它必须是唯一的.

A handle to a menu, or specifies a child-window identifier, depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used. For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.

因此您可以拥有一个菜单或一个子ID.重载,在winapi中很常见,子控件不能有菜单,顶层窗口不能有子ID.如果您不顾一切地继续前进而忽略它,并且无论如何都在顶层窗口上调用GetDlgCtrlID(),那么您取回您在create调用中指定的hMenu参数的值.好吧,今天,请始终遵循api,否则有一天您可能会感到无礼,您当然可以使用GetMenu()来代替.

So you can have a menu OR a child ID. Overloaded, pretty common in the winapi, a child control can't have a menu and a toplevel window can't have a child ID. If you forge ahead and ignore this and call GetDlgCtrlID() on a toplevel window anyway then you will get back the value of the hMenu argument you specified in the create call. Well, today, always follow the api or you might get a rude surprise some day, you'd of course use GetMenu() instead.

这篇关于带有菜单栏的顶级窗口的GetDlgCtrlID-返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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