C++实现新年贺卡程序

这篇文章主要为大家详细介绍了C++实现贺卡程序,C++应用程序编写的雪花贺卡,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

用c++应用程序编写的雪花贺卡,逢年过节送给你自己身边的亲友吧

snow.cpp

 /////////////////////////////////////////////////////////////////////////////// // Snow.cpp // Date: 2009-2-5 21:16 // A moving ball. // /////////////////////////////////////////////////////////////////////////////// #include  #include "Snow.h" TCHAR strForWin1[] = "时间过得好快啊!"; TCHAR strForWin2[] = "开学已经十周了..." ; TCHAR strForWin3[] = "你学的怎么样了?"; TCHAR strForWin4[] = "有问题一定要及时让我知道"; TCHAR strForWin5[] = "祝大家“小光棍节”快乐"; TCHAR strForWin6[] = "  CJ Wang 2011.11.1"; const int nMaxHeight = 450; #define ID_TIMER 1 /////////////////////////////////////////////////////////////////////////////// int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, char* cmdParam, int cmdShow ) { char className[] = "Snow"; MovingBall MovingBallClass( WindowsProcedure, className, hInst ); MovingBallClass.Register(); WinMaker win( "-- Have a joy here!", className, hInst ); win.Show( cmdShow ); MSG msg; int status; while( ( status = ::GetMessage( & msg, NULL, 0, 0 ) ) != 0 ) { if ( status == -1 ) return -1; ::TranslateMessage( & msg ); ::DispatchMessage( & msg ); } return msg.wParam; } /////////////////////////////////////////////////////////////////////////////// MovingBall::MovingBall( WNDPROC wndProc, const char* className, HINSTANCE hInstance ) { _class.style = 0; _class.lpfnWndProc = wndProc; // Windows procedure: mandatory _class.cbClsExtra = 0; _class.cbWndExtra = 0; _class.hInstance = hInstance; _class.hIcon = 0; // Owner of class: mandatory _class.hCursor = ::LoadCursor( 0, IDC_ARROW ); _class.hbrBackground = (HBRUSH) ( COLOR_WINDOW + 1 ); // Optional _class.lpszMenuName = 0; _class.lpszClassName = className; // Mandatory } WinMaker::WinMaker( const char* szCaption, const char* className, HINSTANCE hInstance ) { DWORD dwStyle = WS_OVERLAPPEDWINDOW; dwStyle &= ~WS_SIZEBOX; dwStyle &= ~WS_MAXIMIZEBOX; dwStyle &= ~WS_MINIMIZEBOX; _hWnd = ::CreateWindow( className, // Name of a registered window class szCaption, // Window caption dwStyle, // Window style CW_USEDEFAULT, // x position CW_USEDEFAULT, // y position 787, // width 590, // height 0, // Handle to parent window 0, // Handle to menu hInstance, // Application instance 0 ); // Window creation data } /*:: -- 作用域标识符!如果是在MFC下编程的话,因为MFC封装了API函数,但是参数有的和API函数不一样, 比如MFC封装的函数一般都没有句柄这个参数,但是API函数都有, 所以在MFC编程中,如果你调用的是全局的API函数的话就要加::符号, 来通知编译器你调用的是全局的API函数,而不是MFC封装的API函数! 当然有的函数比如参数是个布尔型的,MFC封装的函数和全局的API函数的参数相同, 编译器默认的是调用MFC封装的函数,所以你加不加::作用域标识符都是一样的!! 控制台下编写的程序用的就是API函数所以没必要加::作用域标识符的。 */ /////////////////////////////////////////////////////////////////////////////// LRESULT CALLBACK WindowsProcedure( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam ) { static HBITMAP hbmpBkground = NULL, hbmpSnow = NULL, hbmpMask = NULL; static Snow snowFlakes[ 80 ]; static int countSnow = 0; static int cxClient, cyClient; static int nHeightY = nMaxHeight; COLORREF clrBk; PAINTSTRUCT ps; HDC hdc = NULL, hdcMem = NULL; HINSTANCE hInst = NULL; switch( uMessage ) { case WM_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 ); return 0; case WM_SIZE: cxClient = LOWORD( lParam ); cyClient = HIWORD( lParam ); return 0; case WM_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 ); return 0; case WM_TIMER: ::FlashWindow( hWnd, TRUE ); if ( countSnow <80 ) { snowflakes[ countsnow ].xpos=rand() % cxclient; ].ypos=0; ].bisexist=TRUE; countsnow++; } if ( 80 0; hdc hwnd ); assert( hdcmem ::selectobject( hdcmem, hbmpbkground ::bitblt( hdc, 0, cxclient, cyclient, srccopy clrbk ::settextcolor( rgb( 11, 255 ::setbkcolor( ::textout( 100, nheighty, strforwin1, lstrlen( strforwin1 nheighty + 18, strforwin2, strforwin2 36, strforwin3, strforwin3 54, strforwin4, strforwin4 70, strforwin5, strforwin5 88, strforwin6, strforwin6> cyClient ) { snowFlakes[ i ].xPos = rand() % cxClient; snowFlakes[ i ].yPos = 0; } } } ::ReleaseDC( hWnd, hdc ); ::DeleteDC( hdcMem ); return 0; case WM_DESTROY: ::DeleteObject( hbmpBkground ); ::DeleteObject( hbmpSnow ); ::DeleteObject( hbmpMask ); ::KillTimer( hWnd, ID_TIMER ); ::PostQuitMessage( 0 ); return 0; } return ::DefWindowProc( hWnd, uMessage, wParam, lParam ); }

源码下载:贺卡程序

以上就是C++实现新年贺卡程序的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » C语言