我想得到一个对话框的ID,代码如下:
void CTestDlg::OnButton1() 
{
// TODO: Add your control notification handler code here
long nID = GetWindowLong(m_hWnd, GWL_ID);
DWORD dwError = GetLastError();
CString str;
str.Format("对话框ID为 %d",nID);
AfxMessageBox(str);
}调试时发现nID值为0;dwError 的值也为0。
什么意思?
还有就是他返回的ID应该是IDD_DIALOG1被预定义的数吧?
新手,望赐教!

解决方案 »

  1.   

    没问题啊,我用你的代码,VS2008测试有ID值...
      

  2.   

    况且你说的情况和MSDN似乎矛盾
    Return Values
    The requested 32-bit value indicates success. Zero indicates failure. To get extended error information, call GetLastErrorGetWindowLong返回0表示失败,那么GetLastError肯定不会返回0啊
      

  3.   

    GWL_EXSTYLE Retrieves the extended window styles. 
    GWL_STYLE Retrieves the window styles. 
    GWL_WNDPROC Retrieves the address of the window procedure, or a handle representing the address of the window procedure. You must use the CallWindowProc function to call the window procedure. 
    GWL_ID Not supported. GWL_USERDATA Not supported. 
      

  4.   

    windows对一个不支持的东西进行处理,应该返回0,但是这个0却不是因为发生错误导致,这可能就是出现况且你说的情况和MSDN似乎矛盾
    Return Values
    The requested 32-bit value indicates success. Zero indicates failure. To get extended error information, call GetLastErrorGetWindowLong返回0表示失败,那么GetLastError肯定不会返回0啊
    的问题
      

  5.   


    至于这个为何会出现,可能是Vs2008默认使用最新的函数(旧的就转换)
    GetWindowLong->GetWindowLongPtr以上仅是本人的猜测
      

  6.   


    在VC6.0下如何得到窗口ID呢?
    最好有相关代码。。
      

  7.   

    long nID = GetWindowLongPtr(m_hWnd, GWL_ID);
    试试
      

  8.   


    error C2065: 'GetWindowLongPtr' : undeclared identifier
      

  9.   

    对话框的ID不就是对话框的一个成员变量么IDD
      

  10.   

    可能不行了。。难道没有dialog ID?因为我在一个对话框中嵌入了由同一个类实例化的一个对话框,并且在初始化的时候增加控件提示ToolTipCtl.AddTool;
    由于两个对话框的控件不一样,因此想在初始化中addtool之前进行对话框判断。
    不用ID有没有其他更好的办法区分不同的对话框?
    或者将ToolTipCtl.AddTool放到其他某个我不知道的地方?
      

  11.   

    ToolTipCtl.AddTool
    就一定要窗体ID吗?
      

  12.   

    这样是可以;
    我的m_pDockDlg在视图中定义的;比较起来很麻烦,还要包含视图头文件。。还有没其他方法啦??
      

  13.   

    因为我是在一个窗口中嵌入了一个同一类的窗口,为了在初始化时区别一下不同的窗口,就想到了如何得到窗口id
    (再问一下,所谓的窗口ID是IDD_DIALOG...之类的吗?)
    当然,我也试过用窗口指针区分,是可以的,有点麻烦。还有能不能把ToolTipCtl.AddTool放到不用区分对话框的别的地方呢?
      

  14.   

    我也试过GetWindowLongPtr,一样的