Click here to Skip to main content
16,005,149 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to read numbers (int and float) from a text file in C/C++? Pin
Saurabh.Garg7-Nov-08 19:04
Saurabh.Garg7-Nov-08 19:04 
AnswerRe: How to read numbers (int and float) from a text file in C/C++? Pin
Hamid_RT7-Nov-08 20:19
Hamid_RT7-Nov-08 20:19 
Questionlistview Pin
trioum7-Nov-08 17:50
trioum7-Nov-08 17:50 
AnswerRe: listview Pin
David Crow7-Nov-08 18:04
David Crow7-Nov-08 18:04 
QuestionReg : Key Down message not receiving in dialog procedure Pin
MANISH RASTOGI7-Nov-08 17:49
MANISH RASTOGI7-Nov-08 17:49 
AnswerRe: Reg : Key Down message not receiving in dialog procedure Pin
Hamid_RT7-Nov-08 20:23
Hamid_RT7-Nov-08 20:23 
GeneralRe: Reg : Key Down message not receiving in dialog procedure Pin
MANISH RASTOGI7-Nov-08 20:32
MANISH RASTOGI7-Nov-08 20:32 
Question[please help]why i cannot render my pic?thks! Pin
kaviniswell7-Nov-08 15:51
kaviniswell7-Nov-08 15:51 
i wana to load a JPG file and render it on gui,but no any result however...and every time it prints: Render PIC SUC!! and i cannot resolve the problem,my code is:

// open the pic file 
void CTestLoadJPEGDlg::OnBtnNew() 
{
    CFileDialog cFileDlg( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "File(*.JPEG;*.JPG;*.BMP)|*.JPEG;*.JPG;*.BMP||", NULL);
      
    if (IDOK == cFileDlg.DoModal())
    {
        // Get the pic and length
        CString strPicFilePath;
        strPicFilePath = cFileDlg.GetPathName();
        TRACE("the file path:%s\n",strPicFilePath);
        CFile cFile(strPicFilePath,CFile::modeRead);
        int nPicFileBufSize = cFile.GetLength(); 

        // Allocates movable memory. 
        // In Win32, memory blocks are never moved in physical memory, but they can be moved within the default heap. 
        HGLOBAL hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, nPicFileBufSize);
        if(NULL != hGlobal)
        {
            // locks a global memory object and returns a pointer to the first byte of the object's memory block
            LPVOID lpData = NULL;
            lpData = ::GlobalLock(hGlobal);
            if (NULL != lpData)
            {
                // read and lock
                cFile.ReadHuge(lpData, nPicFileBufSize);
                GlobalUnlock(hGlobal);

                // create a stream object in the heap
                IStream *pIstream = NULL;
                CreateStreamOnHGlobal(hGlobal,TRUE,&pIstream);
                if (NULL != pIstream)
                {
                    // load the pic by the stream object
                    HRESULT hr = ::OleLoadPicture(pIstream, nPicFileBufSize, TRUE, IID_IPicture, (LPVOID*)&m_iPicture);
                    if (FAILED(hr))
                    {
                        TRACE("OleLoadPicture failed!!\n");
                        goto CLOSEFILE;
                    }
                    pIstream->Release();
                }
            }
            else
            {
                TRACE("lpData=NULL!!!\n");
                goto CLOSEFILE;
            }
        }
        else
        {
            TRACE("hGlobal=NULL!!!\n");
            goto CLOSEFILE;
        }

        // show the pic
        if (NULL != m_iPicture)
        {   
            CSize sizeInHimetric;   // pic size, metric system

            HRESULT hr = NULL;
            hr = m_iPicture->get_Width(&sizeInHimetric.cx);
            if (FAILED(hr))
            {
                TRACE("get_Width failed!!\n");
                goto CLOSEFILE;
            }
            hr = m_iPicture->get_Height(&sizeInHimetric.cy);
            if (FAILED(hr))
            {
                TRACE("get_Height failed!!\n");
                goto CLOSEFILE;
            }

            //himetric convert to inch, then inch to pixel

            HDC hDCScreen = ::GetDC(NULL);
            int nPixelsPerInchX = ::GetDeviceCaps(hDCScreen, LOGPIXELSX);
            int nPixelsPerInchY = ::GetDeviceCaps(hDCScreen, LOGPIXELSY);
            ::ReleaseDC(NULL, hDCScreen);

            CSize sizeInPixel;  // pic size, pixel system
            sizeInPixel.cx = MulDiv(sizeInHimetric.cx, nPixelsPerInchX, HIMETRIC_PER_INCH);
            sizeInPixel.cy = MulDiv(sizeInHimetric.cy, nPixelsPerInchY, HIMETRIC_PER_INCH);

            m_szPicPixel = sizeInPixel;
            m_szPicHimetric = sizeInHimetric;

            DrawPic();
        }
        
    CLOSEFILE:
        cFile.Close();
    }
    return;
}

// draw pic
void CTestLoadJPEGDlg::DrawPic()
{
    if (NULL == m_iPicture)
    {
        TRACE("m_iPicture=NULL!!\n");
        return;
    }

    CRect rect;
    m_staticPicRect.GetWindowRect(rect);
    
    // the left point
    CPoint ptTopLeft;
    ptTopLeft = rect.TopLeft();

    // zoom rate. [>1.0:zoom in, <1.0:zoom out] 
    float fZoomRate = 1.0;

    int   xSrcPos = (int)(ptTopLeft.x / fZoomRate);              
    int   ySrcPos = (int)(ptTopLeft.y / fZoomRate);            
    int   cxSrcWidth = (int)(rect.Width() / fZoomRate);          
    int   cySrcHeight = (int)(rect.Height() / fZoomRate);       
  
    CDC* dc = GetDC();
    int nPixelsPerInchX = ::GetDeviceCaps(*dc, LOGPIXELSX);
    int nPixelsPerInchY = ::GetDeviceCaps(*dc, LOGPIXELSY);

    // MulDiv(a,b,c) -> a*b/c

    // Horizontal   offset   in   source   picture
    int xHimetric = MulDiv(xSrcPos, HIMETRIC_PER_INCH, nPixelsPerInchX);   
    // Vertical   offset   in   source   picture   
    int yHimetric = MulDiv(ySrcPos, HIMETRIC_PER_INCH, nPixelsPerInchY);
    // Amount   to   copy   horizontally   in   source   picture
    int wHimetric = MulDiv(cxSrcWidth, HIMETRIC_PER_INCH, nPixelsPerInchX);
    // Amount   to   copy   vertically   in   source   picture   
    int hHimetric = MulDiv(cySrcHeight, HIMETRIC_PER_INCH, nPixelsPerInchY);

    HRESULT hr = m_iPicture->Render(dc->GetSafeHdc(), rect.left, rect.top, rect.Width(), rect.Height(), 
                                xHimetric, yHimetric, wHimetric, hHimetric, NULL);
    if (FAILED(hr))
    {
        TRACE("Render failed!!\n");
        return;
    }
    TRACE("Render PIC SUC!!\n");
}


thks again!
AnswerRe: [please help]why i cannot render my pic?thks! Pin
Hamid_RT7-Nov-08 20:47
Hamid_RT7-Nov-08 20:47 
GeneralRe: [please help]why i cannot render my pic?thks! Pin
kaviniswell7-Nov-08 20:53
kaviniswell7-Nov-08 20:53 
GeneralRe: [please help]why i cannot render my pic?thks! Pin
Hamid_RT8-Nov-08 4:40
Hamid_RT8-Nov-08 4:40 
QuestionIs there a way to call a method with a CStringT Variable ? Pin
SNArruda7-Nov-08 11:48
SNArruda7-Nov-08 11:48 
QuestionHow to draw a chinese text on a window Pin
Tianan7-Nov-08 10:50
Tianan7-Nov-08 10:50 
JokeRe: How to draw a chinese text on a window Pin
sashoalm7-Nov-08 23:52
sashoalm7-Nov-08 23:52 
GeneralRe: How to draw a chinese text on a window Pin
Hamid_RT8-Nov-08 3:31
Hamid_RT8-Nov-08 3:31 
GeneralRe: How to draw a chinese text on a window Pin
Tianan8-Nov-08 13:01
Tianan8-Nov-08 13:01 
GeneralRe: How to draw a chinese text on a window Pin
Hamid_RT8-Nov-08 20:52
Hamid_RT8-Nov-08 20:52 
AnswerRe: How to draw a chinese text on a window Pin
Iain Clarke, Warrior Programmer8-Nov-08 13:10
Iain Clarke, Warrior Programmer8-Nov-08 13:10 
GeneralRe: How to draw a chinese text on a window Pin
Tianan8-Nov-08 16:27
Tianan8-Nov-08 16:27 
QuestionChecking for a registered DLL Pin
kpiciulo7-Nov-08 9:57
kpiciulo7-Nov-08 9:57 
AnswerRe: Checking for a registered DLL Pin
CPallini7-Nov-08 10:42
mveCPallini7-Nov-08 10:42 
QuestionStrange Behaviour on LookupPrivilegeValue Pin
bsaksida7-Nov-08 8:42
bsaksida7-Nov-08 8:42 
QuestionVisual C++ 2003 MDI file associations fail out of the box [solved] Pin
bob169727-Nov-08 4:49
bob169727-Nov-08 4:49 
QuestionDisable a Button ina SDI application Pin
m_mun7-Nov-08 2:50
m_mun7-Nov-08 2:50 
AnswerRe: Disable a Button ina SDI application Pin
Nishad S7-Nov-08 2:53
Nishad S7-Nov-08 2:53 

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.