Thread: c++ 11 - win32 - make my image class

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    451

    c++ 11 - win32 - make my image class

    heres what i did with my class:
    Code:
    class image
    {
    private:
        HDC hdcimage=NULL;
        BITMAP bm;
        HBITMAP hbmOld;
    public:
        image(HDC img=NULL)
        {
            HBITMAP g_hbmBall =  (HBITMAP)LoadImage(NULL, "C:\\FireDragon.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_SHARED);
            HDC hdcMem = CreateCompatibleDC(NULL);
            hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmBall);
            GetObject(g_hbmBall, sizeof(bm), &bm);
        }
        int height()
        {
            return (int)bm.bmHeight;
        }
        int width()
        {
            return (int)bm.bmWidth;
        }
        operator HDC()
        {
            return hdcimage;
        }
    
        ~image()
        {
            SelectObject(hdcimage, hbmOld);
            DeleteDC(hdcimage);
        }
    };
    image m;
    heres how i use it:
    Code:
    TransparentBlt(hdcWindow, 0, 0,m.width(), m.height(),(HDC) m, 0, 0,m.width, m.height, GetPixel(m,0,0));
    for now, i get these error message:
    "cannot convert 'image::width' from type 'int (image:()' to type 'int'"
    i don't understand why the error
    can anyone explain to me what i'm doing wrong?

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Syntax is important; take a longer look at that line of code.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  3. #3
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    If m is the image class, then you aren't calling the width and height functions in the 10th and 11th parameters of TransparentBlt(). Maybe change it to GetHeight() and GetWidth(), so you don't mix up the image::width() with the BITMAP::bmWidth.
    WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;

  4. #4
    Registered User
    Join Date
    Aug 2013
    Posts
    451
    Quote Originally Posted by phantomotap View Post
    O_o

    Syntax is important; take a longer look at that line of code.

    Soma
    sorry... you have right
    thanks for correct me:
    Code:
    TransparentBlt(hdcWindow, 0, 0,m.width(), m.height(),m, 0, 0,m.width(), m.height(), GetPixel(m,0,0));
    but i see 1 problem: the image isn't showed
    can you tell me what i'm doing wrong?

  5. #5
    Registered User
    Join Date
    Aug 2013
    Posts
    451
    finally i fix it:
    Code:
    class image
    {
    private:
        HDC hdcimage=NULL;
        BITMAP bm;
        HBITMAP hbmOld;
    public:
        image()
        {
            HBITMAP g_hbmBall =  (HBITMAP)LoadImage(NULL, "C:\\FireDragon.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_SHARED);
            hdcimage = CreateCompatibleDC(NULL);
            hbmOld = (HBITMAP)SelectObject(hdcimage, g_hbmBall);
            GetObject(g_hbmBall, sizeof(bm), &bm);
        }
    
        int height()
        {
            return (int)bm.bmHeight;
        }
        int width()
        {
            return (int)bm.bmWidth;
        }
    
        operator HDC()
        {
            return hdcimage;
        }
    
        ~image()
        {
            SelectObject(hdcimage, hbmOld);
            DeleteDC(hdcimage);
        }
    };
    
    image m;
    //how i use with a Paint message:
    TransparentBlt(hdcWindow, 0, 0,m.width(), m.height(),m, 0, 0,m.width(), m.height(), GetPixel(m,0,0));
    for now i only have a problem... maybe anyone can advice me.
    the win32 let me use BMP,ICON, CUR,ANI image files... but i want read JPG,GIF, PNG(the most used) too. can anyone advice me?
    Last edited by joaquim; 09-15-2014 at 02:37 PM.

  6. #6
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    Quote Originally Posted by joaquim View Post
    for now i only have a problem... maybe anyone can advice me.
    the win32 let me use BMP,ICON, CUR,ANI image files... but i want read JPG,GIF, PNG(the most used) too. can anyone advice me?
    Have you looked in to libpng? I have no idea if it's any good or not, but from what I remember SDL_Image uses it for png format representation. You might want to try google too, or have a look at what other libraries are doing. Sorry not to be of more help.
    WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;

  7. #7
    Registered User
    Join Date
    Aug 2013
    Posts
    451
    Quote Originally Posted by Alpo View Post
    Have you looked in to libpng? I have no idea if it's any good or not, but from what I remember SDL_Image uses it for png format representation. You might want to try google too, or have a look at what other libraries are doing. Sorry not to be of more help.
    not yet... sorry but i must go back for a while: i'm trying show an icon:
    Code:
    hdcimage = CreateCompatibleDC(NULL);
                if(hdcimage==NULL)
                    MessageBox(NULL,"no HDC","error",MB_OK);
                hicon = (HICON)LoadImage(NULL, "C:\\acrobat.ico", IMAGE_ICON, 0 , 0 , LR_LOADFROMFILE|LR_SHARED);
                if(hicon==NULL)
                    MessageBox(NULL,"no icon","error",MB_OK);
    
                if(DrawIcon(hdcimage,0,0,hicon)==NULL)
                    MessageBox(NULL,"icon not drawed","error",MB_OK);
                ICONINFO s;
                GetIconInfo(hicon,&s);
                 bm.bmHeight=s.yHotspot;
                  bm.bmWidth=s.xHotspot;
                  MessageBox(NULL,to_string(s.xHotspot).c_str(),"error",MB_OK);//give 8... so the icon is handled
                  MessageBox(NULL,to_string(GetLastError()).c_str(),"error",MB_OK);//give 0(zero)
    the icon size is showed, but why the icon isn't showed? is the memory device context correctly created?(but i don't recive NULL)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [win32] - about child controls with text and image
    By joaquim in forum Windows Programming
    Replies: 15
    Last Post: 05-29-2014, 02:35 PM
  2. Make this image in c:
    By meLearningC in forum C Programming
    Replies: 46
    Last Post: 10-19-2012, 02:26 PM
  3. How to make an image reappear
    By hannah_n in forum C# Programming
    Replies: 2
    Last Post: 03-05-2011, 07:53 PM
  4. Beginner, trying to learn how to make an image.
    By shishkabob in forum C++ Programming
    Replies: 1
    Last Post: 10-24-2004, 08:46 PM
  5. Image class - loading image file
    By GaPe in forum Windows Programming
    Replies: 2
    Last Post: 07-11-2004, 01:35 PM