Click here to Skip to main content
15,887,746 members
Home / Discussions / C#
   

C#

 
GeneralRe: displaying database query result in reports Pin
Mubeen.asim22-Feb-09 2:16
Mubeen.asim22-Feb-09 2:16 
Questionplaying mpeg file Pin
sbs21-Feb-09 17:56
sbs21-Feb-09 17:56 
Question[Message Deleted] Pin
Mel Feik21-Feb-09 17:36
Mel Feik21-Feb-09 17:36 
AnswerRe: creating a service with monitoring capabilities... Pin
Mubeen.asim22-Feb-09 2:22
Mubeen.asim22-Feb-09 2:22 
Question[Message Deleted] Pin
rpopple21-Feb-09 14:12
rpopple21-Feb-09 14:12 
AnswerRe: child handle in a window programed in a different language Pin
Anthony Mushrow21-Feb-09 15:37
professionalAnthony Mushrow21-Feb-09 15:37 
GeneralRe: child handle in a window programed in a different language Pin
rpopple22-Feb-09 4:58
rpopple22-Feb-09 4:58 
Questionproc.MainWindowTitle == variable doesn't work Pin
Kimjor21-Feb-09 10:54
Kimjor21-Feb-09 10:54 
Hi
Ok so i have only been playing with C# for 1 day, so it's probably just me who can't get it to work.
It's a very small program to take 3 inputs (a string, a number and a selected process name) then input the string a number of times into the selected process. For testing i have Notepad open and the application name is "a.txt - Notepad"

Now my problem is that it works perfectly if i simply put "a.txt - Notepad" into the code. But if i do
String a = "a.txt - Notepad"
and then proc.MainWindowTitle == a then it doesn't work Frown | :-(


Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Collections;

namespace ting
{
public partial class frmMain : Form
{
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);

[DllImport("user32.dll")]
static extern byte VkKeyScan(char ch);

public frmMain()
{
InitializeComponent();
comboBox1.DataSource = ProcessValidation.ListAllApplications();
}

private void Form1_Load(object sender, EventArgs e) { }

private void StartButtonClick(object sender, EventArgs e)
{
const uint WM_KEYDOWN = 0x100;

string text = txtText.Text;
string tidx = txtTime.Text;
if (tidx == "") tidx = "1";
int tid = int.Parse(tidx);

string windowTitle = (string)comboBox1.SelectedItem;
//MessageBox.Show(windowTitle + "a.txt - Notepad");

Process[] procs = Process.GetProcessesByName("Notepad");
foreach (Process proc in procs)
{
MessageBox.Show(windowTitle);
if (proc.MainWindowTitle == windowTitle)//"a.txt - Notepad")
{
// get handle to Notepad's edit window
IntPtr hWnd = FindWindowEx(proc.MainWindowHandle, IntPtr.Zero, "edit", null);

for (int i = 0; i < tid; i++)
{
for (int z = 0; z < text.Length; z++)
{
PostMessage(hWnd, WM_KEYDOWN, VkKeyScan(text[z]), 0);
}
// Thread.Sleep(11000);

}
break;
}
}

}

private void closeButtonClick(object sender, EventArgs e)
{
this.Close();
}

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
}

private void frmMain_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
Hide();
}
}
}



ProcessList.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.ComponentModel;
using System.Diagnostics;
using System.Collections;


namespace ting
{


public static class ProcessList
{

public static ArrayList ListAllApplications()
{
StringBuilder sb = new StringBuilder();
ArrayList a = new ArrayList();

foreach (Process p in Process.GetProcesses("."))
{
try
{
if (p.MainWindowTitle.Length > 0)
{
a.Add(p.MainWindowTitle.ToString() + Environment.NewLine);
}
}
catch { }
}
return a;
}
}
}


Form1.designer.cs
namespace ting
{
partial class frmMain
{
///
/// Required designer variable.
///

private System.ComponentModel.IContainer components = null;

///
/// Clean up any resources being used.
///

/// <param name="disposing" />true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain));
this.btnStart = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
this.txtText = new System.Windows.Forms.TextBox();
this.txtTime = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.panel1 = new System.Windows.Forms.Panel();
this.processValidationBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.processValidationBindingSource)).BeginInit();
this.SuspendLayout();
//
// btnStart
//
this.btnStart.Location = new System.Drawing.Point(16, 16);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(75, 23);
this.btnStart.TabIndex = 0;
this.btnStart.Text = "Start";
this.btnStart.UseVisualStyleBackColor = true;
this.btnStart.Click += new System.EventHandler(this.StartButtonClick);
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(178, 16);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 23);
this.btnClose.TabIndex = 1;
this.btnClose.Text = "Luk";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.closeButtonClick);
//
// txtText
//
this.txtText.BackColor = System.Drawing.SystemColors.Menu;
this.txtText.Location = new System.Drawing.Point(16, 75);
this.txtText.Name = "txtText";
this.txtText.Size = new System.Drawing.Size(100, 20);
this.txtText.TabIndex = 2;
//
// txtTime
//
this.txtTime.BackColor = System.Drawing.SystemColors.MenuBar;
this.txtTime.Location = new System.Drawing.Point(153, 75);
this.txtTime.Name = "txtTime";
this.txtTime.Size = new System.Drawing.Size(100, 20);
this.txtTime.TabIndex = 3;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(5, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(28, 13);
this.label1.TabIndex = 5;
this.label1.Text = "Text";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(142, 12);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(22, 13);
this.label2.TabIndex = 6;
this.label2.Text = "Tid";
//
// notifyIcon1
//
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "KillerApp 1.0";
this.notifyIcon1.Visible = true;
this.notifyIcon1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDoubleClick);
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(16, 130);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(237, 21);
this.comboBox1.TabIndex = 11;
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.label2);
this.panel1.Location = new System.Drawing.Point(6, 45);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(255, 256);
this.panel1.TabIndex = 12;
//
// processValidationBindingSource
//
this.processValidationBindingSource.DataSource = typeof(ting.ProcessList);
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(269, 313);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.txtTime);
this.Controls.Add(this.txtText);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnStart);
this.Controls.Add(this.panel1);
this.Name = "frmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Kims Killer App";
this.Load += new System.EventHandler(this.Form1_Load);
this.Resize += new System.EventHandler(this.frmMain_Resize);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.processValidationBindingSource)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.TextBox txtText;
private System.Windows.Forms.TextBox txtTime;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.BindingSource processValidationBindingSource;
private System.Windows.Forms.Panel panel1;
}
}

AnswerRe: proc.MainWindowTitle == variable doesn't work Pin
Christian Graus21-Feb-09 11:25
protectorChristian Graus21-Feb-09 11:25 
AnswerRe: proc.MainWindowTitle == variable doesn't work Pin
Xmen Real 22-Feb-09 3:15
professional Xmen Real 22-Feb-09 3:15 
QuestionHow to get pointer ( Interop ) to microsoft outlook ?? Pin
Yanshof21-Feb-09 10:44
Yanshof21-Feb-09 10:44 
AnswerRe: How to get pointer ( Interop ) to microsoft outlook ?? Pin
Christian Graus21-Feb-09 11:29
protectorChristian Graus21-Feb-09 11:29 
GeneralRe: How to get pointer ( Interop ) to microsoft outlook ?? Pin
Yanshof21-Feb-09 11:44
Yanshof21-Feb-09 11:44 
GeneralRe: How to get pointer ( Interop ) to microsoft outlook ?? Pin
Christian Graus21-Feb-09 12:07
protectorChristian Graus21-Feb-09 12:07 
AnswerRe: How to get pointer ( Interop ) to microsoft outlook ?? Pin
Wendelius21-Feb-09 20:54
mentorWendelius21-Feb-09 20:54 
QuestionInstalled exe on Vista [modified] Pin
Rafone21-Feb-09 7:40
Rafone21-Feb-09 7:40 
AnswerRe: Installed exe on Vista Pin
god.hacks21-Feb-09 11:23
god.hacks21-Feb-09 11:23 
AnswerRe: Installed exe on Vista Pin
Christian Graus21-Feb-09 11:34
protectorChristian Graus21-Feb-09 11:34 
GeneralRe: Installed exe on Vista Pin
Rafone21-Feb-09 13:28
Rafone21-Feb-09 13:28 
QuestionHow to type text in Hidden textbox Pin
srinivasadithya21-Feb-09 5:48
srinivasadithya21-Feb-09 5:48 
AnswerRe: How to type text in Hidden textbox Pin
Ravi Bhavnani21-Feb-09 5:54
professionalRavi Bhavnani21-Feb-09 5:54 
GeneralRe: How to type text in Hidden textbox Pin
srinivasadithya21-Feb-09 6:06
srinivasadithya21-Feb-09 6:06 
QuestionRunnig custom script Pin
Lewis0121-Feb-09 5:01
Lewis0121-Feb-09 5:01 
AnswerRe: Runnig custom script Pin
Ravi Bhavnani21-Feb-09 5:55
professionalRavi Bhavnani21-Feb-09 5:55 
QuestionData crypting at C# Pin
_c2h5oh_21-Feb-09 3:57
_c2h5oh_21-Feb-09 3:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.