更新时间:2015-12-28 17:23:07浏览次数:1+次
我们先看看我们实现的拉手风琴的动态效果图:
BOOL InflateRect(LPRECT lprc,int dx,int dy);
第二个参数就是调整宽度的,正数宽度向两边增大,每一边都增大dx。如果是负数,就是两边都减少dx。同理第三个参数用于调整高度。如果调整成功,则返回非零,否则返回0。#include "windows.h"
#include <tchar.h>
// - 项目是Unicode字符集
LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static RECT rect,rectClient;
static int x=10;//每次x轴上移动的单位
static int y=10;//每次y轴上移动的单位
switch (message)
{
case WM_CREATE:
SetRect(&rect,500,0,800,100);//设置矩形的大小
SetTimer(hwnd,0,50,NULL);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
InflateRect(&rect,x,0);
SelectObject(hdc,GetStockObject(LTGRAY_BRUSH));
Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
if (rect.right-rect.left>200||rect.right-rect.left<-200)
{
x=-x;
}
EndPaint(hwnd,&ps);
return 0;
case WM_TIMER:
InvalidateRect(hwnd,NULL,TRUE);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrev,LPSTR lpCmd,int iShow)
{
TCHAR ClassName[] = _T("MyClass");
TCHAR title1[] = _T("C++技术网http://www.cjjjs.com");
WNDCLASS wndClass;
wndClass.cbClsExtra=0;
wndClass.cbWndExtra=0;
wndClass.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.hCursor=LoadCursor(NULL,IDC_HAND);
wndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = WinProc;
wndClass.lpszClassName = ClassName;
wndClass.lpszMenuName=NULL;
wndClass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&wndClass))return 0;
HWND hwnd = CreateWindow(ClassName,title1,WS_OVERLAPPEDWINDOW,0,0,440,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
相关资讯