CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    Unhappy Convert this function to load from Resource rather than File

    Hello gurus,

    You can see following function (I got from codeproject as far I remember), loads from an external file. What I want is have same fucntion load from resources, I pass it resource ID as DWORD and it simply loads from resources not an external file. something like
    HBITMAP LoadImageResource(DWORD resID);


    I am sure for winapi gurus it is task of a few minutes. Any help is apprecited.

    Please, it is urgent:

    Code:
    HBITMAP LoadImageFile(char *FileName)  {
       // Use IPicture stuff to use JPG / GIF / BMP files
       IPicture* p;
       IStream* s;
       IPersistStream* ps;
       HGLOBAL hG;
       void* pp;
       FILE* fp;
    
    
       // Read file in memory
       fp = fopen(FileName,"rb");
       if (!fp)
    	  return NULL;
    	
    
       fseek(fp,0,SEEK_END);
       
       int fs = ftell(fp); //get filesize
       fseek(fp,0,SEEK_SET);
       hG = GlobalAlloc(GPTR,fs);
       if (!hG)  {
          fclose(fp);
          return NULL;
       }
    
    
          
       pp = (void*)hG;
       fread(pp,1,fs,fp);
       fclose(fp);
    	
    
       // Create an IStream so IPicture can
        CreateStreamOnHGlobal(hG,false,&s);
       if (!s) {
          GlobalFree(hG);
          return NULL;
       }
    
    
       OleLoadPicture(s,0,false,IID_IPicture,(void**)&p);
    
       if (!p) {
          s->Release();
          GlobalFree(hG);
          return NULL;
       }
       s->Release();
       GlobalFree(hG);
    
       HBITMAP hB = 0;
       p->get_Handle((unsigned int*)&hB);
    
       // Copy the image. Necessary, because upon p's release,
       // the handle is destroyed.
       HBITMAP hBB = (HBITMAP)CopyImage(hB,IMAGE_BITMAP,0,0,LR_COPYRETURNORG);
    
       p->Release();
       return hBB;
    }

    I do not want to use LoadBitmap or LoadImage in this regard, please. If possible, I want exactly same function but reading resources not external file.

    waiting for kind quick reply.


    regards
    Last edited by Ali Imran; January 31st, 2007 at 11:46 AM. Reason: fix typos
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured