簡體   English   中英

Findwindowex 通過句柄 c#

[英]Findwindowex by handle c#

我已經為此苦苦掙扎了很長一段時間,但無法得到任何我理解的答案。 我是 C# 的新手。

所以我正在啟動一個應用程序(具體來說是 Accpac),然后我需要通過 sendkeys/sendmessage 將用戶名發送到子窗口。 我有 childwindow 的句柄,但我無法讓它工作:IntPtr.(00020380),我收到錯誤“Identifier expected”

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices; 
    using System.Diagnostics; 
    using System.Windows.Forms; 
    using System.Threading; 
    
    namespace myNamespace
    {
        class StartAccpac
        {
            [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
            [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
    
            public static void Main3()
            {  
                //START ACCPAC
                //Process.Start("C:\\Programs\\Accpac\\runtime\\accpac.exe");
                IntPtr hwnd = IntPtr.Zero;
                IntPtr hwndChild = IntPtr.Zero;
    
                //Get a MAIN HANDLE
                hwnd = FindWindow(null, "Open Company");
                hwndChild = FindWindowEx(hwnd, IntPtr.(00020380), null, null); <---- ERROR
            }
            
        }
    }

在此處輸入圖片說明 在此處輸入圖片說明 在此處輸入圖片說明

你的問題在這里:

IntPtr.(00020380)

你需要做的是這樣的:

new IntPtr(00020380)

但是我懷疑,作為八位數字並查看您的屏幕截圖,這是一個十六進制數,因此您可能還需要考慮:

new IntPtr(0x00020380)

和他們一起玩,看看會發生什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM