主题:怎么设置键盘上,下,左,右,类移动图片
#include <windows.h>
#include "resource.h"
HBITMAP hBm; //用HBITMAP指向资源内的图片
BITMAP bm; //存储位图信息结构体
HDC hdc; //得到当前窗口得环境设备描述表
HDC hdcmem; //把位图存放在内存中时需使用得内存环境设备描述表
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("Typer") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
hBm = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP1));
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox ( NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow ( szAppName, TEXT ("Typing Program"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc ( HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)
{
static int cxChar, cyChar, xCaret, yCaret ;
static TCHAR * pBuffer = NULL ;
HDC hdc ;
PAINTSTRUCT ps ;
switch (message)
{
case WM_CREATE:
hdc = GetDC (hwnd) ;
hdcmem = CreateCompatibleDC(hdc);
SelectObject(hdcmem,hBm);
GetObject(hBm,sizeof(BITMAP),&bm);
cxChar = bm.bmWidth;
cyChar = bm.bmHeight;
ReleaseDC (hwnd, hdc) ;
case WM_SETFOCUS:
CreateCaret (hwnd, hBm, cxChar, cyChar) ;
SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
ShowCaret (hwnd) ;
return 0 ;
case WM_KILLFOCUS:
HideCaret (hwnd) ;
DestroyCaret () ;
return 0 ;
case WM_KEYDOWN:
switch (wParam)
{
case VK_LEFT:
xCaret = xCaret- 1 ;
break ;
case VK_RIGHT:
xCaret = xCaret+ 1 ;
break ;
case VK_UP:
yCaret = yCaret - 1 ;
break ;
case VK_DOWN:
yCaret = yCaret + 1 ;
break ;
}
SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
SelectObject(hdcmem,hBm);
BitBlt(hdc,xCaret,yCaret,bm.bmWidth,bm.bmHeight,hdcmem,0,0,SRCCOPY);
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
按键图片没动没用,那个高手帮下忙,怎么写才好