博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
《windows程序设计》学习_3.3:利用xp扫雷资源
阅读量:6488 次
发布时间:2019-06-24

本文共 3759 字,大约阅读时间需要 12 分钟。

1 #include
2 #include "resource.h" 3 4 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); 5 6 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstace, PSTR szCmdLine, int iCmdShow) 7 { 8 static TCHAR szAppName[] = TEXT ("stick1"); 9 HWND hwnd; 10 MSG msg; 11 WNDCLASS wndclass; 12 13 wndclass.style = CS_HREDRAW | CS_VREDRAW ; 14 wndclass.lpfnWndProc = WndProc; 15 wndclass.cbClsExtra = 0; 16 wndclass.cbWndExtra = 0; 17 wndclass.hInstance = hInstance; 18 wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON1)); 19 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); 20 wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 21 wndclass.lpszMenuName = NULL; 22 wndclass.lpszClassName = szAppName; 23 24 if(!RegisterClass(&wndclass)) 25 { 26 MessageBox(NULL, TEXT ("The Program requires Windows NT!"), szAppName, MB_ICONERROR); 27 return 0; 28 } 29 30 hwnd = CreateWindow (szAppName, 31 TEXT ("ɨÀ×"), 32 WS_OVERLAPPEDWINDOW, 33 CW_USEDEFAULT, 34 CW_USEDEFAULT, 35 CW_USEDEFAULT, 36 CW_USEDEFAULT, 37 NULL, 38 NULL, 39 hInstance, 40 NULL); 41 42 ShowWindow(hwnd , iCmdShow); 43 UpdateWindow(hwnd); 44 45 while(GetMessage(&msg, NULL, 0, 0)) 46 { 47 TranslateMessage(&msg); 48 DispatchMessage(&msg); 49 } 50 return msg.wParam; 51 } 52 53 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 54 { 55 static HBITMAP hBitmap; 56 static int cxClient, cyClient, cxSource, cySource; 57 BITMAP bitmap; 58 HDC hdc,hdcMem; 59 HINSTANCE hInstance; 60 int x,y,mx,my; 61 PAINTSTRUCT ps; 62 63 64 switch(message) 65 { 66 case WM_CREATE: 67 hInstance = ((LPCREATESTRUCT) lParam) ->hInstance; 68 69 hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(IDM_BITMAP)/*TEXT("bitmap1")*/); 70 GetObject(hBitmap,sizeof(BITMAP),&bitmap); 71 72 cxSource = bitmap.bmWidth; 73 cySource = bitmap.bmHeight/16; 74 75 return 0; 76 case WM_SIZE: 77 cxClient = LOWORD (lParam); 78 cyClient = HIWORD (lParam); 79 return 0; 80 case WM_PAINT: 81 hdc = BeginPaint(hwnd , &ps); 82 83 hdcMem = CreateCompatibleDC(hdc); 84 SelectObject(hdcMem,hBitmap); 85 86 for(y = 100; y < cyClient - 100 ; y += cySource) 87 { 88 for(x = 100; x < cxClient - 100; x += cxSource) 89 { 90 BitBlt(hdc,x,y,cxSource,cySource,hdcMem,0,0,SRCCOPY); 91 } 92 } 93 DeleteDC(hdcMem); 94 EndPaint(hwnd, &ps); 95 return 0; 96 case WM_LBUTTONDOWN: 97 hdc = GetDC(hwnd); 98 99 mx = LOWORD(lParam);100 my = HIWORD(lParam);101 102 hdcMem = CreateCompatibleDC(hdc);103 SelectObject(hdcMem, hBitmap);104 105 BitBlt(hdc, mx, my, cxSource, cySource, hdcMem, 0, cySource, SRCCOPY);106 107 DeleteDC(hdcMem);108 ReleaseDC(hwnd, hdc);109 return 0;110 case WM_DESTROY:111 DeleteObject(hBitmap);112 PostQuitMessage(0);113 return 0;114 }115 return DefWindowProc(hwnd, message, wParam, lParam);116 }

转载于:https://www.cnblogs.com/Hewie/p/3422041.html

你可能感兴趣的文章
使用js在网页上记录鼠标划圈的小程序
查看>>
[macOS] keychain的跳坑之旅!git拉取的权限问题
查看>>
bootstrap的两种在input框里面增加一个图标的方式
查看>>
算法笔记_080:蓝桥杯练习 队列操作(Java)
查看>>
Solidworks 如何绘制投影曲线
查看>>
Linux 文件夹含义(转)
查看>>
c++构造函数具体解释
查看>>
利用ROS工具从bag文件中提取图片
查看>>
JDBC2.0操作:结果集,更新,插入,删除,批处理语句
查看>>
HDU 1710 Binary Tree Traversals(二叉树)
查看>>
C#知识点总结系列
查看>>
POJ 3463 Sightseeing
查看>>
[转]真正了解CSS3背景下的@font face规则
查看>>
loadrunner下的putty和plink
查看>>
鼠标右键添加"在此处打开命令窗口"
查看>>
exadata(硬件更换文档部分)
查看>>
Asp.Net Core WebAPI入门整理(一)
查看>>
CSS Text
查看>>
Android 防内存泄露handler
查看>>
Redis整合Spring结合使用缓存实例
查看>>