Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how to load file.bmp with macro MAKEINTRESOURCE(IDB_BITMAP) with Qt Creator



  • Hi Guys, I need advice, which codes can I use to upload a .bitmap file and upload it to MAKEINTRESOURCE (IDB_BITMAP) for the function:

    HBITMAP bitMap = (HBITMAP)LoadImageA(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BITMAP),IMAGE_BITMAP,16,16,LR_LOADFROMFILE);

    i tried with: #define IDB_BITMAP 1000

    in resource.h

    resource.rc
    IDB_BITMAP BITMAP "file.bmp"

    but it is not possible because Qt creator does not create file resource.rc but resource.qrc which is very different from resource.rc. what codes can I use to automatically load the .bmp file in the macro MAKEINTRESOURCE (IDB_BITMAP)??
    thank you for those who help me



  • I solved the same way:

    #include "afxwin.h"
    #include <qt_windows.h>
    #include <QtWinExtras/qwinfunctions.h>

    QT_BEGIN_NAMESPACE
    Q_GUI_EXPORT HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0);

    QPixmap pixmap(":/resources/images/file.bmp");
    if(!pixmap.isNull())
    {
    pixmap = pixmap.scaled(16,16);
    }
    HBITMAP bitMap = qt_pixmapToWinHBITMAP(pixmap);

    thanks all the same for those who wanted to help me!!


Log in to reply