DeleteObject(hbitmap); /*char buff[20]; _itoa(rect.top,buff,10); MessageBox(buff); _itoa(rect.left,buff,10); MessageBox(buff); _itoa(rect.bottom,buff,10); MessageBox(buff); _itoa(rect.right,buff,10); MessageBox(buff);*/ break; case WM_LBUTTONDOWN: int x,y; RECT rect; x=LOWORD(lParam); y=HIWORD(lParam); POINT p; p.x=x; p.y=y; //the '~' rect=CRect(0,0,25,27); if (PtInRect(&rect,p)) { keybd_event(0xC0,0,0,0); keybd_event(0xC0,0,KEYEVENTF_KEYUP,0); if (gShift==true) { keybd_event(0x20,0,KEYEVENTF_KEYUP,0); } } //'1' rect=CRect(25,0,50,27); if (PtInRect(&rect,p)) { keybd_event(0x31,0,0,0); keybd_event(0x31,0,KEYEVENTF_KEYUP,0); if (gShift==true) { keybd_event(0x20,0,KEYEVENTF_KEYUP,0); } } //'2' rect=CRect(50,0,75,27); if (PtInRect(&rect,p)) { keybd_event(0x32,0,0,0); keybd_event(0x32,0,KEYEVENTF_KEYUP,0); if (gShift==true) { keybd_event(0x20,0,KEYEVENTF_KEYUP,0); } } //'3' rect=CRect(75,0,100,27); if (PtInRect(&rect,p)) { keybd_event(0x33,0,0,0); keybd_event(0x33,0,KEYEVENTF_KEYUP,0); if (gShift==true) { keybd_event(0x20,0,KEYEVENTF_KEYUP,0); } } //'4' rect=CRect(100,0,125,27); if (PtInRect(&rect,p)) { keybd_event(0x34,0,0,0); keybd_event(0x34,0,KEYEVENTF_KEYUP,0); if (gShift==true) { keybd_event(0x20,0,KEYEVENTF_KEYUP,0); } } ------------- //'5' }} 就是处理它的窗口的消息处理函数,我给你写一个DELPHI的
对了,在DELPHI的DEMOS中有个APPEVENTS这个例子,你看看就会明白了!
你看看DELPHI中的DEMOS中的APPEVENTS这个讲得挺好了
我的意思是在窗体上有控件,比如BUTTON,我在它上面击鼠标左键,如何捕获这一消息。
function WindowProc(hWnd, uMsg, wParam, lParam: Integer): Integer; stdcall; begin Result := DefWindowProc(hWnd, uMsg, wParam, lParam); { Checks for messages } if (lParam = Button1) and (uMsg = WM_COMMAND) then CheckPassword; if uMsg = WM_DESTROY then Halt; end;
Determines whether an application message requires hiding the hint window.type TMsg = packed record hwnd: HWND; message: UINT; wParam: WPARAM; lParam: LPARAM; time: DWORD; pt: TPoint; end;function IsHintMsg(var Msg: TMsg): Boolean; virtual;DescriptionCall IsHintMsg to determine whether the message specified by the Msg parameter requires hiding the hint window. Upon seeing a mouse, keyboard, command, or activation message, IsHintMsg returns True. The global Application object calls IsHintMsg to check messages while the hint window is on the screen, and hides the window if IsHintMsg returns True.
LRESULT CTopEisKeyboardCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch(message)
{
case WM_ACTIVATE:
MSG msg;
wParam=WA_INACTIVE;
msg.wParam=wParam;
msg.lParam=wParam;
msg.message=message;
msg.hwnd=hwnd;
DispatchMessage(&msg);
break;
case WM_MOUSEACTIVATE:
return MA_NOACTIVATE;
break;
case WM_SETFOCUS:
{
::PostMessage(hwnd,WM_KILLFOCUS,0,0);
CWnd *wnd=::AfxGetMainWnd();
HWND hwndwnd=wnd->m_hWnd;
lihao=hwndwnd;
::SetFocus(hwndwnd);
//&&gFocus!=NULL
/*if (hwndwnd!=gFocus)
{
::SetFocus(gFocus);
char buffer[9];
long l=(long)gFocus;
_ltoa(l,buffer,16);
//MessageBox(buffer);
}*/
}
break;
case WM_KILLFOCUS:
{
//::SetFocus(lihao);
/*if (hwndwnd!=hwnd)
b=::PostMessage(hwndwnd,WM_MOUSEACTIVATE,0,0);
if (b)
{
::SetFocus(hwndwnd);
lihao=hwndwnd;
}9*/
}
case WM_DESTROY:
if (gShift==true)
{
keybd_event(0x20,0,KEYEVENTF_KEYUP,0);
}
break;
case WM_CREATE:
CWnd *wnd;
//MSG msg;
hwnd=CWnd::m_hWnd;
wnd=AfxGetMainWnd();
hInst=AfxGetResourceHandle();
//HANDLE hmutex;
//LPCTSTR szAppName;
//CreateMutex
/*while (GetMessage(&msg,NULL,0,0))
{
HWND hwndx=::GetForegroundWindow();
//BringWindowToTop(hwndMain);
if (IsWindow(hwndx))
{
if (hwndx!=hwnd)
{
if (gFocus!=hwndx)
{
if (IsWindow(gFocus))
{
AttachThreadInput(GetWindowThreadProcessId(hwnd,NULL),GetWindowThreadProcessId(gFocus,NULL),false);
}
gFocus=hwndx;
AttachThreadInput(GetWindowThreadProcessId(hwnd,NULL),GetWindowThreadProcessId(gFocus,NULL),true);
}
}
}
if (!hwnd||!::IsDialogMessage(hwnd,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} //ReleaseMutex(hMutex);
return(msg.wParam );*/
//AfxGetInstanceHandle();
/*char buffer[20];
long l=(long)hInst;
_ltoa(l,buffer,16);
//MessageBox(buffer);
/*MessageBox("next");
HINSTANCE hin=AfxGetInstanceHandle();
l=(long)hin;
_ltoa(l,buffer,16);
MessageBox(buffer);*/
/*HDC hdc;
HDC hMemdc;
HBITMAP hbitmap;
BITMAP bm;
hbitmap=LoadBitmap(hInst,"IDB_KEYBOARD");
GetObject(hbitmap,sizeof(BITMAP),&bm);
hdc=::GetDC(hwnd);
hMemdc=CreateCompatibleDC(hdc);
GetClientRect(&rect);
StretchBlt(hdc,0,0,rect.right,rect.bottom,hMemdc,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
DeleteDC(hMemdc);
::ReleaseDC(hwnd,hdc);
DeleteObject(hbitmap); /*char buff[20];
_itoa(rect.top,buff,10);
MessageBox(buff);
_itoa(rect.left,buff,10);
MessageBox(buff);
_itoa(rect.bottom,buff,10);
MessageBox(buff);
_itoa(rect.right,buff,10);
MessageBox(buff);*/
break;
case WM_LBUTTONDOWN:
int x,y;
RECT rect;
x=LOWORD(lParam);
y=HIWORD(lParam);
POINT p;
p.x=x;
p.y=y;
//the '~'
rect=CRect(0,0,25,27);
if (PtInRect(&rect,p))
{
keybd_event(0xC0,0,0,0);
keybd_event(0xC0,0,KEYEVENTF_KEYUP,0);
if (gShift==true)
{
keybd_event(0x20,0,KEYEVENTF_KEYUP,0);
}
}
//'1'
rect=CRect(25,0,50,27);
if (PtInRect(&rect,p))
{
keybd_event(0x31,0,0,0);
keybd_event(0x31,0,KEYEVENTF_KEYUP,0);
if (gShift==true)
{
keybd_event(0x20,0,KEYEVENTF_KEYUP,0);
}
}
//'2'
rect=CRect(50,0,75,27);
if (PtInRect(&rect,p))
{
keybd_event(0x32,0,0,0);
keybd_event(0x32,0,KEYEVENTF_KEYUP,0);
if (gShift==true)
{
keybd_event(0x20,0,KEYEVENTF_KEYUP,0);
}
}
//'3'
rect=CRect(75,0,100,27);
if (PtInRect(&rect,p))
{
keybd_event(0x33,0,0,0);
keybd_event(0x33,0,KEYEVENTF_KEYUP,0);
if (gShift==true)
{
keybd_event(0x20,0,KEYEVENTF_KEYUP,0);
}
}
//'4'
rect=CRect(100,0,125,27);
if (PtInRect(&rect,p))
{
keybd_event(0x34,0,0,0);
keybd_event(0x34,0,KEYEVENTF_KEYUP,0);
if (gShift==true)
{
keybd_event(0x20,0,KEYEVENTF_KEYUP,0);
}
}
-------------
//'5'
}}
就是处理它的窗口的消息处理函数,我给你写一个DELPHI的
begin
Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
{ Checks for messages }
if (lParam = Button1) and (uMsg = WM_COMMAND) then
CheckPassword;
if uMsg = WM_DESTROY then
Halt;
end;
msg.message就是如左键呀等
msg.lparam就是具体的某个控件
hwnd: HWND;
message: UINT;
wParam: WPARAM;
lParam: LPARAM;
time: DWORD;
pt: TPoint; end;function IsHintMsg(var Msg: TMsg): Boolean; virtual;DescriptionCall IsHintMsg to determine whether the message specified by the Msg parameter requires hiding the hint window. Upon seeing a mouse, keyboard, command, or activation message, IsHintMsg returns True. The global Application object calls IsHintMsg to check messages while the hint window is on the screen, and hides the window if IsHintMsg returns True.
上边的意思是LPARM指某个控件,那WPARM指什么,谢谢!!