首页 / WINDOWS / windows截图代码
windows截图代码
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了windows截图代码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含6163字,纯文字阅读大概需要9分钟。
内容图文
注意点: 1.在大屏的笔记本:要去显示设置里面把缩放调到100% 2.获取屏幕坐标的注意点https://blog.csdn.net/zhangweishuang/article/details/5966105?utm_source=jiancool // ICONDEMO.cpp : 定义应用程序的入口点。// #include "stdafx.h"
#include "ICONDEMO.h" // 此代码模块中包含的函数的前向声明:
LRESULT CALLBACK??? WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
?_In_opt_ HINSTANCE hPrevInstance,
?_In_ LPWSTR??? lpCmdLine,
?_In_ int?????? nCmdShow)
{
?static TCHAR szAppName[] = TEXT("Blowup");
?HACCEL hAccel;
?HWND hwnd;
?MSG msg;
?WNDCLASS wndclass; ?wndclass.style = CS_HREDRAW | CS_VREDRAW;
?wndclass.lpfnWndProc = WndProc;
?wndclass.cbClsExtra = 0;
?wndclass.cbWndExtra = 0;
?wndclass.hInstance = hInstance;
?wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
?wndclass.hCursor = LoadCursor(nullptr, IDC_ARROW);
?wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
?wndclass.lpszMenuName = szAppName;
?wndclass.lpszClassName = szAppName; ?if (!RegisterClass(&wndclass))
?{
??MessageBox(NULL, TEXT("This program requires Windows NT!"), szAppName, MB_ICONERROR);
??return 0;
?} ?hwnd = CreateWindow(szAppName, TEXT("Blow-Up Mouse Demo"), WS_OVERLAPPEDWINDOW,
??CW_USEDEFAULT, CW_USEDEFAULT,
??CW_USEDEFAULT, CW_USEDEFAULT,
??NULL, NULL, hInstance, NULL); ?ShowWindow(hwnd, nCmdShow);
?UpdateWindow(hwnd); ?hAccel = LoadAccelerators(hInstance, szAppName); ??? // 主消息循环:
??? while (GetMessage(&msg, nullptr, 0, 0))
??? {
??if (!TranslateAccelerator(hwnd, hAccel, &msg))
??{
???TranslateMessage(&msg);
???DispatchMessage(&msg);
??}
??
??? }
?return? msg.wParam;
?
} void InvertBlock(HWND hwndScr, HWND hwnd, POINT ptBeg, POINT ptEnd)
{
?HDC hdc;
?hdc = GetDCEx(hwndScr, NULL, DCX_CACHE | DCX_LOCKWINDOWUPDATE);
?ClientToScreen(hwnd, &ptBeg);
?ClientToScreen(hwnd, &ptEnd); ?PatBlt(hdc, ptBeg.x, ptBeg.y, ptEnd.x - ptBeg.x, ptEnd.y - ptBeg.y, DSTINVERT);
?ReleaseDC(hwndScr, hdc);
} HBITMAP CopyBitmap(HBITMAP hBitmapSrc)
{
?BITMAP bitmap;
?HBITMAP hBitmapDst;
?HDC hdcSrc, hdcDst;
?
?GetObject(hBitmapSrc, sizeof(BITMAP), &bitmap);
?hBitmapDst = CreateBitmapIndirect(&bitmap); ?hdcSrc = CreateCompatibleDC(NULL);
?hdcDst = CreateCompatibleDC(NULL); ?SelectObject(hdcSrc, hBitmapSrc);
?SelectObject(hdcDst, hBitmapDst); ?BitBlt(hdcDst, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcSrc, 0, 0, SRCCOPY); ?DeleteDC(hdcSrc);
?DeleteDC(hdcDst); ?return hBitmapDst;
} //
//? 函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//? 目的:??? 处理主窗口的消息。
//
//? WM_COMMAND? - 处理应用程序菜单
//? WM_PAINT??? - 绘制主窗口
//? WM_DESTROY? - 发送退出消息并返回
//
//
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
?static BOOL bCapturing, bBlocking;
?static HBITMAP hBitmap;
?static HWND hwndScr;
?static POINT ptBeg, ptEnd;
?BITMAP bm;
?HBITMAP hBitmapClip;
?HDC hdc, hdcMem;
?int iEnable;
?PAINTSTRUCT ps;
?RECT rect;
?POINT point; ?switch (message)
?{
?case WM_LBUTTONDOWN:
??if (!bCapturing)
??{
???if (LockWindowUpdate(hwndScr = GetDesktopWindow()))
???{
????bCapturing = TRUE;
????SetCapture(hwnd);
????SetCursor(LoadCursor(NULL, IDC_CROSS));
???}
???else
???{
????MessageBeep(0);
???}
??}
??return 0;
?case WM_RBUTTONDOWN:
??if (bCapturing)
??{
???bBlocking = TRUE;
??/*?ptBeg.x = LOWORD(lParam);
???ptBeg.y = HIWORD(lParam);*/
???ptBeg.x = MAKEPOINTS(lParam).x;
???ptBeg.y = MAKEPOINTS(lParam).y;
???ptEnd = ptBeg;
???InvertBlock(hwndScr, hwnd, ptBeg, ptEnd);
??}
??return 0;
?case WM_MOUSEMOVE:
??if (bBlocking)
??{
???InvertBlock(hwndScr, hwnd, ptBeg, ptEnd);
???ptEnd.x = MAKEPOINTS(lParam).x;
???ptEnd.y = MAKEPOINTS(lParam).y;
???InvertBlock(hwndScr, hwnd, ptBeg, ptEnd);
??}
??return 0;
?case WM_LBUTTONUP:
?case WM_RBUTTONUP:
??if (bBlocking)
??{
???InvertBlock(hwndScr, hwnd, ptBeg, ptEnd);
???ptEnd.x = MAKEPOINTS(lParam).x;
???ptEnd.y = MAKEPOINTS(lParam).y;
???if (hBitmap)
???{
????DeleteObject(hBitmap);
????hBitmap = NULL;
???}
???//hdc = GetDC(hwndScr);
???hdc = GetDCEx(hwndScr, NULL, DCX_CACHE | DCX_LOCKWINDOWUPDATE);
???hdcMem = CreateCompatibleDC(hdc);
???hBitmap = CreateCompatibleBitmap(hdc, abs(ptEnd.x - ptBeg.x), abs(ptEnd.y - ptBeg.y));
???SelectObject(hdcMem, hBitmap);
???point = ptBeg;
???ClientToScreen(hwnd,&point);
???StretchBlt(hdcMem, 0, 0, abs(ptEnd.x - ptBeg.x), abs(ptEnd.y - ptBeg.y), hdc, point.x, point.y, ptEnd.x - ptBeg.x, ptEnd.y - ptBeg.y, SRCCOPY);
???DeleteDC(hdcMem);
???ReleaseDC(hwnd, hdc);
???InvalidateRect(hwnd, NULL, TRUE);
??}
??if (bBlocking || bCapturing)
??{
???bBlocking = bCapturing = FALSE;
???SetCursor(LoadCursor(NULL, IDC_ARROW));
???ReleaseCapture();
???LockWindowUpdate(NULL);
??}
??return 0;
?case WM_INITMENUPOPUP:
??iEnable = IsClipboardFormatAvailable(CF_BITMAP) ? MF_ENABLED : MF_GRAYED;
??EnableMenuItem((HMENU)wParam, IDM_EDIT_PASTE, iEnable); ??iEnable = hBitmap ? MF_ENABLED : MF_GRAYED;
??EnableMenuItem((HMENU)wParam, IDM_EDIT_CUT, iEnable);
??EnableMenuItem((HMENU)wParam, IDM_EDIT_COPY, iEnable);
??EnableMenuItem((HMENU)wParam, IDM_EDIT_DELETE, iEnable);
??return 0;
?case WM_COMMAND:
??switch (LOWORD(wParam))
??{
??case IDM_EDIT_CUT:
??case IDM_EDIT_COPY:
???if (hBitmap)
???{
????hBitmapClip = CopyBitmap(hBitmap);
????OpenClipboard(hwnd);
????EmptyClipboard();
????SetClipboardData(CF_BITMAP, hBitmapClip);
???}
???if (LOWORD(wParam) == IDM_EDIT_COPY)
???{
????return 0;
???} ??case IDM_EDIT_DELETE:
???if (hBitmap)
???{
????DeleteObject(hBitmap);
????hBitmap = NULL;
???}
???InvalidateRect(hwnd, NULL, TRUE);
???return 0;
??case IDM_EDIT_PASTE:
???if (hBitmap)
???{
????DeleteObject(hBitmap);
????hBitmap = NULL;
???}
???OpenClipboard(hwnd);
???hBitmapClip = (HBITMAP)GetClipboardData(CF_BITMAP);
???if (hBitmapClip)
???{
????hBitmap = CopyBitmap(hBitmapClip);
???}
???CloseClipboard();
???InvalidateRect(hwnd, NULL, TRUE);
???return 0;
??}
??break;
?case WM_PAINT:
??hdc = BeginPaint(hwnd, &ps);
??if (hBitmap)
??{
???GetClientRect(hwnd, &rect);
???hdcMem = CreateCompatibleDC(hdc);
???SelectObject(hdcMem, hBitmap);
???GetObject(hBitmap, sizeof(BITMAP), (PSTR)&bm);
???SetStretchBltMode(hdc, COLORONCOLOR);
???StretchBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
???DeleteDC(hdcMem);
??}
??EndPaint(hwnd, &ps);
??return 0;
?case WM_DESTROY:
??if (hBitmap)
??{
???DeleteObject(hBitmap);
??}
??PostQuitMessage(0);
??return 0;
??
?}
?return DefWindowProc(hwnd, message, wParam, lParam);
}
内容总结
以上是互联网集市为您收集整理的windows截图代码全部内容,希望文章能够帮你解决windows截图代码所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。