Thread: load gif into program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    That's probably because GDI+ is a C++ only. Why they've done that I don't know, but either way it'll never work in your C file.

    The cheaters' way to do it is:-
    Code:
    LPPICTURE LoadPicture(char *szFilename)
    {
       LPPICTURE lpPicture;
    
       // This is an OLE function, filename must be in Unicode
    #ifndef UNICODE
       unsigned short wzFilename[MAX_PATH];
       MultiByteToWideChar(GetACP(), MB_PRECOMPOSED, szFilename, -1, wzFilename, MAX_PATH);
    #else
       char *wzFilename;
       wzFilename = szFilename;
    #endif
       if (OleLoadPicturePath(wzFilename, NULL, 0, 0, &IID_IPicture, (void **)&lpPicture) != S_OK)
          return NULL;
    
       return lpPicture;
    }
    And when you want to show it on a DC:-
    Code:
    int iHiWidth, iHiHeight; // gives you size in HIMETRICs
    BITMAP bmp; // pixel size in here
    HBITMAP hbmp;
    
    lpPicture->lpVtbl->get_Width(lpPicture, &iHiWidth);
    lpPicture->lpVtbl->get_Height(lpPicture, &iHiHeight);
    lpPicture->lpVtbl->get_Handle(lpPicture, (OLE_HANDLE *)&hbmp);
    GetObject(hbmp, sizeof(BITMAP), &bmp);
    lpPicture->lpVtbl->Render(lpPicture, hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, 0, iHiHeight, iHiWidth, -iHiHeight, NULL);
    When you're finished with it, remember to:-
    Code:
    lpPicture->lpVtbl->Release(lpPicture);
    Depending on which version of Windows is being used, you may also need to call CoInitialize().
    Last edited by SMurf; 01-10-2006 at 07:34 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM