|
Try handling the Validating Event and use Datetime.Tryparse() to see if it is a valid date.
|
|
|
|
|
hi,
but the problem is that the maskedTextBox format (datetime) based on JC(Julian calendar ) and its format is mm/dd/yyyy , but the format I want is yyyy/mm/dd based on Persian Calendar .
thanks for ur guide ,
s_mostafa_h
|
|
|
|
|
Author: hema
hello,
i have developed an application thats a BHO.The setsite method of IObjectWithSite installs keyboard hooks. though the hook is getting installed, its not executing the expected work. i am attaching the code below. please tell me wats wrong in this.
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Web.Services;
using Microsoft.Win32;
using SHDocVw;
namespace KeyboardHooks_BHO
{
[ComVisible(true)]
[Guid("20C718C8-0D8C-42dc-B0CD-C7C53A23F116")]
public class BHO : IObjectWithSite
{
#region Member Variables
protected SHDocVw.IWebBrowser2 m_pIWebBrowser2;
protected SHDocVw.DWebBrowserEvents2_Event m_pDWebBrowserEvents2;
#endregion
#region Hook Variables
public struct KeyboardHookStruct
{
public long vkCode;
public long scanCode;
public int flags;
public long time;
public long dwExtraInfo;
};
private const int HC_ACTION = 0;
private const int LLKHF_EXTENDED = 0x01;
private const int LLKHF_ALTDOWN = 0x20;
private const long VK_T = 0x54;
private const long VK_P = 0x50;
private const long VK_S = 0x53;
private const int WH_KEYBOARD_LL=13;
protected IntPtr KeyboardHandle = IntPtr.Zero;
private static int mHook;
#endregion
public BHO()
{
MessageBox.Show("inside BHO's constructor");
}
#region COM interfaces
#region IObjectWithSite Members
public void SetSite(object newSite)
{
MessageBox.Show("inside SetSite");
object site=newSite;
string explorer= null;
if (m_pIWebBrowser2!=null)
Release();
if( site != null )
Marshal.ReleaseComObject( site );
site = newSite;
if( site != null )
{
MessageBox.Show("inside if site!=null");
IServiceProvider sp = site as IServiceProvider;
m_pIWebBrowser2 = site as SHDocVw.IWebBrowser2;
Guid guid = ExplorerGUIDs.IID_IWebBrowserApp;
Guid riid = ExplorerGUIDs.IID_IUnknown;
object wba;
sp.QueryService(ref guid,ref riid,out wba );
explorer=m_pIWebBrowser2.FullName.ToUpper();
if(explorer.EndsWith("IEXPLORE.EXE"))
{
MessageBox.Show("inside the IEXPLORE.EXE");
Install();
MessageBox.Show("hooking");
}
}
else
{
if ( explorer != null )
{
IServiceProvider sp = site as IServiceProvider;
m_pIWebBrowser2 = site as SHDocVw.IWebBrowser2;
Guid guid = ExplorerGUIDs.IID_IWebBrowserApp;
Guid riid = ExplorerGUIDs.IID_IUnknown;
object wba;
sp.QueryService(ref guid,ref riid,out wba );
explorer=m_pIWebBrowser2.FullName.ToUpper();
if(explorer.EndsWith("IEXPLORE.EXE"))
{
UnInstall();
MessageBox.Show("UnHookMe");
}
explorer = null;
}
MessageBox.Show("end of setsite");
return;
}
}
public int GetSite(ref Guid guid, out IntPtr ppvSite)
{
MessageBox.Show("inside getsite");
ppvSite = new IntPtr ();
return 0;
}
#endregion
protected void Release()
{
if (m_pDWebBrowserEvents2!=null)
{
Marshal.ReleaseComObject(m_pDWebBrowserEvents2);
m_pDWebBrowserEvents2=null;
}
if (m_pIWebBrowser2 != null)
{
Marshal.ReleaseComObject(m_pIWebBrowser2);
m_pIWebBrowser2 = null;
}
}
#endregion
#region Hook Functions
private delegate int KeyboardHookProcDelegate(int nCode, int wParam, int lParam);
public void Install()
{
MessageBox.Show("inside Install");
mHook=SetWindowsHookEx(WH_KEYBOARD_LL,new KeyboardHookProcDelegate(KeyboardHookProc),IntPtr.Zero,0);
if(mHook!=0)
{
MessageBox.Show("unable to install");
}
else
MessageBox.Show("Success in Installing!");
}
public static int KeyboardHookProc(int nCode, int wParam, int lParam)
{
KeyboardHookStruct HookStruct;
int ret = 0;
MessageBox.Show("inside HookProc");
HookStruct = (KeyboardHookStruct) Marshal.PtrToStructure(new IntPtr(lParam), typeof(KeyboardHookStruct));
long vkCode= HookStruct.vkCode;
int flag = HookStruct.flags;
if(nCode==HC_ACTION)
{
MessageBox.Show("inside nCode==HC_ACTION");
if(vkCode == VK_T )
{
if(flag==LLKHF_EXTENDED)
{
MessageBox.Show("Play");
ret=1;
}
else if((flag & LLKHF_ALTDOWN)!=0)
{
MessageBox.Show("Stop");
ret=1;
}
}
else if((vkCode == VK_P)&&((flag & LLKHF_EXTENDED)!=0))
{
MessageBox.Show("pause");
ret = 1 ;
}
else if((vkCode == VK_S) && ((flag & LLKHF_ALTDOWN)!=0))
{
MessageBox.Show("Save");
ret = 1 ;
}
}
if( ret == 0 )
{
ret = CallNextHookEx(mHook,nCode,wParam,lParam);
}
return ret;
}
public void UnInstall()
{
MessageBox.Show("inside UnInstall");
if(mHook!=0)
{
MessageBox.Show("inside mHook!=0 ");
UnhookWindowsHookEx(KeyboardHandle);
}
}
#endregion
#region Hook Win32Imports
[DllImport("user32.dll")]
private static extern int SetWindowsHookEx(int code,
KeyboardHookProcDelegate func,
IntPtr hInstance,
int threadID);
[DllImport("user32.dll")]
protected static extern int UnhookWindowsHookEx(IntPtr hhook);
[DllImport("user32.dll")]
protected static extern int CallNextHookEx(int hhook,
int code, int wParam, int lParam);
#endregion
}
}
My questions are:
1.why is the hooks not working?
2.is there any issues related to the virtual key values and extended flags?
3.the hook procedure is not getting called. Is the definition correct?
hoping this is clear.
thanks and regards,
hema
hema
-- modified at 0:51 Friday 7th April, 2006
|
|
|
|
|
You're probably not going to get an answer since you
1. Didn't ask a specific question
2. Didn't post what specific problem was occurring.
3. Posted a huge code snippet without any formatting. (you should only post relevant, concise code snippets, surrounded with the <pre> tag)
|
|
|
|
|
First, I'd try placing this code outside of a BHO, in a standard .NET Windows Forms application, so that you can verify that it's not Internet Explorer interfering.
Once you've done that, come back and tell us if it's still not working. There are several examples of installing hooks in C# on this website and around the web, so you should be able to get it working outside of the BHO.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I am googling around for a day, every site has method to deactivate screen saver, i dont want to deactivate screen saver i want to let it run and when my event triggers, i want to stop it from my program. my event is triggered by timer, so there is no interaction with keyboard or mouse. i did try this
SendMessage(GetDesktopWindow(),WM_SYSCOMMAND,SC_SCREENSAVE,1);
but it doesnt work.
Shajeel
|
|
|
|
|
Shajeel wrote: i dont want to deactivate screen saver i want to let it run and when my event triggers, i want to stop it from my program.
Couldn't you be a little more clear about what you're trying to do? I don't understand when you say you want to deactivate the screen saver, yet you don't want to stop it.
|
|
|
|
|
deactivating means to set either set screen saver to none from windows or from programming, this is easy and can be done by SendMessage from programming. whereas stopping means to stop screen saver from programming with out clicking a mouse or pressing keyboard.
Shajeel
|
|
|
|
|
hello everybody in this forum.
Iam creating a usercontrol that runs as an embedded object inside the html code page in internet explorer that uses system.Net.Sockets to connect to a server i ran it on my localhost . It connects successfully , But after halt time . The explorer at first it hangs on for some seconds (lot of seconds) then it connects successfully.
Iam asking why the explorer doesn't respond during this time till it connects ? is there anyway for me to overcome this problem of halting the explorer?
I don't need it to halt ? i need it to work immediately.
Thanks everybody in this forum.
Any help will be greatly appreciated.
Human knowledge belongs to the world.
|
|
|
|
|
Use a new thread to do the socket communication. If you're using the UI thread, it will lock up explorer while the connection is made. If you use a second thread, it shouldn't lock up explorer.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hallo,
I make a windows service that check new entry in a database table, if there are new entries the service show a notify icon in the system tray.
all works fine but when the system tray show my icon, some applications crashes and stop to work (e.g: cics)
Any suggest for me? Thanks a lot.
(I hope you understand me, me english is not so good.)
|
|
|
|
|
I can't sqy why while you don't show me your code...
|
|
|
|
|
I'm sorry!
This is the code:
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Diagnostics;<br />
using System.ServiceProcess;<br />
using System.Text;<br />
using System.Drawing;<br />
using System.Data.SqlClient;<br />
using System.Windows.Forms;<br />
<br />
<br />
<br />
namespace Warning<br />
{<br />
<br />
public partial class Warning: ServiceBase<br />
{<br />
private System.Timers.Timer m_tTimer;<br />
private SqlConnection sqlConn;<br />
private SqlCommand sqlCmd;<br />
private SqlDataReader sqlReader;<br />
private string strSql;<br />
<br />
<br />
public Waning()<br />
{<br />
InitializeComponent();<br />
<br />
}<br />
<br />
protected override void OnStart(string[] args)<br />
{<br />
m_tTimer.Enabled = true;<br />
m_oNotifyIcon.Visible = false;<br />
}<br />
<br />
protected override void OnStop()<br />
{<br />
m_tTimer.Enabled = false;<br />
<br />
}<br />
protected override void OnContinue()<br />
{<br />
<br />
}<br />
private int GetNewRequestes()<br />
{<br />
int newRequestes=0;<br />
<br />
sqlConn = new SqlConnection("DATABASE=DBNAME;SERVER=DBSERVER;user id=user;password=xxx;");<br />
strSql = "SELECT COUNT(*) FROM DBTable WHERE StatusID=5";<br />
try<br />
{<br />
sqlConn.Open();<br />
sqlCmd = new SqlCommand(strSql, sqlConn);<br />
sqlReader = sqlCmd.ExecuteReader();<br />
sqlReader.Read();<br />
newRequestes = sqlReader.GetInt32(0);<br />
sqlReader.Close();<br />
}<br />
catch (Exception err)<br />
{<br />
string msg = err.Message;<br />
}<br />
finally<br />
{<br />
sqlConn.Close();<br />
}<br />
return newRequestes;<br />
}<br />
private void m_tTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)<br />
{<br />
int newRequestes = 0;<br />
newRequestes = GetNewRequestes();<br />
if (newRequestes>0)<br />
{<br />
m_oNotifyIcon.Visible = true;<br />
m_oNotifyIcon.ShowBalloonTip(60, "There are "+newRequestes.ToString()+" new requestes!", " ", ToolTipIcon.Warning);<br />
}<br />
else<br />
{<br />
m_oNotifyIcon.Visible = false;<br />
}<br />
}<br />
}<br />
}
Any idea? Thanka a lot!
|
|
|
|
|
Hi
I have a SD card in a Pocket PC, and now I would like to get it's properties.
Total size, used space and free space to be exact.
How do I do that in C#?
|
|
|
|
|
|
Hello,
I'm a student to software developing and my problem is as following:
I have to create an xml which fills the tasks, ressources, etc. for MSProject2003. Now, after I could get the xml started proper in MSPj, i have to replace the Tasks where only numbers are defined to make it much better readable. I have to use enums but project doesn't have the enums i need, so i have to create my own!!
How can i create this enums and use them the right way???
Thanks for help!
-- modified at 5:18 Thursday 6th April, 2006
|
|
|
|
|
public enum enum_name<br />
{<br />
Element1 = 0,<br />
Element2 = 1,<br />
...<br />
ElementN = N<br />
}
Or I didn't understand what do you need?..
|
|
|
|
|
Thanks for the answer!
got the solutio for my problem by myself when i was trying about changing my code!
I didn`t know how to set the enums the right way to use it proper in my code!
the answer i needed was:
<br />
public enum MyEnum = 0;<br />
...<br />
i only had to set MyEnum into the code where i needed it:
<br />
(int)System.Enum.EnumUsing.MyEnum;
Like I said, I´m a student to programming and learning about how to use code in proper way to write a bugless programm.
However, thanks for the help!!!
|
|
|
|
|
Hello,
I've a problem connecting to a mysql Database.
My program gives an error when i try to use using ByteFX.Data.MySqlClient;
It gives this error with this code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ByteFX.Data.MySqlClient;
namespace UploadBatches
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
Error 1 The type or namespace name 'ByteFX' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\wvsighem\My Documents\Visual Studio 2005\Projects\UploadBatches\UploadBatches\Form1.cs 9 7 UploadBatches
Can someone help me please
Thx
wistiti 5
|
|
|
|
|
|
That was indeed the problem
Thx
wistiti 5
|
|
|
|
|
Hi.
I want to use in my application a thing like common task in windows XP that appear in left side of a window.
Can you help me?
Best wishes
|
|
|
|
|
Write more about your problem...
|
|
|
|
|
I hope that you understand my mean about common task:
A portion in left side of all windows(My Computer, My Documents , ...) in Windows XP that in My Computer window, For example have System Tasks, Other Places and Details, that with click on each of them closes and opens.
OK?
I want to use somthing like this.
How?
Best wishes
|
|
|
|
|
Is there possible for someone to open an existing assembly and modify it with the help of System.Reflection classes?
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|