<bdo id='EdC8k'></bdo><ul id='EdC8k'></ul>

      <i id='EdC8k'><tr id='EdC8k'><dt id='EdC8k'><q id='EdC8k'><span id='EdC8k'><b id='EdC8k'><form id='EdC8k'><ins id='EdC8k'></ins><ul id='EdC8k'></ul><sub id='EdC8k'></sub></form><legend id='EdC8k'></legend><bdo id='EdC8k'><pre id='EdC8k'><center id='EdC8k'></center></pre></bdo></b><th id='EdC8k'></th></span></q></dt></tr></i><div id='EdC8k'><tfoot id='EdC8k'></tfoot><dl id='EdC8k'><fieldset id='EdC8k'></fieldset></dl></div>
    1. <small id='EdC8k'></small><noframes id='EdC8k'>

    2. <tfoot id='EdC8k'></tfoot><legend id='EdC8k'><style id='EdC8k'><dir id='EdC8k'><q id='EdC8k'></q></dir></style></legend>

      如何在 VC++ 中将 HICON 转换为 HBITMAP?

      How to convert HICON to HBITMAP in VC++?(如何在 VC++ 中将 HICON 转换为 HBITMAP?)

        <legend id='dsIgu'><style id='dsIgu'><dir id='dsIgu'><q id='dsIgu'></q></dir></style></legend>
          <tbody id='dsIgu'></tbody>
        • <i id='dsIgu'><tr id='dsIgu'><dt id='dsIgu'><q id='dsIgu'><span id='dsIgu'><b id='dsIgu'><form id='dsIgu'><ins id='dsIgu'></ins><ul id='dsIgu'></ul><sub id='dsIgu'></sub></form><legend id='dsIgu'></legend><bdo id='dsIgu'><pre id='dsIgu'><center id='dsIgu'></center></pre></bdo></b><th id='dsIgu'></th></span></q></dt></tr></i><div id='dsIgu'><tfoot id='dsIgu'></tfoot><dl id='dsIgu'><fieldset id='dsIgu'></fieldset></dl></div>

          <small id='dsIgu'></small><noframes id='dsIgu'>

          • <bdo id='dsIgu'></bdo><ul id='dsIgu'></ul>
                <tfoot id='dsIgu'></tfoot>

                本文介绍了如何在 VC++ 中将 HICON 转换为 HBITMAP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                VC++中如何将HICON转为HBITMAP?

                How to convert HICON to HBITMAP in VC++?

                我知道这是一个常见问题,但我在 Google 上找到的所有解决方案都不起作用.我需要的是一个接受参数 HICON 并返回 HBITMAP 的函数.

                I know this is an FAQ but all the solutions I've found on Google don't work. What I need is a function which takes a parameter HICON and returns HBITMAP.

                即使图标是 24 位、16 位或 8 位,也尽可能转换为 32 位位图.

                Greatest if possible to make conversion to 32-bit bitmap even the icon is 24-bit, 16-bit or 8-bit.

                这是代码,不知道哪里出错了:

                This is the code, I don't know where it goes wrong:

                HBITMAP icon_to_bitmap(HICON Icon_Handle) {
                  HDC Screen_Handle = GetDC(NULL);
                  HDC Device_Handle = CreateCompatibleDC(Screen_Handle);
                
                  HBITMAP Bitmap_Handle = 
                  CreateCompatibleBitmap(Device_Handle,GetSystemMetrics(SM_CXICON),
                  GetSystemMetrics(SM_CYICON));
                
                  HBITMAP Old_Bitmap = (HBITMAP)SelectObject(Device_Handle,Bitmap_Handle);
                  DrawIcon(Device_Handle, 0,0, Icon_Handle);
                  SelectObject(Device_Handle,Old_Bitmap);
                
                  DeleteDC(Device_Handle);
                  ReleaseDC(NULL,Screen_Handle);
                  return Bitmap_Handle;
                }
                

                推荐答案

                我没有现成的代码可以共享,但我认为这很容易.您必须创建 HBITMAP,创建设备上下文,将位图选入 DC(这将使位图成为此 DC 的绘图区域).最后调用 DrawIcon() 函数在此 DC 上绘制您的图标.之后从 DC 分离位图并销毁 DC.您的位图现在应该可以使用了.

                I don't have code readily available to share, but I think this is pretty easy. You have to create the HBITMAP, create a device context, select the bitmap into the DC (this will make the bitmap the drawing area for this DC). Finally call the DrawIcon() function to draw your icon on this DC. After that detach the bitmap from the DC and destroy the DC. Your bitmap now should be ready to go.

                查看代码后更新:

                我相信问题出在 createCompatibleBitmap 调用中.您要求与内存 DC 兼容的位图,但内存 DC 以选择到其中的 1 位/像素位图开始.尝试要求与屏幕 DC 兼容的位图.

                I believe the problem is in the createCompatibleBitmap call. You are asking for a bitmap compatible with the memory DC, but memory DCs start with a 1 bit/pixel bitmap selected into them. Try asking for a bitmap compatible with the screen DC instead.

                更新 2:您可能需要查看这个问题因为它似乎与您的问题有关.

                Update 2: you may want to look at this question as it seems related to your problem.

                这篇关于如何在 VC++ 中将 HICON 转换为 HBITMAP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to print vector#39;s data(如何打印矢量的数据)
                Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                MSVC++ warning flags(MSVC++ 警告标志)
                How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                stack overflow error in C++ program(C++程序中的堆栈溢出错误)

                    <tbody id='WKToT'></tbody>

                  <small id='WKToT'></small><noframes id='WKToT'>

                        <legend id='WKToT'><style id='WKToT'><dir id='WKToT'><q id='WKToT'></q></dir></style></legend>
                          <bdo id='WKToT'></bdo><ul id='WKToT'></ul>
                          <i id='WKToT'><tr id='WKToT'><dt id='WKToT'><q id='WKToT'><span id='WKToT'><b id='WKToT'><form id='WKToT'><ins id='WKToT'></ins><ul id='WKToT'></ul><sub id='WKToT'></sub></form><legend id='WKToT'></legend><bdo id='WKToT'><pre id='WKToT'><center id='WKToT'></center></pre></bdo></b><th id='WKToT'></th></span></q></dt></tr></i><div id='WKToT'><tfoot id='WKToT'></tfoot><dl id='WKToT'><fieldset id='WKToT'></fieldset></dl></div>

                          <tfoot id='WKToT'></tfoot>