我用CreateWindowEx创建了一个按钮,但是在很多消息处理中我都需要检测它的ID,我怎么检查,如:在WM_DRAWITEM这个消息中WAPRAM就是control identifier,那我创建的按钮ID是多少呀,不然我就没法去和它比较了。

解决方案 »

  1.   

    不要急,看看CreateWindowEx的声明
    HWND CreateWindowEx(
      DWORD dwExStyle,      // extended window style
      LPCTSTR lpClassName,  // pointer to registered class name
      LPCTSTR lpWindowName, // pointer to window name
      DWORD dwStyle,        // window style
      int x,                // horizontal position of window
      int y,                // vertical position of window
      int nWidth,           // window width
      int nHeight,          // window height
      HWND hWndParent,      // handle to parent or owner window
      HMENU hMenu,          // handle to menu, or child-window identifier
      HINSTANCE hInstance,  // handle to application instance
      LPVOID lpParam        // pointer to window-creation data
    );现在应该清楚了,你的控件ID就是原来菜单句柄的位置,ID是自己设置
    应该这样定义hwndCtrl=CreateWindowEx(...,HMENU(自己设置ID,1...n都,但是不能和其他的ID相同),...);
      

  2.   

    试试使用GetWindowLong( hWnd , GWL_ID )以取得ID,其中的hWnd即为你使用CreateWindowEx创建的窗口的句柄。