又来提问 ~~~哥哥姐姐们帮帮忙~~~~
我是新手 刚学几天vc 下面是我写得代码
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int X=0;
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
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=WindowProc;
wndclass.lpszClassName="ran003";
wndclass.lpszMenuName=NULL;
wndclass.style=0;
RegisterClass(&wndclass);
hwnd=CreateWindow("ran003","动呀动",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,600,450,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
while(GetMessage(&Msg,hwnd,NULL,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
HDC hdc;
HBRUSH hBrush;
HPEN hp;
PAINTSTRUCT ps;
int Y=X*X;
switch(uMsg)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SetMapMode(hdc,MM_ANISOTROPIC);
SetWindowExtEx(hdc,400,300,NULL);
SetViewportExtEx(hdc,600,450,NULL);
SetViewportOrgEx(hdc,300,200,NULL);
hBrush=CreateSolidBrush(RGB(255,0,255));
SelectObject(hdc,hBrush);
hp=CreatePen(PS_SOLID,1,RGB(255,0,255));
SelectObject(hdc,hp);
Ellipse(hdc,Y-5,X-5,Y+5,X+5);
X++;Y++;
Sleep(1000);
InvalidateRect(hwnd,NULL,1);
EndPaint(hwnd,&ps);
return 0;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
这里有两个问题 第一是我每次把这个窗口关了后,可是进程里却还有“ran003.exe”,可能是sleep出了问题 我不知道怎么该 看了一天set/ontimer 硬是没学会 试了一个晚上也不行 我要重绘
第二是 我不知道那两个变量X Y 到底要放在那儿 因为这两个变量是在不断变化的 我每次改变两个 这个圆却只在一条直线上运动
谢谢各位了~~~~