In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to make a website hang-up program in C#". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to make a website hang-up program in C#".
First, the program interface (as shown below)
Name: simulated keyboard program, why not hang up program, because its function is weak, the scope is narrow, and, as a by-product, it is not really made for hanging up. Please note that our goal is to automate network testing.
2. Instructions for use 1. Interface description
1. Application path, which is for FireFox browsers, so you need to put the address of the program.
two。 Website address: a local file or URL that can be accessed directly in URL format
3. Browser title: FireFox program has hidden the application title, if you see the title bar shows: test
In fact, the title of the application should be: test-Mozilla Firefox
4. [start browser] in fact, this feature can be left unchecked and FireFox can be started manually.
5. [Start] button is the essence, which will be found according to the content of [browser title].
Go to FireFox to browse the real [handle] of the web page, and if found, the decimal value of the [handle] will be displayed, and if 0 is displayed, it is not found.
6. [Stop] disable timer operation.
two。 Pay attention to use
1. After the display [handle] position starts, it must be a non-zero value. If it is 0, modify the [browser title] content and click [Start] again.
two。 You must keep the FireFox browser in front of all forms
3. Make sure that [computer] does not enter [sleep] or [screen saver] state.
Third, program development process 1. Test the web page
1. File name: test.html
two。 The code of the web page is as follows:
Test alert ("ok")
two。 Program complete code
Using System;using System.Diagnostics;using System.Runtime.InteropServices;using System.Threading;using System.Windows.Forms;namespace simulation keyboard {public partial class Form1: Form {[DllImport ("user32.dll", EntryPoint = "keybd_event", SetLastError = true)] public static extern void keybd_event (Keys bVk, byte bScan, uint dwFlags, uint dwExtraInfo) [DllImport ("user32.dll", EntryPoint = "FindWindow")] private static extern IntPtr FindWindow (string IpClassName, string IpWindowName); / / find form controls public int iSeconds=30; public delegate bool CallBack (int hwnd, int lParam); public Process Proc = new Process (); public System.Windows.Forms.Timer myTimer; public Form1 () {InitializeComponent () } private void btnBrowser_Click (object sender, EventArgs e) {openFileDialog1.Filter = "* .exe | * .exe | all files | *. *"; openFileDialog1.FileName = ""; DialogResult dr = openFileDialog1.ShowDialog (); if (DialogResult.OK==dr) {txtFile.Text = openFileDialog1.FileName }} string str = "Message"; int iP = 0; private void btnStart_Click (object sender, EventArgs e) {IntPtr hnd = FindWindow (null, txtTitle.Text); / / get handle lblMessage.Text = hnd.ToString (); iSeconds = int.Parse (txtSeconds.Text.Trim ()) MyTimer.Interval = 1000 * iSeconds; / / 1 s = 1000 Ms myTimer.Enabled = true;} private void Form1_Load (object sender, EventArgs e) {myTimer = new System.Windows.Forms.Timer (); / / instantiate Timer timer myTimer.Tick + = new EventHandler (CallBack2) / / timer associated event function} private void CallBack2 (object sender,EventArgs e) / / timer event {keybd_event (Keys.Return, 0,0,0); / / simulated keyboard input: enter} private void btnStop_Click (object sender,EventArgs e) {myTimer.Enabled = false / / disable timer} private void btnStartBrowser_Click (object sender, EventArgs e) {if (string.IsNullOrEmpty (txtFile.Text)) return; try {/ / browser program startup thread Proc = new System.Diagnostics.Process (); Proc.StartInfo.FileName = txtFile.Text Proc.StartInfo.Arguments = txtNetAddr.Text; / / browser opens the URL parameter Proc.StartInfo.UseShellExecute = false; Proc.StartInfo.RedirectStandardInput = true; Proc.StartInfo.RedirectStandardOutput = true; Proc.Start ();} catch {Proc = null Fourth, some other ideas and problems of program development. The main window handle is obtained through the known process and then traverses the child window handle.
The following code has nothing to do with this program, are fragments, please do not copy directly to use, mainly provide reference for those who are interested in promotion.
If (string.IsNullOrEmpty (txtFile.Text)) return;try {Proc = new System.Diagnostics.Process (); Proc.StartInfo.FileName = txtFile.Text; Proc.StartInfo.Arguments = txtNetAddr.Text; Proc.StartInfo.UseShellExecute = false; Proc.StartInfo.RedirectStandardInput = true; Proc.StartInfo.RedirectStandardOutput = true; Proc.Start (); Thread.Sleep (2000);} catch {Proc = null } if (Proc.MainWindowHandle! = null) {/ / call API, passing data while (Proc.MainWindowHandle = = IntPtr.Zero) {Proc.Refresh ();} while (Proc.MainWindowHandle = = IntPtr.Zero) {Proc.Refresh ();} / / execute code slightly}
[problem description]: the thread here is Proc, but this thread is not the main form. The main form handle of this thread needs to be obtained through Proc.MainWindowHandle. In the process of use, it is easy to obtain the C#GUI program developed by yourself, and it is normal for the [notepad] program, but for the [Chrome] browser, the result is either 0 or abnormal, sometimes it can be obtained normally and sometimes it is abnormal when aiming at [FireFox].
two。 There are few and incomplete things to search for C # to operate API functions on the Internet.
Here provides a query website of API function, which basically catches up all the API functions. Http://pinvoke.net/#
3. If you want to view the API function under Windows, you can also use the tool:
1.DLL function Viewer
2.DLL Export Viewer
4. A tool that gets the handle, title, and type of an application form
You can use Spy++ in the VS environment (C++) here.
The above is all the contents of the article "how to make a website hang-up program in C#". Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.