Click here to Skip to main content
15,920,217 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questiondifference between CSocket class and window socket Pin
neha.agarwal2722-Mar-07 7:21
neha.agarwal2722-Mar-07 7:21 
AnswerRe: difference between CSocket class and window socket Pin
David Crow22-Mar-07 7:22
David Crow22-Mar-07 7:22 
QuestionAbstract Class, Socket Programming, JPEG in VC6 Pin
Andy Rama22-Mar-07 7:10
Andy Rama22-Mar-07 7:10 
AnswerRe: Abstract Class, Socket Programming, JPEG in VC6 Pin
Christian Graus22-Mar-07 7:14
protectorChristian Graus22-Mar-07 7:14 
AnswerRe: Abstract Class, Socket Programming, JPEG in VC6 Pin
Mark Salsbery22-Mar-07 7:23
Mark Salsbery22-Mar-07 7:23 
AnswerRe: Abstract Class, Socket Programming, JPEG in VC6 Pin
led mike22-Mar-07 8:18
led mike22-Mar-07 8:18 
JokeRe: Abstract Class, Socket Programming, JPEG in VC6 Pin
Mark Salsbery22-Mar-07 9:19
Mark Salsbery22-Mar-07 9:19 
AnswerRe: Abstract Class, Socket Programming, JPEG in VC6 Pin
DLChambers23-Mar-07 16:27
DLChambers23-Mar-07 16:27 
You can use OleLoadPicture().
The following code two-steps it - loads the JPG into a HBITMAP then draws the HBITMAP
If you just wanted load & draw it w/o the intermediate BMP you could call pPic->Render() into the dialog's DC.

#include <Ole2.h>
#include <olectl.h>
#define HIMETRIC_INCH 2540
HBITMAP LoadJpgFile(LPCTSTR filename)
{
  HBITMAP hBmp = NULL;

  if(filename && *filename)
  {
    HANDLE hFile = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
    if(hFile)
    {
      DWORD dwFileSize = GetFileSize(hFile, NULL);
      HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
      if(hGlobal)
      {
        LPVOID pvData = GlobalLock(hGlobal);
        if(pvData)
        {
          DWORD dwBytesRead = 0;
          BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
          GlobalUnlock(hGlobal);

          if(bRead && (dwBytesRead==dwFileSize))
          {
            LPSTREAM pstm = NULL;
            HRESULT hr = ::CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
            if(pstm)
            {
              LPPICTURE pPic = NULL;
              hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID*)&pPic);
              if(pPic)
              {
                // Retrieve logical dimensions
                long lWidth=0, lHeight=0;
                pPic->get_Width(&lWidth);
                pPic->get_Height(&lHeight);

                HDC hMemDC = CreateCompatibleDC(NULL);
                if(hMemDC)
                {
                  // Map logical dimensions to physical device
                  int nWidth = MulDiv(lWidth, GetDeviceCaps(hMemDC, LOGPIXELSX), HIMETRIC_INCH);
                  int nHeight = MulDiv(lHeight, GetDeviceCaps(hMemDC, LOGPIXELSY), HIMETRIC_INCH);
                  if((nWidth>=0) && (nHeight>=0))
                  {
                    HDC dcScreen = GetDC(NULL);
                    if(dcScreen)
                    {
                      HBITMAP hJpgBmp = ::CreateCompatibleBitmap(dcScreen, nWidth, nHeight);
                      if(hJpgBmp)
                      {
                        HBITMAP hPrevBmp = (HBITMAP)::SelectObject(hMemDC, hJpgBmp);

                        RECT rect = {0,0, nWidth,nHeight};
                        hr = pPic->Render(hMemDC, 0, 0, nWidth, nHeight, 0, lHeight, lWidth, -lHeight, &rect);

                        ::SelectObject(hMemDC, hPrevBmp);

                        if(SUCCEEDED(hr))
                          hBmp = hJpgBmp;
                        else
                          DeleteObject(hJpgBmp);
                      }
                      DeleteDC(dcScreen);
                    }
                  }
                  DeleteDC(hMemDC);
                }
                pPic->Release();
              }
              pstm->Release();
            }
          }
        }
        // Note: BoundChecker may say that 'hGlobal' is bad after it's been passed to CreateStreamOnHGlobal().
        // CreateStreamOnHGlobal() docs say that the fcn doesn't  modify the hdl, but BoundsChecker seems to think something is wrong.
        GlobalFree(hGlobal);  
      }
      CloseHandle(hFile);
    }
  }

  return hBmp;
}

void DrawBitmap(HDC hDC, HBITMAP hBitmap, int nXDest, int nYDest)
{
  BITMAP bm;
  if (GetObject(hBitmap, sizeof(bm), &bm))
  {
    HDC hMemDC = CreateCompatibleDC(hDC);

    HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);

    BitBlt(hDC, nXDest, nYDest, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);

    SelectObject(hMemDC, hOldBitmap);
    DeleteDC(hMemDC);
  }
}

void somefcn()
{
  // You supply szJpgFile, hDC, x, y
  HBITMAP hBmp = LoadJpgFile(szJpgFile);
  DrawBitmap(hDC, hBmp, x, y);
  DeleteObject(hBmp);
}

<pre>

QuestionIf Unix is on the server and client is windows Pin
prithaa22-Mar-07 6:52
prithaa22-Mar-07 6:52 
AnswerRe: If Unix is on the server and client is windows Pin
David Crow22-Mar-07 6:58
David Crow22-Mar-07 6:58 
JokeRe: If Unix is on the server and client is windows Pin
toxcct22-Mar-07 7:17
toxcct22-Mar-07 7:17 
GeneralRe: If Unix is on the server and client is windows Pin
prithaa22-Mar-07 8:19
prithaa22-Mar-07 8:19 
GeneralRe: If Unix is on the server and client is windows Pin
toxcct22-Mar-07 8:22
toxcct22-Mar-07 8:22 
GeneralRe: If Unix is on the server and client is windows Pin
prithaa22-Mar-07 8:44
prithaa22-Mar-07 8:44 
QuestionRe: If Unix is on the server and client is windows Pin
David Crow22-Mar-07 8:45
David Crow22-Mar-07 8:45 
GeneralRe: If Unix is on the server and client is windows Pin
David Crow22-Mar-07 8:44
David Crow22-Mar-07 8:44 
GeneralRe: If Unix is on the server and client is windows Pin
prithaa22-Mar-07 9:18
prithaa22-Mar-07 9:18 
GeneralRe: If Unix is on the server and client is windows Pin
David Crow22-Mar-07 9:29
David Crow22-Mar-07 9:29 
GeneralRe: If Unix is on the server and client is windows Pin
prithaa22-Mar-07 23:32
prithaa22-Mar-07 23:32 
QuestionMenu problem. Pin
david bagaturia22-Mar-07 6:21
david bagaturia22-Mar-07 6:21 
AnswerRe: Menu problem. Pin
toxcct22-Mar-07 6:42
toxcct22-Mar-07 6:42 
GeneralRe: Menu problem. Pin
david bagaturia22-Mar-07 19:26
david bagaturia22-Mar-07 19:26 
QuestionEdit Report at RunTime [modified] Pin
CDRAIN22-Mar-07 5:53
CDRAIN22-Mar-07 5:53 
QuestionFast Compression Codec in Directshow/C++ Pin
godspeed12322-Mar-07 5:44
godspeed12322-Mar-07 5:44 
AnswerRe: Fast Compression Codec in Directshow/C++ Pin
Christian Graus22-Mar-07 5:56
protectorChristian Graus22-Mar-07 5:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.