none
vs2005 mfc pocket pc載圖 RRS feed

  • 問題

  •  

    我開發的環境是vs2005 mfc智慧型裝置應用程式,我己找到mfc應用程式的範例可是不能在手機上執行,圖片出不來,請問各位大大要如何修改,下面是我目前的程式,請各位先進指教。

    CFileDialog Load(true,NULL,NULL,NULL,L"Bitmap Files (*.*)|*.*",this); // 呼叫檔案讀入的視窗
     Load.DoModal();
     HBITMAP hbitmap = (HBITMAP)LoadImage(NULL, Load.GetPathName(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
     CStatic* pImage = (CStatic*) GetDlgItem(IDC_STATIC_1);
     pImage->SetBitmap (hbitmap);
     UpdateData(false);

    2008年4月22日 上午 08:24

解答

  • CFileDialog fileDlg(TRUE, NULL, _T("\\"), NULL, _T("All Files|*.bmp"));
     if(IDOK == fileDlg.DoModal())
     {
      HBITMAP hBitmap = SHLoadDIBitmap(fileDlg.GetPathName());
      map.ModifyStyle(0xF, SS_BITMAP);
      map.SetBitmap(hBitmap);
     }

     UpdateData(false);

    2008年4月28日 上午 11:44

所有回覆

  • HI,

     

    您可以參考這一支程式的寫法, VS2005的目錄可能會不太一樣, 找一下應該可以找到:

     

    C:\Program Files\Windows Mobile 5.0 SDK R2\Samples\PocketPC\CPP\Win32\Imaging

     

    void DrawImage(HDC hdc)
    {
        IImagingFactory *pImgFactory = NULL;
        IImage *pImage = NULL;
        RECT rc = { 0, 0, 110, 88};

        // Normally you would only call CoInitialize/CoUninitialize
        // once per thread.  This sample calls CoInitialize in this
        // draw function simply to illustrate that you must call
        // CoInitialize before calling CoCreateInstance.
        CoInitializeEx(NULL, COINIT_MULTITHREADED);

        // Create the imaging factory.
        if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory,
                                        NULL,
                                        CLSCTX_INPROC_SERVER,
                                        IID_IImagingFactory,
                                        (void **)&pImgFactory)))
        {
            // Load the image from the JPG file.
            if (SUCCEEDED(pImgFactory->CreateImageFromFile(
                            TEXT("\\Program Files\\Imaging\\flower.jpg"),
                            &pImage)))
            {
                // Draw the image.
                pImage->Draw(hdc, &rc, NULL);
                pImage->Release();
            }

            pImgFactory->Release();
        }
        CoUninitialize();
    }

     

    這種做法會比LoadImage好, 因為LoadImage只能處理三種圖檔格式, .bmp, .cur, 和.ico

     

    tihs

    2008年4月22日 上午 08:55
  •  

    謝謝我找到那個當案了,用模擬器跑也可以,不過我mfc的功力太差了我不會移植過去,試了四十幾分鐘還是搞不定,如果可以的話可以幫我修改一下,就按下下button可以選擇檔案,在picture 物件中show出bmp就好。謝謝了
    2008年4月22日 上午 10:15
  • CFileDialog fileDlg(TRUE, NULL, _T("\\"), NULL, _T("All Files|*.bmp"));
     if(IDOK == fileDlg.DoModal())
     {
      HBITMAP hBitmap = SHLoadDIBitmap(fileDlg.GetPathName());
      map.ModifyStyle(0xF, SS_BITMAP);
      map.SetBitmap(hBitmap);
     }

     UpdateData(false);

    2008年4月28日 上午 11:44
  • 我是這樣做的:

     

    1) 在類別加入以下的變數和方法:

     

    CString strFileName;

     

    void DrawImage(HDC hdc, RECT rc, CString FileName)
    {
        IImagingFactory *pImgFactory = NULL;
        IImage *pImage = NULL;
        //RECT rc = { 0, 0, 110, 88};

        // Normally you would only call CoInitialize/CoUninitialize
        // once per thread.  This sample calls CoInitialize in this
        // draw function simply to illustrate that you must call
        // CoInitialize before calling CoCreateInstance.
        CoInitializeEx(NULL, COINIT_MULTITHREADED);

        // Create the imaging factory.
        if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory,
                                        NULL,
                                        CLSCTX_INPROC_SERVER,
                                        IID_IImagingFactory,
                                        (void **)&pImgFactory)))
        {
            // Load the image from the JPG file.
            if (SUCCEEDED(pImgFactory->CreateImageFromFile(FileName, &pImage)))
            {
                // Draw the image.
                pImage->Draw(hdc, &rc, NULL);
                pImage->Release();
            }

            pImgFactory->Release();
        }
        CoUninitialize();
    }

     

    2) 處理Dialog的OnPaint

    void CShowPicDlg:SurprisenPaint()
    {
     CPaintDC dc(this); // device context for painting
     CRect rt;
     m_Pic.GetWindowRect(&rt);
     DrawImage(dc, rt, strFileName);
     
    }

     

    3) 處理Button被使用者點中的事件:

     

    void CShowPicDlg:SurprisenBnClickedButton1()
    {
     CFileDialog fileDlg(TRUE, NULL, _T("\\"), NULL, _T("All Files|*.bmp"));
     if(IDOK == fileDlg.DoModal())
     {
      strFileName=fileDlg.GetPathName();
      UpdateWindow();
     }
    }

     

    tihs

    2008年5月1日 上午 06:03