Пример #1
0
            /// <summary>
            /// liefert den Text (i.A. Caption) des Fensters
            /// </summary>
            /// <returns></returns>
            public string GetText()
            {
                Int32 size = Win32User.SendMessage(hWnd, Win32User.WM_GETTEXTLENGTH, 0, 0).ToInt32();

                if (size > 0)    // sonst kein Text
                {
                    StringBuilder title = new StringBuilder(size + 1);
                    Win32User.SendMessage(hWnd, Win32User.WM_GETTEXT, title.Capacity, title);
                    return(title.ToString());
                }
                return("");
            }
Пример #2
0
            //public unsafe static string GetPanelText1(IntPtr hStatusBar, int pos) {
            //   string text = "";
            //   // Programmfenster ermitteln
            //   IntPtr hwnd = GetAncestor(hStatusBar, GetAncestorFlags.GetRoot);
            //   // Prozess-ID ermitteln
            //   uint processId;
            //   uint threadId = GetWindowThreadProcessId(hwnd, out processId);
            //   if (processId > 0) {
            //      // Prozess öffnen
            //      IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, processId);
            //      if (hProcess != IntPtr.Zero) {
            //         // Remote-Puffer anlegen
            //         const int BUFFER_SIZE = 0x1000;
            //         IntPtr ipRemoteBuffer = VirtualAllocEx(hProcess, IntPtr.Zero, new IntPtr(BUFFER_SIZE), AllocationType.COMMIT, MemoryProtection.READWRITE);
            //         if (ipRemoteBuffer != IntPtr.Zero) {
            //            // Textlänge und Text ermitteln
            //            int chars = SendMessage(hStatusBar.ToInt32(), SB_GETTEXT, pos, ipRemoteBuffer.ToInt32());
            //            if (chars >= 0) {
            //               byte[] localBuffer = new byte[BUFFER_SIZE];
            //               fixed (byte* pLocalBuffer = localBuffer) {
            //                  IntPtr ipLocalBuffer = new IntPtr(pLocalBuffer);
            //                  Int32 dwBytesRead = 0;
            //                  IntPtr ipBytesRead = new IntPtr(&dwBytesRead);
            //                  // Remote-Puffer in den lokalen Puffer einlesen
            //                  bool b4 = ReadProcessMemory(hProcess, ipRemoteBuffer, localBuffer, BUFFER_SIZE, out ipBytesRead);
            //                  //bool b4 = ReadProcessMemory(hProcess, ipRemoteBuffer, ipLocalBuffer, BUFFER_SIZE, out ipBytesRead);
            //                  if (b4) {
            //                     // Umwandlung in Text
            //                     text = Marshal.PtrToStringUni(ipLocalBuffer, chars);
            //                     if (text == " ")
            //                        text = String.Empty;
            //                  }
            //               }
            //            }
            //            VirtualFreeEx(hProcess, ipRemoteBuffer, 0, FreeType.Release);
            //         }
            //         CloseHandle(hProcess);
            //      }
            //   }
            //   return text;
            //}

            /// <summary>
            /// ermittelt den Text einer Statusbar
            /// </summary>
            /// <param name="hStatusBar"></param>
            /// <param name="pos">Position 0, ...</param>
            /// <returns></returns>
            public static string GetPanelText(IntPtr hStatusBar, int pos)
            {
                string text = "";
                // Programmfenster ermitteln
                IntPtr hwnd = Win32User.GetAncestor(hStatusBar, Win32User.GetAncestorFlags.GetRoot);
                // Prozess-ID ermitteln
                uint processId;
                uint threadId = Win32User.GetWindowThreadProcessId(hwnd, out processId);

                if (processId > 0)
                {
                    // Prozess öffnen
                    IntPtr hProcess = Win32Kernel.OpenProcess(Win32Kernel.ProcessAccessFlags.All, false, processId);
                    if (hProcess != IntPtr.Zero)
                    {
                        // Remote-Puffer anlegen
                        const int BUFFER_SIZE    = 0x1000;
                        IntPtr    ipRemoteBuffer = Win32Kernel.VirtualAllocEx(hProcess, IntPtr.Zero, new IntPtr(BUFFER_SIZE), Win32Kernel.AllocationType.COMMIT, Win32Kernel.MemoryProtection.READWRITE);
                        if (ipRemoteBuffer != IntPtr.Zero)
                        {
                            // Textlänge und Text ermitteln
                            int chars = Win32User.SendMessage(hStatusBar, Win32User.SB_GETTEXT, pos, ipRemoteBuffer.ToInt32()).ToInt32();
                            if (chars >= 0)
                            {
                                byte[] localBuffer = new byte[BUFFER_SIZE];
                                IntPtr ipBytesRead = new IntPtr(0);
                                // Remote-Puffer in den lokalen Puffer einlesen
                                if (Win32Kernel.ReadProcessMemory(hProcess, ipRemoteBuffer, localBuffer, BUFFER_SIZE, out ipBytesRead))
                                {
                                    // Umwandlung in Text
                                    text = System.Text.Encoding.Unicode.GetString(localBuffer).Substring(0, chars);
                                    if (text == " ")
                                    {
                                        text = String.Empty;
                                    }
                                }
                            }
                            Win32Kernel.VirtualFreeEx(hProcess, ipRemoteBuffer, 0, Win32Kernel.FreeType.Release);
                        }
                        Win32Kernel.CloseHandle(hProcess);
                    }
                }
                return(text);
            }