代码之家  ›  专栏  ›  技术社区  ›  Ozzy

C十六进制值到intptr

  •  1
  • Ozzy  · 技术社区  · 15 年前

    我对使用spy++找到的窗口有一个十六进制值。

    数值为:00010010

    由于回答了我之前问的一个问题,我得到了以下代码:

    IntPtr hwndf = this.Handle;
    IntPtr hwndParent = FindWindow("WINDOW HERE", null); ;
    
    SetParent(hwndf, hwndParent);
    this.TopMost = false;
    

    现在,据我所知,intptr hwndparent将在这里包含窗口的句柄。如何重写该行以使用十六进制句柄?我试过:

    IntPtr hwndParent = (IntPtr) 0x00010010
    

    但它不起作用。有什么想法吗?

    5 回复  |  直到 15 年前
        1
  •  1
  •   Michael Petrotta user3140870    15 年前

    那么,十六进制的等价物00010010是0x12。所以理论上你可以用

    IntPtr hwndParent = (IntPtr) 0x12
    

    Windows计算器可以进行这种转换。不过,这个值听起来不正确。你能更详细地解释一下你是如何得到这个价值的吗?

    编辑: 您的评论提到您正试图获得桌面窗口的句柄。它有一个功能: GetDesktopWindow ,返回一个intptr。如果你只对桌面窗口感兴趣,那就用它。

    下面是该函数的p/invoke:

    [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
    public static extern IntPtr GetDesktopWindow();
    
        2
  •  1
  •   joshperry    15 年前

    Intptr的构造函数接受初始化参数:

    IntPtr hwndParent = new IntPtr(0x00010010);
    
        3
  •  0
  •   richardtallent    15 年前

    尝试:

     Convert.ToInt32("00010010", 16);
    
        4
  •  0
  •   almog.ori    15 年前

    这应该管用

     var hwnd = new IntPtr(Convert.ToInt32({HexNumber}, 16));
    
        5
  •  0
  •   Community CDub    8 年前

    既然你在说 this 问题:您似乎不想在桌面上创建一个小部件/窗口,而是在另一个窗口上创建? 如果是这样的话,为什么不使用find window()找到那个窗口?

    为什么是常量?