Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
namespace FFauslesen
{
class Program
{
static void Main(string[] args)
{
Process[] processes = Process.GetProcessesByName("firefox");
string titel = "";
foreach (Process process in processes)
{
titel = process.MainWindowTitle;
}
IntPtr hwnd = UnsafeNativeMethods.FindWindow(null, titel);
StringBuilder stringBuilder = new StringBuilder(256);
UnsafeNativeMethods.GetWindowText(hwnd, stringBuilder, stringBuilder.Capacity);
Console.WriteLine(stringBuilder.ToString());
}
}
[SuppressUnmanagedCodeSecurity]
internal static class UnsafeNativeMethods
{
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll", SetLastError = true)]
internal static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
}
}
naja wenn du den quelltext hast, kannst ja trotzdem durchsuchen oder versteh ich das falsch?
an den php quelltext kommst auf clientseitig in der regel gar nicht ...Wenn eine Webseite z.b. mit php geschrieben ist bekomme ich da nicht den Text den ich eigentlich will.
was ist das hindernis ?Ein Firefox addon zu bauen ist leider keine Möglichkeit, da ich den Firefox nicht verändern möchte/kann.
Sry, aber mein Code soll teil eines größern Programms werden, an dem ich und ein paar Freunde arbeiten.
Wäre es vielleicht generell nicht einfacher auf die History von Firefox zuzugreifen und den Link dann direkt im C-Programm zu laden? Das Ergebnis kann man dann ja durch einen Parser schicken um den gewollten Text zu bekommen. Nur so eine Idee..
Also erstmal verstehe ich deine Aussage nicht, dass dir der Quelltext nicht reichen würde, wenn die Seite mit PHP erstellt/generiert ist. Der Quelltext ist das, was am Ende auch von deinem Browser angezeigt wird. Wenn, dann könnte ich mir höchstens bei JS, speziell AJAX, Probleme vorstellen.
unter c++ könntest du auf xpcom zurück greifen ...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
public delegate bool CallBack(int hwnd, int lParam);
[DllImport("user32.dll")]
public static extern int GetClassName(int hWnd, string lpClassName, int nMaxCount);
[DllImport("user32.dll", SetLastError = true)]
public static extern int GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
public static extern int EnumWindows(CallBack callback, int param);
[DllImport("user32.dll")]
public static extern int FindWindowEx(int hWndParent, int hWndChild, string lpsClass, string lpsTilte);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hwnd, int wMsg,
IntPtr wParam,
IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessageBlah(IntPtr hwnd, int wMsg,
IntPtr wParam,
IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "SendMessage")]
public static extern int SendMessageFaul(IntPtr hwnd, int wMsg,
int wParam,
StringBuilder lParam);
private const int WM_GETTEXT = 0x000D;
private const int WM_GETTEXTLENGTH = 0x000E;
private static string GetText(IntPtr hwnd)
{
int lngLength;
StringBuilder strBuffer = new StringBuilder();
int lngRet;
lngLength = SendMessage(hwnd, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero) + 1;
strBuffer.Capacity = lngLength;
lngRet = SendMessageFaul(hwnd, WM_GETTEXT, strBuffer.Capacity, strBuffer);
if (lngRet > 0)
return strBuffer.ToString().Substring(0, lngRet);
return
null;
}
static void Main(string[] args)
{
CallBack callBack = new CallBack(DisplayWindowInfo);
EnumWindows(callBack, 0);
//char = (char)7;
int hwnd = FindWindowEx(0, 0, null, "C# Fensterinhalt vom Firefox auslesen - Seite 2 - Mozilla Firefox");
int hwndedit = FindWindowEx(hwnd, 0, "edit", null);
//int chars = 100;
//if (GetWindowText(hwndedit, buf, chars) != 0)
string text = GetText((IntPtr)hwndedit);
if (text != null)
{
Console.WriteLine(text);
}
else
{
Console.WriteLine("myfunc: " + Marshal.GetLastWin32Error());
}
Console.ReadLine();
}
public static bool DisplayWindowInfo(int hWnd, int lParam)
{
int chars = 500;
StringBuilder buf = new StringBuilder(chars);
if (GetWindowText(hWnd, buf, chars) != 0)
{
string searchf = "Unbenannt - Editor".ToString();
if (String.Equals(searchf, buf.ToString()))
{
StringBuilder bufc = new StringBuilder(chars);
Console.WriteLine("Application: " + buf);
Console.WriteLine("ClassName: " + GetClassName(hWnd, bufc.ToString(), chars));
Console.WriteLine("-----------------------------------------");
}
//else
// Console.WriteLine("Unequal: " + searchf + " // " + buf);
}
return true;
}
}
}
Geht es eigentlich um eine bestimmte Seite? Wenn ja, ist dieser Umweg über Firefox überhaupt nicht nötig.Ja der Quellcode würde auch gehen. Trotzdem weiß ich noch nicht wie ich da ran kommen soll.