更新时间:2016-01-13 18:13:01浏览次数:1+次
下面是我们实现的效果图:
#include "windows.h"
#include <tchar.h>
TCHAR tip[100]=_T("");
TCHAR txt[100]=_T("C++技术网www.cjjjs.com");
// - 项目是Unicode字符集
LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static RECT rect;
static int iRotate=0;
switch (message)
{
case WM_CREATE:
SetRect(&rect,10,40,200,200);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
TextOut(hdc,2,10,txt,lstrlen(txt));
TextOut(hdc,2,30,tip,lstrlen(tip));
Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
EndPaint(hwnd,&ps);
return 0;
case WM_MOUSEWHEEL:
{
iRotate += (short)HIWORD(wParam);
wsprintf(tip,_T("滚轮滚动:%d"),iRotate);
if (iRotate>0)
{
//放大
InflateRect(&rect,10,10);
iRotate-=120;
}
else if (iRotate<0)
{
//缩小
InflateRect(&rect,-10,-10);
iRotate+=120;
}
InvalidateRect(hwnd,NULL,TRUE);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
break;//跳出到默认处理
}
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_ARROW);
wndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = WinProc;
wndClass.lpszClassName = ClassName;
wndClass.lpszMenuName=NULL;
wndClass.style=CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
if(!RegisterClass(&wndClass))return 0;
HWND hwnd = CreateWindow(ClassName,title1,WS_OVERLAPPEDWINDOW,0,0,350,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
相关资讯