欢迎访问Ningto's博客

Menu
  • 首页
  • 归档
  • 关于
  • 书签
  • 必应壁纸
  • IT聚合
  • 工具
    • 我的工具列表
    • 我的网盘
    • 必应每日壁纸API
    • Html转Markdown
    • 仙尘光标
Menu

windows 获取剪切板中的图片大小

最后更新 2017-01-01 15:40:25   阅读量 1713
#pragma once

class cliboard_data
{
public:
    static bool getImageSize(int &width, int &height);
    static unsigned int getLastError();
};

#include "cliboard_data.h"
#include <stdint.h>
#include <Windows.h>

typedef struct
{
    uint32_t biSize;
    int32_t  biWidth;
    int32_t  biHeight;
    uint16_t biPlanes;
    uint16_t biBitCount;
    uint32_t biCompression;
    uint32_t biSizeImage;
    int32_t  biXPelsPerMeter;
    int32_t  biYPelsPerMeter;
    uint32_t biClrUsed;
    uint32_t biClrImportant;
} DIB;

bool cliboard_data::getImageSize(int &width, int &height)
{
    if (!(IsClipboardFormatAvailable(CF_BITMAP) || IsClipboardFormatAvailable(CF_DIB) || IsClipboardFormatAvailable(CF_DIBV5))) {
        return false;
    }

    bool result = false;
    if (OpenClipboard(NULL)) {
        HANDLE hClipboard = GetClipboardData(CF_DIB);
        if (!hClipboard) {
            hClipboard = GetClipboardData(CF_DIBV5);
        }

        if (hClipboard != NULL && hClipboard != INVALID_HANDLE_VALUE) {
            void* dib = GlobalLock(hClipboard);
            if (dib) {
                DIB *info = reinterpret_cast<DIB*>(dib);
                width = info->biWidth;
                height = info->biHeight;
                result = true;
                GlobalUnlock(dib);
            }
        }
        CloseClipboard();
    }

    return result;
}

unsigned int cliboard_data::getLastError()
{
    return GetLastError();
}
(转载本站文章请注明作者和出处:泞途 - ningto.com)

下一篇 – Qt自定义MessageBox
上一篇 – linux git ssh配置

  1. Windows
  2. C/C++

toningto@outlook.com

推荐文章

QProcess 7z.exe 解压进度

IE获取元素样式

标签云

IOS Life Qt Node.js Design Android Tools Product Bug Shell Mobile Go Web Javascript Mac Windows Linux React MQ Others Boost C/C++ MongoDB Tips Python Java Database

推广链接

【腾讯云】云产品限时秒杀,爆款1核2G云服务器,首年99元

多谢支持,用了好几年,服务很稳定支持多设备!

其他

文章RSS

Copyright © 2016 Welcome To Ningto Blog | 鄂ICP备17003086号-2