C++实现新年贺卡程序
用c++应用程序编写的雪花贺卡,逢年过节送给你自己身边的亲友吧
snow.cpp
/////////////////////////////////////////////////////////////////////////////// //Snow.cpp //Date:2009-2-521:16 //Amovingball. // /////////////////////////////////////////////////////////////////////////////// #include#include"Snow.h" TCHARstrForWin1[]="时间过得好快啊!"; TCHARstrForWin2[]="开学已经十周了..."; TCHARstrForWin3[]="你学的怎么样了?"; TCHARstrForWin4[]="有问题一定要及时让我知道"; TCHARstrForWin5[]="祝大家“小光棍节”快乐"; TCHARstrForWin6[]="CJWang2011.11.1"; constintnMaxHeight=450; #defineID_TIMER1 /////////////////////////////////////////////////////////////////////////////// intWINAPIWinMain(HINSTANCEhInst,HINSTANCEhPrevInst,char*cmdParam,intcmdShow) { charclassName[]="Snow"; MovingBallMovingBallClass(WindowsProcedure,className,hInst); MovingBallClass.Register(); WinMakerwin("--Haveajoyhere!",className,hInst); win.Show(cmdShow); MSGmsg; intstatus; while((status=::GetMessage(&msg,NULL,0,0))!=0) { if(status==-1) return-1; ::TranslateMessage(&msg); ::DispatchMessage(&msg); } returnmsg.wParam; } /////////////////////////////////////////////////////////////////////////////// MovingBall::MovingBall(WNDPROCwndProc,constchar*className,HINSTANCEhInstance) { _class.style=0; _class.lpfnWndProc=wndProc;//Windowsprocedure:mandatory _class.cbClsExtra=0; _class.cbWndExtra=0; _class.hInstance=hInstance; _class.hIcon=0;//Ownerofclass:mandatory _class.hCursor=::LoadCursor(0,IDC_ARROW); _class.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);//Optional _class.lpszMenuName=0; _class.lpszClassName=className;//Mandatory } WinMaker::WinMaker(constchar*szCaption,constchar*className,HINSTANCEhInstance) { DWORDdwStyle=WS_OVERLAPPEDWINDOW; dwStyle&=~WS_SIZEBOX; dwStyle&=~WS_MAXIMIZEBOX; dwStyle&=~WS_MINIMIZEBOX; _hWnd=::CreateWindow( className,//Nameofaregisteredwindowclass szCaption,//Windowcaption dwStyle,//Windowstyle CW_USEDEFAULT,//xposition CW_USEDEFAULT,//yposition 787,//width 590,//height 0,//Handletoparentwindow 0,//Handletomenu hInstance,//Applicationinstance 0);//Windowcreationdata } /*::--作用域标识符!如果是在MFC下编程的话,因为MFC封装了API函数,但是参数有的和API函数不一样, 比如MFC封装的函数一般都没有句柄这个参数,但是API函数都有, 所以在MFC编程中,如果你调用的是全局的API函数的话就要加::符号, 来通知编译器你调用的是全局的API函数,而不是MFC封装的API函数! 当然有的函数比如参数是个布尔型的,MFC封装的函数和全局的API函数的参数相同, 编译器默认的是调用MFC封装的函数,所以你加不加::作用域标识符都是一样的!! 控制台下编写的程序用的就是API函数所以没必要加::作用域标识符的。 */ /////////////////////////////////////////////////////////////////////////////// LRESULTCALLBACKWindowsProcedure(HWNDhWnd,UINTuMessage,WPARAMwParam,LPARAMlParam) { staticHBITMAPhbmpBkground=NULL, hbmpSnow=NULL, hbmpMask=NULL; staticSnowsnowFlakes[80]; staticintcountSnow=0; staticintcxClient,cyClient; staticintnHeightY=nMaxHeight; COLORREFclrBk; PAINTSTRUCTps; HDChdc=NULL, hdcMem=NULL; HINSTANCEhInst=NULL; switch(uMessage) { caseWM_CREATE: hInst=((LPCREATESTRUCT)lParam)->hInstance; assert(hInst); hbmpBkground=::LoadBitmap(hInst,TEXT("bground")); assert(hbmpBkground); hbmpSnow=::LoadBitmap(hInst,TEXT("snow")); assert(hbmpSnow); hbmpMask=::LoadBitmap(hInst,TEXT("mask")); assert(hbmpMask); ::SetWindowPos(hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); //设置定时器 ::SetTimer(hWnd,ID_TIMER,160,NULL); return0; caseWM_SIZE: cxClient=LOWORD(lParam); cyClient=HIWORD(lParam); return0; caseWM_PAINT: hdc=::BeginPaint(hWnd,&ps); assert(hdc); hdcMem=::CreateCompatibleDC(hdc); assert(hdcMem); ::SelectObject(hdcMem,hbmpBkground); ::BitBlt( hdc, 0,0, cxClient,cyClient, hdcMem, 0,0, SRCCOPY); ::DeleteDC(hdcMem); ::EndPaint(hWnd,&ps); return0; caseWM_TIMER: ::FlashWindow(hWnd,TRUE); if(countSnow<80) { snowFlakes[countSnow].xPos=rand()%cxClient; snowFlakes[countSnow].yPos=0; snowFlakes[countSnow].bIsExist=TRUE; countSnow++; } if(countSnow==80) countSnow=0; hdc=::GetDC(hWnd); assert(hdc); hdcMem=::CreateCompatibleDC(hdc); assert(hdcMem); ::SelectObject(hdcMem,hbmpBkground); ::BitBlt( hdc, 0,0, cxClient,cyClient, hdcMem, 0,0, SRCCOPY); clrBk=::GetBkColor(hdc); ::SetTextColor(hdc,RGB(0,11,255)); ::SetBkColor(hdc,clrBk); ::TextOut(hdc,100,nHeightY,strForWin1,lstrlen(strForWin1)); ::TextOut(hdc,100,nHeightY+18,strForWin2,lstrlen(strForWin2)); ::TextOut(hdc,100,nHeightY+36,strForWin3,lstrlen(strForWin3)); ::TextOut(hdc,100,nHeightY+54,strForWin4,lstrlen(strForWin4)); ::TextOut(hdc,100,nHeightY+70,strForWin5,lstrlen(strForWin5)); ::TextOut(hdc,100,nHeightY+88,strForWin6,lstrlen(strForWin6)); // //Theredrawareaforthetext // nHeightY-=10; if(nHeightY<=-88) { nHeightY=nMaxHeight; } inti; for(i=0;i<80;i++) { if(snowFlakes[i].bIsExist) { ::SelectObject(hdcMem,hbmpMask); ::BitBlt( hdc, snowFlakes[i].xPos,snowFlakes[i].yPos, 20,20, hdcMem, 0,0, SRCAND); ::SelectObject(hdcMem,hbmpSnow); ::BitBlt( hdc, snowFlakes[i].xPos,snowFlakes[i].yPos, 20,20, hdcMem, 0,0, SRCPAINT); if(rand()%2==0) snowFlakes[i].xPos+=3; else snowFlakes[i].xPos-=3; snowFlakes[i].yPos+=10; if(snowFlakes[i].yPos>cyClient) { snowFlakes[i].xPos=rand()%cxClient; snowFlakes[i].yPos=0; } } } ::ReleaseDC(hWnd,hdc); ::DeleteDC(hdcMem); return0; caseWM_DESTROY: ::DeleteObject(hbmpBkground); ::DeleteObject(hbmpSnow); ::DeleteObject(hbmpMask); ::KillTimer(hWnd,ID_TIMER); ::PostQuitMessage(0); return0; } return::DefWindowProc(hWnd,uMessage,wParam,lParam); }
源码下载:贺卡程序
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。