2008年12月4日 星期四

防止重複執行程式

//防止重複執行程式
//方法一
HANDLE h = CreateMutex(NULL, TRUE, L"xxxxx");
if((h == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS)) {
MessageBox(NULL,L"系統中已經有重複的程式正在執行",L"Error",MB_OK);
return 0;
}
//方法二
HWND h = FindWindow(NULL, L"xxxxx");
if(h != NULL) {
MessageBox(NULL,L"系統中已經有重複的程式正在執行",L"Error",MB_OK);
return 0;
}
//方法三
HANDLE h = CreateEvent(NULL, FALSE, FALSE, L"xxxxx");
if((h == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS)) {
MessageBox(NULL,L"系統中已經有重複的程式正在執行",L"Error",MB_OK);
return 0;
}

2008年12月1日 星期一

[轉貼]偵測觸控筆持續押著螢幕的事件

在eVC中..
可以在OnLBottonDown使用SHRecognizeGesture(point, FALSE)函式
來偵測觸控筆持續押著螢幕的事件...

[轉貼]模擬滑鼠及鍵盤事件

由虛擬碼而知當
key=1表示您按下了滑鼠的左鍵
key=2表示您按下了滑鼠的右鍵依此類推...

keybd_event();是模擬鍵盤的動作(按下某個鍵)
mouse_event();是模擬滑鼠的動作
==================================
如何用程式觸發滑鼠按鍵的事件(如何模擬滑鼠的按鍵)
模擬滑鼠按左鍵:
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);// click down
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);// click down
模擬滑鼠按Double Click:
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);// click down
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);// click down
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);// click down
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);// click down
模擬滑鼠按右鍵:
mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);// click down
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);// click down
==================================
如何用程式觸發鍵盤按鍵的事件(模擬鍵盤按鍵)
對Form1觸發Tab按鍵按下事件:
PostMessage(form1.Handle, WM_KEYDOWN, VK_TAB, 0);
對Edit1觸發Enter按鍵按下事件:
PostMessage(edit1.Handle, WM_KEYDOWN, VK_RETURN, 0);
對Edit1觸發Enter按鍵放開事件:
PostMessage(edit1.Handle, WM_KEYUP, VK_F1, 0);
對Edit1觸發 1 按鍵按下事件:
PostMessage(edit1.Handle, WM_KEYDOWN, 49, 0);
對Edit1觸發 A 按鍵按下事件:
PostMessage(edit1.Handle, WM_KEYDOWN, 65, 0);
==================================

[轉貼]鍵盤上的 key 對應查詢表

F1~F12 對應為 $70(112)~$7B(123)
A~Z 對應為 $41(65)~$5A(90)
0~9 對應為 $30(48)~$39(57)

鍵 十六進位 十進位 說明
----------------------------------------------------------------------
vk_LButton = $01; 1 滑鼠左鈕
vk_RButton = $02; 2 滑鼠右鈕
vk_Cancel = $03; 3 Control-Break 執行
vk_MButton = $04; 4 滑鼠中鈕
05-07 5-7 { NOT contiguous with L & RBUTTON }
vk_Back = $08; 8 BackSpace 鍵
vk_Tab = $09; 9 AB鍵
0A-0B 10-11 未定義
vk_Clear = $0C; 12 Clear
vk_Return = $0D; 13 Enter
0E-0F 14-15 未定義
vk_Shift = $10; 16 Shift
vk_Control = $11; 17 Ctrl
vk_Menu = $12; 18 Alt
vk_Pause = $13; 19 Pause
vk_Capital = $14; 20 Caps Lock
15-19 21-25 保留給Kanji使用
1A 26 未定義
vk_Escape = $1B; 27 Esc
1C-1F 29-31 保留給Kanji使用
vk_Space = $20; 32 SpaceBar
vk_Prior = $21; 33 Page Up
vk_Next = $22; 34 Page Down
vk_End = $23; 35 End
vk_Home = $24; 36 Home
vk_Left = $25; 37 Left Arrow
vk_Up = $26; 38 Up Arrow
vk_Right = $27; 39 Right Arrow
vk_Down = $28; 40 Down Arrow
vk_Select = $29; 41 Select
vk_Print = $2A; 42 OEM自訂使用
vk_Execute = $2B; 43 Execute
vk_SnapShot = $2C; 44 Print Screen
///////{ vk_Copy = $2C not used by keyboards }
vk_Insert = $2D; 45 Ins
vk_Delete = $2E; 46 Del
vk_Help = $2F; 47 Help
{ vk_0 thru vk_9 are the same as their ascii equivalents: '0' thru '9' }
vk_0 $30 48
vk_1 31 49
vk_2 32 50
vk_3 33 51
vk_4 34 52
vk_5 35 53
vk_6 36 54
vk_7 37 55
vk_8 38 56
vk_9 39 57
3A-40 58-64 未定義
////{ vk_A thru vk_Z are the same as their ASCII equivalents: 'A' thru 'Z' }
vk_A $41 65
vk_B 42 66
vk_C 43 67
vk_D 44 68
vk_E 45 69
vk_F 46 70
vk_G 47 71
vk_H 48 72
vk_I 49 73
vk_J 4A 74
vk_K 4B 75
vk_L 4C 76
vk_M 4D 77
vk_N 4E 78
vk_O 4F 79
vk_P 50 80
vk_Q 51 81
vk_R 52 82
vk_S $53 83
vk_T 54 84
vk_U 55 85
vk_V 56 86
vk_W 57 87
vk_X 58 88
vk_Y 59 89
vk_Z 5A 90
5B-5C 91-95 未定義
vk_NumPad0 = $60; 96 數字鍵
vk_NumPad1 = $61; 97 數字鍵
vk_NumPad2 = $62; 98 數字鍵
vk_NumPad3 = $63; 99 數字鍵
vk_NumPad4 = $64; 100 數字鍵
vk_NumPad5 = $65; 101 數字鍵
vk_NumPad6 = $66; 102 數字鍵
vk_NumPad7 = $67; 103 數字鍵
vk_NumPad8 = $68; 104 數字鍵
vk_NumPad9 = $69; 105 數字鍵
vk_Multiply = $6A; 106 * 鍵
vk_Add = $6B; 107 + 鍵
vk_Separator = $6C; 108 Separator 鍵
vk_Subtract = $6D; 109 -- 鍵
vk_Decimal = $6E; 110 . 鍵
vk_Divide = $6F; 111 / 鍵
vk_F1 = $70; 112
vk_F2 = $71; 113
vk_F3 = $72; 114
vk_F4 = $73; 115
vk_F5 = $74; 116
vk_F6 = $75; 117
vk_F7 = $76; 118
vk_F8 = $77; 119
vk_F9 = $78; 120
vk_F10 = $79; 121
vk_F11 = $7A; 122
vk_F12 = $7B; 123
vk_F13 = $7C; 124
vk_F14 = $7D; 125
vk_F15 = $7E; 126
vk_F16 = $7F; 127
vk_F17 = $80; 128
vk_F18 = $81; 129
vk_F19 = $82; 130
vk_F20 = $83; 131
vk_F21 = $84; 132
vk_F22 = $85; 133
vk_F23 = $86; 134
vk_F24 = $87; 135
88-8F; 136-143 未指定
vk_NumLock = $90; 144 Num Lock
vk_Scroll = $91; 145 Scroll Lock
92-B9; 146-185 未指定
BA-C0; 186-192 OEM自訂
C1-DA; 193-218 未指定
DB-E4; 219-228 OEM自訂
E5 ; 229 未指定
E6 ; 230 OEM自訂
E7-E8; 231-232 未指定
E9-F5; 233-245 OEM自訂
F6-FE; 246-254 未指定
============================================