Click here to Skip to main content
15,914,350 members
Home / Discussions / C#
   

C#

 
AnswerRe: Has anyone attempted synchronized scolling? Pin
Heath Stewart30-Aug-04 7:34
protectorHeath Stewart30-Aug-04 7:34 
GeneralRe: Has anyone attempted synchronized scolling? Pin
LongRange.Shooter31-Aug-04 6:50
LongRange.Shooter31-Aug-04 6:50 
GeneralRe: Has anyone attempted synchronized scolling? Pin
progload3-Oct-04 10:21
progload3-Oct-04 10:21 
GeneralErrorProvider() Not Displayed Pin
dbetting30-Aug-04 5:36
dbetting30-Aug-04 5:36 
Generalinstalling global cbt hooks in c# Pin
vignesh_s30-Aug-04 3:51
vignesh_s30-Aug-04 3:51 
GeneralRe: installing global cbt hooks in c# Pin
Nick Parker30-Aug-04 4:15
protectorNick Parker30-Aug-04 4:15 
GeneralRe: installing global cbt hooks in c# Pin
Duncan Edwards Jones30-Aug-04 4:15
professionalDuncan Edwards Jones30-Aug-04 4:15 
GeneralRe: installing global cbt hooks in c# Pin
vignesh_s3-Sep-04 3:40
vignesh_s3-Sep-04 3:40 
sorry i could not understand what u said.I am attaching the code that i tried please check out the error i have made and inform me.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Threading;
using System.Text;

namespace ThreadSpecificMouseHook
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{

public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);


static int hHook = 0;
public String WindowName;

public const int HCBT_ACTIVATE = 5;
public const int WH_CBT= 5;

private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;


HookProc WindowHookProcedure;



[StructLayout(LayoutKind.Sequential)]
public class CBTACTIVATESTRUCT
{
public bool fMouse;
public int hWndActive;

}

[DllImport("user32.dll",CharSet=CharSet.Auto,
CallingConvention=CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn,
IntPtr hInstance, int threadId);

[DllImport("user32.dll",CharSet=CharSet.Auto,
CallingConvention=CallingConvention.StdCall)]
public static extern bool UnhookWindowsHookEx(int idHook);

[DllImport("user32.dll",CharSet=CharSet.Auto,
CallingConvention=CallingConvention.StdCall)]
public static extern int CallNextHookEx(int idHook, int nCode,
Int32 wParam, IntPtr lParam);

[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll")]
public static extern int GetWindowText(int hWnd, StringBuilder text, int count);

[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr GetModuleHandle(string lpModuleName);


///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

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

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(88, 112);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(40, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 2;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.TopMost = true;
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}



public int WindowHookProc(int nCode, Int32 wParam, IntPtr lParam)
{
//CBTACTIVATESTRUCT myhook = (CBTACTIVATESTRUCT) Marshal.PtrToStructure(lParam,typeof(CBTACTIVATESTRUCT));
if (nCode < 0)
{
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
else
{

if (nCode == HCBT_ACTIVATE)
{
GetActiveWindow();
MessageBox.Show(WindowName);

}

return CallNextHookEx(hHook, nCode, wParam, lParam);
}

}
private void button1_Click(object sender, System.EventArgs e)
{
if(hHook == 0)
{
WindowHookProcedure = new HookProc(WindowHookProc);

hHook = SetWindowsHookEx(WH_CBT,
WindowHookProcedure,
Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),
0);
//If SetWindowsHookEx fails.
if(hHook == 0 )
{
MessageBox.Show("SetWindowsHookEx Failed");
return;
}
button1.Text = "UnHook Windows Hook";
}
else
{
bool ret = UnhookWindowsHookEx(hHook);
//If UnhookWindowsHookEx fails.
if(ret == false )
{
MessageBox.Show("UnhookWindowsHookEx Failed");
return;
}
hHook = 0;
button1.Text = "Set Windows Hook";
this.Text = "Windows Hook";
}


}
public void GetActiveWindow()
{

const int nChars = 256;
int handle = 0;
StringBuilder Buff = new StringBuilder(nChars);

handle = GetForegroundWindow().ToInt32() ;
if (handle != this.Handle.ToInt32())
{
if ( GetWindowText(handle, Buff, nChars) > 0 )
{
WindowName= Buff.ToString();
}
}

}
}
}


advance thanks
Generalset time in c# Pin
erina54830-Aug-04 3:14
erina54830-Aug-04 3:14 
GeneralRe: set time in c# Pin
Nick Parker30-Aug-04 4:27
protectorNick Parker30-Aug-04 4:27 
GeneralRe: set time in c# Pin
Heath Stewart30-Aug-04 5:56
protectorHeath Stewart30-Aug-04 5:56 
GeneralExporting to CVS Pin
Digger2730-Aug-04 1:15
Digger2730-Aug-04 1:15 
GeneralRe: Exporting to CVS Pin
Colin Angus Mackay30-Aug-04 1:31
Colin Angus Mackay30-Aug-04 1:31 
GeneralRe: Exporting to CVS Pin
Digger2730-Aug-04 4:27
Digger2730-Aug-04 4:27 
GeneralRe: Exporting to CVS Pin
Nick Parker30-Aug-04 4:22
protectorNick Parker30-Aug-04 4:22 
GeneralISA bus access Pin
zaarzzz30-Aug-04 1:12
zaarzzz30-Aug-04 1:12 
GeneralRe: ISA bus access Pin
leppie30-Aug-04 3:05
leppie30-Aug-04 3:05 
GeneralExport a report to multiple excel files Pin
KSEI30-Aug-04 1:04
KSEI30-Aug-04 1:04 
GeneralRe: Export a report to multiple excel files Pin
Arch4ngel30-Aug-04 2:23
Arch4ngel30-Aug-04 2:23 
GeneralProblem with Richtextbox wrapping Pin
dmc55530-Aug-04 0:29
dmc55530-Aug-04 0:29 
GeneralRe: Problem with Richtextbox wrapping Pin
Judah Gabriel Himango30-Aug-04 6:42
sponsorJudah Gabriel Himango30-Aug-04 6:42 
GeneralRe: Problem with Richtextbox wrapping Pin
Dave Kreskowiak30-Aug-04 7:40
mveDave Kreskowiak30-Aug-04 7:40 
GeneralRe: Problem with Richtextbox wrapping Pin
dmc55530-Aug-04 23:54
dmc55530-Aug-04 23:54 
QuestionHow to create a line from nodes? Pin
adnanh7530-Aug-04 0:24
adnanh7530-Aug-04 0:24 
AnswerRe: How to create a line from nodes? Pin
Colin Angus Mackay30-Aug-04 1:39
Colin Angus Mackay30-Aug-04 1:39 

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.