换了新电脑,新的键盘上居然没有power键和printscreen,气死……
我设想:printscreen怎么也算是功能键吧,defwindowproc应该行…………
然后就有以下这个简单的程序:
#include"windows.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR iCmdLine,int iCmdshow)
{
static TCHAR szAppName[]=TEXT("printscreen");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
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("ERROR!!!"),szAppName,MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName,TEXT("print the screen"),WS_OVERLAPPEDWINDOW,10,10,100,100,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)
{
HDC hdc;
PAINTSTRUCT ps;
TCHAR szBuffer[30];
switch(message)
{
case WM_CREATE:
SendMessage(hwnd,WM_KEYDOWN,VK_SNAPSHOT,0);
return 0;
case WM_KEYDOWN:
switch(wParam)
{
case VK_SNAPSHOT:
break;
}
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,szBuffer,
wsprintf(szBuffer,TEXT("the screen has been snap")));
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
然后……正如你所料………………米有成功…………
为什么??????
高手快来解答…………………………
[yct10][yct10]