鱼C论坛

 找回密码
 立即注册
查看: 2701|回复: 1

[技术交流] win32 放大镜 附源码!

[复制链接]
发表于 2016-12-22 19:11:58 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
先上代码

  1. #include <Windows.h>

  2. HWND hParent, hBitMap, hDeskTop;
  3. HDC hMemDC;
  4. HBITMAP hBit;
  5. HMODULE hModule;


  6. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


  7. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  8. {
  9.         WNDCLASS wc;

  10.         static TCHAR* szAppName = TEXT("大灰机");

  11.         HWND hwnd = NULL;

  12.         MSG msg;


  13.         wc.style = CS_HREDRAW | CS_VREDRAW;

  14.         wc.lpfnWndProc = WndProc;

  15.         wc.cbClsExtra = 0;

  16.         wc.cbWndExtra = 0;

  17.         wc.hInstance = hInstance;

  18.         wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);

  19.         wc.hCursor = LoadCursor(NULL, IDC_ARROW);

  20.         wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);

  21.         wc.lpszMenuName = NULL;

  22.         wc.lpszClassName = szAppName;


  23.         if (!RegisterClass(&wc))
  24.         {
  25.                 MessageBox(NULL, TEXT("程序只能在WindowsNT下运行"),
  26.                         szAppName, MB_ICONERROR);

  27.                 return 0;

  28.         }


  29.         hwnd = CreateWindow(szAppName,

  30.                 TEXT("大灰机"),

  31.                 WS_OVERLAPPEDWINDOW,

  32.                 CW_USEDEFAULT,

  33.                 CW_USEDEFAULT,

  34.                 200,

  35.                 230,

  36.                 NULL,

  37.                 NULL,

  38.                 hInstance,

  39.                 NULL);


  40.         ShowWindow(hwnd, iCmdShow);

  41.         UpdateWindow(hwnd);


  42.         while (GetMessage(&msg, NULL, 0, 0))
  43.         {
  44.                 TranslateMessage(&msg);

  45.                 DispatchMessage(&msg);

  46.         }

  47.         return msg.wParam;

  48. }


  49. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  50. {
  51.         PAINTSTRUCT ps;

  52.         RECT rect;

  53.         POINT point;

  54.         HDC hDC, hDeskTopDC, hBitDC;


  55.         switch (message)
  56.         {
  57.         case WM_CREATE:

  58.                 hBitMap = CreateWindowEx(0, TEXT("STATIC"),
  59.                         NULL,

  60.                         SS_CENTER | WS_CHILD | WS_VISIBLE,

  61.                         19, 39, 127, 120,

  62.                         hwnd,

  63.                         NULL,

  64.                         hModule,

  65.                         NULL);


  66.                 hDeskTop = GetDesktopWindow();


  67.                 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);


  68.                 hDeskTopDC = GetDC(hDeskTop);


  69.                 hMemDC = CreateCompatibleDC(hDeskTopDC);

  70.                 hBit = CreateCompatibleBitmap(hDeskTopDC, 120, 120);

  71.                 SelectObject(hMemDC, hBit);


  72.                 ReleaseDC(hDeskTop, hDeskTopDC);

  73.                 SetTimer(hwnd, 1, 80, NULL);

  74.                 return 0;


  75.         case WM_CLOSE:

  76.                 DeleteDC(hMemDC);

  77.                 DeleteObject(hBit);

  78.                 DestroyWindow(hwnd);

  79.                 PostQuitMessage(0);

  80.                 return 0;


  81.         case WM_TIMER:

  82.                 GetCursorPos(&point);

  83.                 hDeskTopDC = GetDC(hDeskTop);


  84.                 hBitDC = GetDC(hBitMap);

  85.                 PatBlt(hMemDC, 0, 0, 120, 120, BLACKNESS);

  86.                 StretchBlt(hMemDC, 0, 0, 120, 120, hDeskTopDC, point.x, point.y, 80, 80, SRCCOPY);

  87.                 BitBlt(hBitDC, 0, 0, 120, 120, hMemDC, 0, 0, SRCCOPY);


  88.                 ReleaseDC(hDeskTop, hDeskTopDC);

  89.                 ReleaseDC(hBitMap, hBitDC);

  90.                 return 0;


  91.         case WM_PAINT:

  92.                 hDC = BeginPaint(hwnd, &ps);


  93.                 GetClientRect(hwnd, &rect);

  94.                 DrawText(hDC, TEXT("放大镜"), -1, &rect, DT_CENTER);


  95.                 EndPaint(hwnd, &ps);

  96.                 return 0;

  97.         }

  98.         return DefWindowProc(hwnd, message, wParam, lParam);
  99. }
复制代码


运行效果

QQ图片20161222190840.png

评分

参与人数 1荣誉 +8 鱼币 +8 贡献 +5 收起 理由
拈花小仙 + 8 + 8 + 5 感谢楼主无私奉献!

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-12-26 23:16:05 | 显示全部楼层
谢谢分享
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 01:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表