I'm building a word lookup application that runs in system tray and when you scan a block of a few words and then press a hotkey combination like Shift + C + V for example.
However, the problem is that when I test it on my personal machine, it works fine. But when through tester's machine, it is not possible to catch the selected text event.
I'm using MouseKeyHook's library.
May everyone help you
Here is my code
public partial class Main : Form
{
private int borderSize = 2;
private Color borderColor = Color.FromArgb(128, 128, 255);
ManageDictionary manage;
MySqlConnection conn;
private IKeyboardMouseEvents globalMouseHook;
[DllImport("user32.DLL", EntryPoint = "ReleaseCapture")]
private extern static void ReleaseCapture();
[DllImport("user32.DLL", EntryPoint = "SendMessage")]
private extern static void SendMessage(System.IntPtr hWnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetActiveWindow(IntPtr hWnd);
private int isOpen;
public Main()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
this.Padding = new Padding(borderSize);
this.panel2.BackColor = borderColor;
this.BackColor = borderColor;
this.Subscribe();
manage = new ManageDictionary();
conn = ConnectDB.Connect();
SetActiveWindow(this.Handle);
}
private void Subscribe()
{
globalMouseHook = Hook.GlobalEvents();
globalMouseHook.MouseDragFinished += MouseDragFinished;
}
private void Unsubscribe()
{
globalMouseHook.MouseDragFinished -= MouseDragFinished;
globalMouseHook.Dispose();
}
private void resetConnection()
{
conn.Close();
conn = ConnectDB.Connect();
isOpen = 0;
}
private void showResult()
{
string content = this.txtSearch.Text.Trim();
if (content.Equals(""))
{
MessageBox.Show("Không tìm thấy từ khoá");
return;
}
else
{
this.displayNotification(content);
}
}
private void displayNotification(string content)
{
ArrayList re = new ArrayList();
try
{
//If the connection isn't open, it will open and set value of isOpen parameter to 1
conn.Open();
re = manage.findWord(conn, content);
if (re.Count == 0)
{
Dictionary a = new Dictionary(0, "Không tìm thấy kết quả", "", "", "", "");
re.Add(a);
Notification noti = new Notification(re, content);
noti.TopMost = true;
Thread.Sleep(100);
noti.Show();
}
else
{
Notification noti = new Notification(re, content);
noti.TopMost = true;
Thread.Sleep(2000);
noti.Show();
}
}
catch (MySqlException)
{
MessageBox.Show("MySQL chưa được khởi động hoặc tên CSDL bị sai\r\nVui lòng kiểm tra lại");
}
catch (SocketException)
{
MessageBox.Show("Không kết nối được với cơ sở dữ liệu");
}
catch (Exception ex)
{
MessageBox.Show("Kết nối thất bại\r\n"+ ex.Message);
}
conn.Close();
isOpen = 0;
}