Note that there are some explanatory texts on larger screens.

plurals
  1. POError with displaying an .bmp image using mfc dialog
    primarykey
    data
    text
    <p>I am trying to display a bitmap image using MFC application. I am using a browse button to select file which is working properly. But when I try to load an image by double clicking on the file, the application is launched, but the image is not displayed.</p> <p>Here is my code for browse button and function to open a double clicked image.</p> <pre><code>void COpenImageDlg::OnBnClickedButton1() { // TODO: Add your control notification handler code here CString path; CFileDialog dlg(TRUE); int result=dlg.DoModal(); if(result==IDOK) { path=dlg.GetPathName(); UpdateData(FALSE); } HBITMAP hBmp = (HBITMAP)::LoadImage(NULL, path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION); CBitmap bmp; bmp.Attach(hBmp); CClientDC dc(this); CDC bmDC; bmDC.CreateCompatibleDC(&amp;dc); CBitmap *pOldbmp = bmDC.SelectObject(&amp;bmp); BITMAP bi; bmp.GetBitmap(&amp;bi); dc.BitBlt(0,0,bi.bmWidth,bi.bmHeight,&amp;bmDC,0,0,SRCCOPY); bmDC.SelectObject(pOldbmp); } void COpenImageDlg::OpenImage1(CString path) { //CString path; CFileDialog dlg(TRUE); int result=dlg.DoModal(); if(result==IDOK) { path=dlg.GetPathName(); UpdateData(FALSE); } HBITMAP hBmp = (HBITMAP)::LoadImage(NULL, path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION); CBitmap bmp; bmp.Attach(hBmp); CClientDC dc(this); CDC bmDC; bmDC.CreateCompatibleDC(&amp;dc); CBitmap *pOldbmp = bmDC.SelectObject(&amp;bmp); BITMAP bi; bmp.GetBitmap(&amp;bi); dc.BitBlt(0,0,bi.bmWidth,bi.bmHeight,&amp;bmDC,0,0,SRCCOPY); } </code></pre> <p>Init class :</p> <p>`BOOL COpenImageApp::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail.</p> <pre><code>INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&amp;InitCtrls); CWinApp::InitInstance(); AfxEnableControlContainer(); // Create the shell manager, in case the dialog contains // any shell tree view or shell list view controls. CShellManager *pShellManager = new CShellManager; // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need // Change the registry key under which our settings are stored // TODO: You should modify this string to be something appropriate // such as the name of your company or organization SetRegistryKey(_T("Local AppWizard-Generated Applications")); COpenImageDlg dlg; m_pMainWnd = &amp;dlg; INT_PTR nResponse = dlg.DoModal(); char* buff; char* command_line = GetCommandLine(); buff = strchr(command_line, ' '); buff++; buff = strchr(buff, ' '); buff++; buff = strchr(buff, ' '); buff++; if (buff != NULL) { HBITMAP hBmp = (HBITMAP)::LoadImage(NULL, "C:\Users\Raguvaran\Desktop\tiger.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION); CBitmap bmp; bmp.Attach(hBmp); dlg.RedrawWindow(); CClientDC dc(m_pMainWnd); CDC bmDC; bmDC.CreateCompatibleDC(&amp;dc); CBitmap *pOldbmp = bmDC.SelectObject(&amp;bmp); BITMAP bi; bmp.GetBitmap(&amp;bi); dc.BitBlt(0,0,bi.bmWidth,bi.bmHeight,&amp;bmDC,0,0,SRCCOPY); } //RedrawWindow(dlg, NULL, NULL, RDW_INVALIDATE); //UpdateWindow(dlg); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Delete the shell manager created above. if (pShellManager != NULL) { delete pShellManager; } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; </code></pre> <p>}`</p> <p>I used the same code for browse button and it displays the image. But when I double click the file, the image is not displayed. Please tell me what I am doing wrong.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload