Windows界面编程第十三篇 位图显示特效合集
本文配套程序下载地址为:http://download.csdn.net/detail/morewindows/5177047
转载请标明出处,原文地址:http://blog.csdn.net/morewindows/article/details/8696730
欢迎关注微博:http://weibo.com/MoreWindows
Windows界面编程之位图显示特效系列目录:
1. 《Windows界面编程第九篇位图显示特效交错效果》
http://blog.csdn.net/morewindows/article/details/8696720
2. 《Windows界面编程第十篇位图显示特效百叶窗效果》
http://blog.csdn.net/morewindows/article/details/8696722
3. 《Windows界面编程第十一篇位图显示特效随机积木效果》
http://blog.csdn.net/morewindows/article/details/8696724
4. 《Windows界面编程第十二篇位图显示特效飞入效果与伸展效果》
http://blog.csdn.net/morewindows/article/details/8696726
5. 《Windows界面编程第十三篇位图显示特效合集》
http://blog.csdn.net/morewindows/article/details/8696730
前面的四篇已经介绍了位图的交错效果、百叶窗效果、随机积木效果、飞入效果与伸展效果。下面用一个程序将展示这些效果。这里给出主要代码(下载地址见:http://download.csdn.net/detail/morewindows/5177047)。代码中的DragAcceptFiles可以参考《Windows界面编程第七篇文件拖拽(文件拖放)》(http://blog.csdn.net/morewindows/article/details/8634451),主要是为了能将位图文件拖入到窗口中。
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int s_nShow; static HDC s_hdcMem; static int s_nWidth, s_nHeight; switch (message) { case WM_CREATE: { DragAcceptFiles(hwnd, TRUE); // 加载位图 HBITMAP hBitmap; hBitmap = (HBITMAP)LoadImage(NULL, "107.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); if (hBitmap == NULL) { MessageBox(hwnd, "LoadImage failed", "Error", MB_ICONERROR); exit(0); } // 位图HDC HDC hdc = GetDC(hwnd); s_hdcMem = CreateCompatibleDC(hdc); SelectObject(s_hdcMem, hBitmap); ReleaseDC(hwnd, hdc); // 计算位图宽高 BITMAP bm; GetObject(hBitmap, sizeof(bm), &bm); s_nWidth = bm.bmWidth; s_nHeight = bm.bmHeight; s_nShow = 0; } return 0; case WM_KEYDOWN: switch (wParam) { case VK_ESCAPE: //按下Esc键时退出 SendMessage(hwnd, WM_DESTROY, 0, 0); return 0; } break; case WM_PAINT: { HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hwnd, &ps); switch (s_nShow) { case 0: BitBlt(hdc, 0, 0, s_nWidth, s_nHeight, s_hdcMem, 0, 0, SRCCOPY); break; // 水平交错 case 1: AnimateDraw_StaggeredHorizontal(hdc, s_hdcMem, s_nWidth, s_nHeight); break; // 垂直交错 case 2: AnimateDraw_StaggeredVertical(hdc, s_hdcMem, s_nWidth, s_nHeight); break; // 水平百叶窗 case 3: AnimateDraw_JalousieHorizontal(hdc, s_hdcMem, s_nWidth, s_nHeight); break; // 垂直百叶窗 case 4: AnimateDraw_JalousieVertical(hdc, s_hdcMem, s_nWidth, s_nHeight); break; // 随机积木 case 5: AnimateDraw_RandomBlocks(hdc, s_hdcMem, s_nWidth, s_nHeight); break; // 飞入 从上往下 case 6: AnimateDraw_FlyingTopToBottom(hdc, s_hdcMem, s_nWidth, s_nHeight, 2, FALSE); break; // 飞入 从下往上 case 7: AnimateDraw_FlyingBottomToTop(hdc, s_hdcMem, s_nWidth, s_nHeight, 2, FALSE); break; // 飞入 从左往右 case 8: AnimateDraw_FlyingLeftToRight(hdc, s_hdcMem, s_nWidth, s_nHeight, 2, FALSE); break; // 飞入 从右往左 case 9: AnimateDraw_FlyingRightToLeft(hdc, s_hdcMem, s_nWidth, s_nHeight, 2, FALSE); break; // 伸展 从上往下 case 10: AnimateDraw_FlyingTopToBottom(hdc, s_hdcMem, s_nWidth, s_nHeight); break; // 伸展 从下往上 case 11: AnimateDraw_FlyingBottomToTop(hdc, s_hdcMem, s_nWidth, s_nHeight); break; // 伸展 从左往右 case 12: AnimateDraw_FlyingLeftToRight(hdc, s_hdcMem, s_nWidth, s_nHeight); break; // 伸展 从右往左 case 13: AnimateDraw_FlyingRightToLeft(hdc, s_hdcMem, s_nWidth, s_nHeight); break; } if (s_nShow != 0) { s_nShow = 0; InvalidateRect(hwnd, NULL, FALSE); } EndPaint(hwnd, &ps); } return 0; case WM_COMMAND: if (LOWORD(wParam) >= 40001 && LOWORD(wParam) <= 40013) { s_nShow = LOWORD(wParam) - 40000; InvalidateRect(hwnd, NULL, TRUE); return 0; } break; // 文件拖拽第三步 DragQueryFile and DragQueryFile case WM_DROPFILES: { HDROP hDrop = (HDROP)wParam; UINT nFileNum = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); // 拖拽文件个数 char strFileName[MAX_PATH]; DragQueryFile(hDrop, 0, strFileName, MAX_PATH);//获得拖曳的文件名 DragFinish(hDrop); //释放hDrop DeleteDC(s_hdcMem); // 加载位图 HBITMAP hBitmap; hBitmap = (HBITMAP)LoadImage(NULL, strFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); // 位图HDC HDC hdc = GetDC(hwnd); s_hdcMem = CreateCompatibleDC(hdc); SelectObject(s_hdcMem, hBitmap); ReleaseDC(hwnd, hdc); // 计算位图宽高 BITMAP bm; GetObject(hBitmap, sizeof(bm), &bm); s_nWidth = bm.bmWidth; s_nHeight = bm.bmHeight; InvalidateRect(hwnd, NULL, TRUE); } return 0; case WM_DESTROY: DeleteDC(s_hdcMem); PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }
下面是程序所展示的一种显示效果(图片不能打开,请访问http://blog.csdn.net/morewindows/article/details/8696730)。
更多显示效果可以参考前面的交错效果、百叶窗效果、随机积木效果、飞入效果与伸展效果博客中的示例。
本文配套程序下载地址为:http://download.csdn.net/detail/morewindows/5177047
转载请标明出处,原文地址:http://blog.csdn.net/morewindows/article/details/8696730
欢迎关注微博:http://weibo.com/MoreWindows