Hook:勾子,实现对消息的过滤,例如安装过程中屏蔽对键盘与鼠标的操作使不影响安装进程
创建hook
void SetHook(HWND hwnd)
{
g_hWnd=hwnd;
g_hMouse=SetWindowsHookEx(WH_MOUSE,MouseProc,GetModuleHandle("Hook"),0);
g_hKeyboard=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,GetModuleHandle("Hook"),0);
}
不同类型hook的回调函数,这个鼠标的过程函数
LRESULT CALLBACK MouseProc(
int nCode, // hook code
WPARAM wParam, // message identifier
LPARAM lParam // mouse coordinates
)
{
return 1;
}
这个键盘的过程函数
LRESULT CALLBACK KeyboardProc(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
)
{
if(VK_F2==wParam)
{
SendMessage(g_hWnd,WM_CLOSE,0,0);
UnhookWindowsHookEx(g_hMouse);
UnhookWindowsHookEx(g_hKeyboard);
}
return 1;
}
DataBase:主要是ODBC连接方式,三大核心:connection、command、recordset
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
_CommandPtr pCmd(__uuidof(Command));
pConn->ConnectionString="Provider=SQLOLEDB;Data Source=.;Persist Security Info=False;User ID=sa;PassWord=XXX;Initial Catalog=XXX";
pConn->Open("","","",adConnectUnspecified);
//pRst=pConn->Execute("select CHANNNO from channel ",NULL,adCmdText);
//pRst->Open("select CHANNNO from channel",_variant_t((IDispatch*)pConn),
// adOpenDynamic,adLockOptimistic,adCmdText);
pCmd->PutActiveConnection(_variant_t((IDispatch*)pConn));
pCmd->CommandText="select CHANNNO from channel";
pRst=pCmd->Execute(NULL,NULL,adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString(
(_bstr_t)pRst->GetCollect("CHANNNO"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pCmd.Release();
pRst.Release();
pConn.Release();
CoUninitialize();