Click here to Skip to main content
15,891,981 members
Home / Discussions / C#
   

C#

 
Questioncreating a mp3 scratching program [modified] Pin
dman1000110-Sep-07 12:50
dman1000110-Sep-07 12:50 
AnswerRe: creating a mp3 scratching program Pin
VirtualVoid.NET10-Sep-07 21:46
VirtualVoid.NET10-Sep-07 21:46 
QuestionArray of Regions. Elements seem to disappear. [modified] Pin
hain10-Sep-07 11:18
hain10-Sep-07 11:18 
AnswerRe: Array of Regions. Elements seem to disappear. Pin
Giorgi Dalakishvili10-Sep-07 11:24
mentorGiorgi Dalakishvili10-Sep-07 11:24 
GeneralRe: Simple code example [modified] Pin
hain10-Sep-07 12:28
hain10-Sep-07 12:28 
GeneralRe: Simple code example Pin
Patrick Etc.10-Sep-07 12:49
Patrick Etc.10-Sep-07 12:49 
GeneralRe: Simple code example Pin
hain10-Sep-07 16:12
hain10-Sep-07 16:12 
QuestionModal Dialog [modified] Pin
kamalesh8210-Sep-07 9:34
kamalesh8210-Sep-07 9:34 
hi all,
am getting a stange problem. from a call back function, am calling a MODELESS dialog,(when timeout reached for my dialog), but it's creating as a modal dialog... it's not my requirement. i've develop a sample,i think, it's created on a different thread than main thread. (may be.. not sure.).... please provide any commentsa nad solution.. please... Smile | :) Confused | :confused:

my code:(design form not included)

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

namespace TimeoutWindow
{
public partial class TimeoutForm : Form
{
private System.Threading.Timer m_Timer = null;
private const int WH_KEYBOARD = 2;
private const int WH_MOUSE = 7;
private LowLevelKeyboardProc _procKey = KeyHookCallback;
private LowLevelKeyboardProc _prockMouse = MouseHookCallBack;
private static IntPtr _hookIDKey = IntPtr.Zero;
private static IntPtr _hookIDMouse = IntPtr.Zero;
private static UInt32 m_LastHitTime = 0;
private System.Threading.TimerCallback timerCallBack = null;
private AutoResetEvent autoEvent = null;
private Form2 dlg;

private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);


public TimeoutForm()
{
InitializeComponent();
_hookIDKey = SetWindowsHookEx(WH_KEYBOARD,_procKey,(IntPtr)0,(uint)AppDomain.GetCurrentThreadId());
_hookIDMouse = SetWindowsHookEx(WH_MOUSE,_procKey,(IntPtr)0,(uint)AppDomain.GetCurrentThreadId());

timerCallBack = new System.Threading.TimerCallback(this.CheckTimeout);

autoEvent = new AutoResetEvent(false);
m_LastHitTime = GetTickCount();
m_Timer = new System.Threading.Timer(timerCallBack, autoEvent, 20000, 20000);

}

private void OnTryLogin(object sender, EventArgs e)
{
MessageBox.Show("HI");
Form2 dlg = new Form2();
dlg.ShowDialog();
}

public void CheckTimeout(Object stateInfo)
{
autoEvent = (AutoResetEvent)stateInfo;
UInt32 curTime = GetTickCount();
if (curTime - m_LastHitTime > 2000)
{
this.m_Timer.Dispose();
try
{
this.dlg = new Form2();
if (dlg != null)
{
//problem occuring here................
this.dlg.ShowDialog(); /// creating modal dialog.
m_LastHitTime = GetTickCount();
m_Timer = new System.Threading.Timer(timerCallBack, autoEvent,2000,2000);
}
else
System.Windows.Forms.MessageBox.Show("NULL");
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
}
#region dllimport
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);

[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnhookWindowsHookEx(IntPtr hhk);

[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);

[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);

[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern System.UInt32 GetTickCount();
#endregion
private static IntPtr KeyHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode < 0)
return CallNextHookEx(_hookIDKey, nCode, wParam, lParam);
else
{
m_LastHitTime = GetTickCount();
return CallNextHookEx(_hookIDKey, nCode, wParam, lParam);
}
}
private static IntPtr MouseHookCallBack(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode < 0)
return CallNextHookEx(_hookIDMouse, nCode, wParam, lParam);
else
{
m_LastHitTime = GetTickCount();
return CallNextHookEx(_hookIDMouse, nCode, wParam, lParam);
}
}

private void OnCloseForm1(object sender, FormClosedEventArgs e)
{
UnhookWindowsHookEx(_hookIDKey);
UnhookWindowsHookEx(_hookIDMouse);
}
}
}




-- modified at 15:56 Monday 10th September, 2007

kamalesh

AnswerRe: Modal Dialog Pin
Christian Graus10-Sep-07 9:52
protectorChristian Graus10-Sep-07 9:52 
GeneralRe: Modal Dialog Pin
kamalesh8210-Sep-07 9:58
kamalesh8210-Sep-07 9:58 
GeneralRe: Modal Dialog Pin
Christian Graus10-Sep-07 10:00
protectorChristian Graus10-Sep-07 10:00 
QuestionPicture Box created by code not showing up Pin
Jordanwb10-Sep-07 9:09
Jordanwb10-Sep-07 9:09 
AnswerRe: Picture Box created by code not showing up Pin
Ermak8610-Sep-07 9:38
Ermak8610-Sep-07 9:38 
GeneralRe: Picture Box created by code not showing up Pin
Jordanwb10-Sep-07 9:53
Jordanwb10-Sep-07 9:53 
GeneralRe: Picture Box created by code not showing up Pin
Christian Graus10-Sep-07 9:55
protectorChristian Graus10-Sep-07 9:55 
GeneralRe: Picture Box created by code not showing up Pin
Jordanwb10-Sep-07 9:58
Jordanwb10-Sep-07 9:58 
GeneralRe: Picture Box created by code not showing up Pin
Ermak8610-Sep-07 10:02
Ermak8610-Sep-07 10:02 
GeneralRe: Picture Box created by code not showing up Pin
Jordanwb10-Sep-07 10:04
Jordanwb10-Sep-07 10:04 
GeneralRe: Picture Box created by code not showing up Pin
Ermak8610-Sep-07 10:13
Ermak8610-Sep-07 10:13 
GeneralRe: Picture Box created by code not showing up Pin
Jordanwb10-Sep-07 10:18
Jordanwb10-Sep-07 10:18 
GeneralRe: Picture Box created by code not showing up Pin
Skippums10-Sep-07 10:34
Skippums10-Sep-07 10:34 
GeneralRe: Picture Box created by code not showing up Pin
Jordanwb10-Sep-07 10:42
Jordanwb10-Sep-07 10:42 
GeneralRe: Picture Box created by code not showing up Pin
Skippums10-Sep-07 10:48
Skippums10-Sep-07 10:48 
GeneralRe: Picture Box created by code not showing up Pin
Ermak8610-Sep-07 10:47
Ermak8610-Sep-07 10:47 
GeneralRe: Picture Box created by code not showing up Pin
Jordanwb10-Sep-07 10:48
Jordanwb10-Sep-07 10:48 

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.