Teamviewer停止运行GetWindowTextUser32.dll函数

问题描述

我已经开发了一个访问user32.dll的C#代码,它使用GetwindowText函数。在Windows 7上卸载Teamviewer时,代码可以正常工作。

但是,如果您安装Teamviewer,则该代码无法使用GetwindowText函数在窗口中检索控件的文本。代码如下。我该如何解决这个问题?

     [DllImport("user32.dll",CharSet = CharSet.Auto)]
     static extern IntPtr findwindowexW(IntPtr hwndParent,IntPtr hwndChildAfter,string lpszClass,string lpszWindow);

     [DllImport("user32.dll",CharSet = CharSet.Auto)]
     static extern IntPtr GetwindowText(IntPtr hwndParent,StringBuilder Wintxt,int txtsize);


     public void CloseWin(string param)
    {
        try
        {
         IntPtr hwnD = findwindowexW(IntPtr.Zero,IntPtr.Zero,"CabinetWClass",null);
         IntPtr hwnD2 = findwindowexW(hwDvar,"WorkerW",null);
         IntPtr hwnD3 = findwindowexW(hwnD2,"ReBarWindow32",null);
         IntPtr hwnD4 = findwindowexW(hwnD3,"Address Band Root",null);
         IntPtr hwnD5 = findwindowexW(hwnD4,"msctls_progress32",null);
         IntPtr hwnD6 = findwindowexW(hwnD5,"Breadcrumb Parent",null);
         IntPtr hwnD7 = findwindowexW(hwnD6,"ToolbarWindow32",null);
         StringBuilder sb = new StringBuilder(255);
         GetwindowText(hwnD7,sb,255);

解决方法

我已经解决了这个问题。我还用类名#32770调用了函数FindWindowEx的对话框文件类。

Teamviewer(TV)快速支持用户界面也使用此类类型。当我运行代码时,会干扰电视的界面和user32功能的正常运行。

为解决该问题,我用类名和控件名调用了FindWindow函数,这样就无需干预电视并解决了问题。