为什么不能连续画线?
#include <windows.h>#define UP 0
#define DOWN 1
#define LEFT 2
#define RIGHT 3
int x=0;
int y=0;LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
void draw();
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpcmdline,
int nshowcmd
){ char name[]="hi";
HWND hwnd;
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 =name;
wndclass.lpszMenuName =NULL;
wndclass.style =CS_HREDRAW | CS_VREDRAW; if(!RegisterClass(&wndclass))
{
MessageBox(NULL,"NT NOT SUPPORT","Caption",0);
return 0;
} hwnd=CreateWindow(name,
"nihao",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL); ShowWindow(hwnd,nshowcmd);
UpdateWindow(hwnd); while(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg); } return msg.wParam ;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps; switch(message)
{
case WM_CREATE: return 0;
case WM_PAINT:
return 0;
case WM_KEYDOWN:
switch (wParam)
{
case VK_UP:
draw(hwnd,&x,&y,UP );
return 0;
case VK_DOWN:
draw(hwnd,&x,&y,DOWN);
return 0;
case VK_LEFT:
draw(hwnd,&x,&y,LEFT);
return 0;
case VK_RIGHT:
draw(hwnd,&x,&y,RIGHT);
return 0; } return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
} return DefWindowProc(hwnd,message,wParam,lParam);
}void draw(HWND hwnd,int *x1,int *y1,int d)
{ PAINTSTRUCT ps;
HDC hdc;
hdc=BeginPaint(hwnd,&ps);
switch(d)
{case 0:
MoveToEx(hdc,*x1,*y1,NULL);
LineTo(hdc,0,*y1-100);
*x1+=0;
*y1-=100;
return 0;
case 1: MoveToEx(hdc,*x1,*y1,NULL);
LineTo(hdc,0,*y1+100);
(*x1)+=0;
(*y1)+=100;
return 0;case 2:
MoveToEx(hdc,*x1,*y1,NULL);
LineTo(hdc,*x1-100,0);
(*x1)-=100;
(*y1)+=0;
return 0;
case 3:
MoveToEx(hdc,*x1,*y1,NULL);
LineTo(hdc,*x1+100,0);
(*x1)+=100;
(*y1)+=0;
return 0;
}
EndPaint(hwnd,&ps);
}
#include <windows.h>#define UP 0
#define DOWN 1
#define LEFT 2
#define RIGHT 3
int x=0;
int y=0;LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
void draw();
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpcmdline,
int nshowcmd
){ char name[]="hi";
HWND hwnd;
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 =name;
wndclass.lpszMenuName =NULL;
wndclass.style =CS_HREDRAW | CS_VREDRAW; if(!RegisterClass(&wndclass))
{
MessageBox(NULL,"NT NOT SUPPORT","Caption",0);
return 0;
} hwnd=CreateWindow(name,
"nihao",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL); ShowWindow(hwnd,nshowcmd);
UpdateWindow(hwnd); while(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg); } return msg.wParam ;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps; switch(message)
{
case WM_CREATE: return 0;
case WM_PAINT:
return 0;
case WM_KEYDOWN:
switch (wParam)
{
case VK_UP:
draw(hwnd,&x,&y,UP );
return 0;
case VK_DOWN:
draw(hwnd,&x,&y,DOWN);
return 0;
case VK_LEFT:
draw(hwnd,&x,&y,LEFT);
return 0;
case VK_RIGHT:
draw(hwnd,&x,&y,RIGHT);
return 0; } return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
} return DefWindowProc(hwnd,message,wParam,lParam);
}void draw(HWND hwnd,int *x1,int *y1,int d)
{ PAINTSTRUCT ps;
HDC hdc;
hdc=BeginPaint(hwnd,&ps);
switch(d)
{case 0:
MoveToEx(hdc,*x1,*y1,NULL);
LineTo(hdc,0,*y1-100);
*x1+=0;
*y1-=100;
return 0;
case 1: MoveToEx(hdc,*x1,*y1,NULL);
LineTo(hdc,0,*y1+100);
(*x1)+=0;
(*y1)+=100;
return 0;case 2:
MoveToEx(hdc,*x1,*y1,NULL);
LineTo(hdc,*x1-100,0);
(*x1)-=100;
(*y1)+=0;
return 0;
case 3:
MoveToEx(hdc,*x1,*y1,NULL);
LineTo(hdc,*x1+100,0);
(*x1)+=100;
(*y1)+=0;
return 0;
}
EndPaint(hwnd,&ps);
}
解决方案 »
- 用户区上显示图片,图片上有非模态对话框,拖动图片时,在XP系统下图片表现不完整(对话框处),在win7上表现正常,是什么原因?
- 管理系统的一个问题
- GetCookie问题
- 关于用CRecordset里的Edit()进行修改的问题
- 开新公司征集公司名称,参与有分!!!
- 为什么会 Debug Assertation Failed!
- 请问:如何获取当前操作系统的语言类型?(100)
- 谁能给我一个枚举系统中所有进程,并查找某一特定进程名的源代码?100分!!
- 我在CDHtmlDialog中打开一个页面!如果点击页面中带.exe的url地址,会出现下载对话框,如何屏蔽这种IE默认的下载对话框??
- assert()这个函数是干什么的?
- 二维数组的问题
- 在ADO 中如何取得Access 数据库中各字段的标题?
连续画线?是什么意思?