求助:哪个高手能告诉我为什么下面这个程序的问题。
问题如下,程序在执行SHIFT+左键后停止随机变换屏幕颜色,然后如果我再按下CTRL键就会产生一条线....非常不解....先谢过大家了~#include<windows...
问题如下,程序在执行SHIFT+左键后停止随机变换屏幕颜色,然后如果我再按下CTRL键就会产生一条线....非常不解....先谢过大家了~
#include <windows.h>
#define MY_TIMER 1
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,PARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=TEXT("MyMainClass");
wndclass.lpszMenuName=NULL;
wndclass.style=CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("Window Class registers fail!Error code:1"),TEXT("Error"),MB_OK);
return -1;
}
HWND hwnd=CreateWindow(TEXT("MyMainClass"),TEXT("Application"), WS_OVERLAPPEDWINDOW | WS_VSCROLL | WSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,NULL,hInstance,NULL);
if(!hwnd)
{
MessageBox(NULL,TEXT("Window creates fail!Error code:2"),TEXT ("Error"),MB_OK);
return -1;
}
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(TRUE)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message==WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
/* else
DrawRndRect(hwnd);*/
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Msg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static RECT rect;
HBRUSH hBrush;
switch(Msg)
{
case WM_DESTROY:
KillTimer(hwnd,MY_TIMER);
PostQuitMessage(0);
return 0;
case WM_CREATE:
SetTimer(hwnd,MY_TIMER,100,NULL);
return 0;
case WM_LBUTTONDOWN:
if(wParam&MK_SHIFT)
KillTimer(hwnd,MY_TIMER);
return 0;
case WM_RBUTTONDOWN:
if(wParam&MK_SHIFT)
SetTimer(hwnd,MY_TIMER,100,NULL);
return 0;
case WM_TIMER:
InvalidateRect(hwnd,NULL,TRUE);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
hBrush=CreateSolidBrush(RGB(rand()%256,rand()%256,rand()%256));
FillRect(hdc,&rect,hBrush);
DeleteObject(hBrush);
EndPaint(hwnd,&ps);
return 0;
}
return DefWindowProc(hwnd,Msg,wParam,lParam);
} 展开
#include <windows.h>
#define MY_TIMER 1
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,PARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=TEXT("MyMainClass");
wndclass.lpszMenuName=NULL;
wndclass.style=CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("Window Class registers fail!Error code:1"),TEXT("Error"),MB_OK);
return -1;
}
HWND hwnd=CreateWindow(TEXT("MyMainClass"),TEXT("Application"), WS_OVERLAPPEDWINDOW | WS_VSCROLL | WSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,NULL,hInstance,NULL);
if(!hwnd)
{
MessageBox(NULL,TEXT("Window creates fail!Error code:2"),TEXT ("Error"),MB_OK);
return -1;
}
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(TRUE)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message==WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
/* else
DrawRndRect(hwnd);*/
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Msg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static RECT rect;
HBRUSH hBrush;
switch(Msg)
{
case WM_DESTROY:
KillTimer(hwnd,MY_TIMER);
PostQuitMessage(0);
return 0;
case WM_CREATE:
SetTimer(hwnd,MY_TIMER,100,NULL);
return 0;
case WM_LBUTTONDOWN:
if(wParam&MK_SHIFT)
KillTimer(hwnd,MY_TIMER);
return 0;
case WM_RBUTTONDOWN:
if(wParam&MK_SHIFT)
SetTimer(hwnd,MY_TIMER,100,NULL);
return 0;
case WM_TIMER:
InvalidateRect(hwnd,NULL,TRUE);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
hBrush=CreateSolidBrush(RGB(rand()%256,rand()%256,rand()%256));
FillRect(hdc,&rect,hBrush);
DeleteObject(hBrush);
EndPaint(hwnd,&ps);
return 0;
}
return DefWindowProc(hwnd,Msg,wParam,lParam);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询