Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/articles/mfc-tutorials/)
-   -   Display Bitmap in a Picture Box using MFC from a file (http://www.go4expert.com/articles/display-bitmap-picture-box-using-mfc-t350/)

nishalingadurai 24Dec2006 22:58

Re: Display Bitmap in a Picture Box using MFC from a file
 
hai
code you given for display bitmap is complied but does not display output window.
plz tell what is the reason.

and you mention
"Change the Type of the picture box to OWNER_DRAW."
i could not understand this

shabbir 25Dec2006 10:18

Re: Display Bitmap in a Picture Box using MFC from a file
 
Quote:

Originally Posted by nishalingadurai
hai
code you given for display bitmap is complied but does not display output window.
plz tell what is the reason.

Probably some problem in steps as I could do using the article steps/

Quote:

Originally Posted by nishalingadurai
and you mention
"Change the Type of the picture box to OWNER_DRAW."
i could not understand this

Right Click on picture box resource in the designer and check you will see on property by that name.

nishalingadurai 25Dec2006 19:11

Re: Display Bitmap in a Picture Box using MFC from a file
 
hai

the code which is display in window different in zip file(picture file). i get error on compile
zip code. the error is "error C2039: 'DoModal' : is not a member of 'CBitmapPictureDlg'"
plz what i make wrong.

nishalingadurai 25Dec2006 19:26

Re: Display Bitmap in a Picture Box using MFC from a file
 
hai

you said

"Change the Type of the picture box to OWNER_DRAW.
Add a variable to the picture box. By default it will be CStatic. I call it picPreview"


In picture box property- type have option such as frame,icon,bitmap etc "OWNER_DRAW means what? is picpreview is variable of picturebox?

I cannot create variable for picturebox, there is no object on member variable in class wizard.

I have another doubt why two cpp and h file is created when creating new workspace.
example my project name is BitmapPicture, source file have BitmapPicture.cpp and BitmapPictureDlg.cpp. header file contain BitmapPicture.h and BitmapPictureDlg.h.

plz tell which code i have to follow, code which display under "Display Bitmap in a Picture Box using MFC from a file" or Picture zip file.

shabbir 25Dec2006 21:41

Re: Display Bitmap in a Picture Box using MFC from a file
 
You probably needs to get hands on the MFC before going into some more complicated problems. I am trying to explain some of them but if you cannot get them try getting the a book on basics of MFC as the steps I explained in the article are pretty simple

1. I never told that the zipped files will compile correctly. It just that you add it to your existing project and that should enhance the ability of your picture box.

2. OWNER_DRAW will be a check box type of property which all the controls have and the property is relating to how the control will be drawn. You will handle it or should windows do the job for you.

3. Regarding creating a variable you should use the class Wizard for the picture box and if you cannot use the class wizard either you should use a seperate thread here or use some IDE help.

4. Regarding the files generated I would say you go to the basics first and get some good hands on MFC before going into some good looking samples.

yogessshhh 10Jan2007 17:01

Re: Display Bitmap in a Picture Box using MFC from a file
 
helpful article

thanks shabbirrrrrrrrrrr

shabbir 10Jan2007 18:13

Re: Display Bitmap in a Picture Box using MFC from a file
 
Quote:

Originally Posted by yogessshhh
helpful article

thanks shabbirrrrrrrrrrr

My pleasure.

Cuckoo 15Jan2007 22:12

Re: Display Bitmap in a Picture Box using MFC from a file
 
Hello shabir... i have a question about picture loading...
i have build this engine which switches pictures on a Frame and i want it to be in a 25 fps rate, how can i be done?

here is my code:


Code:

BOOL MovieEngine::paintCurrFrame(BOOL onPaint)
{
        PAINTSTRUCT ps;       
        HDC hDC;
        hDC = ::BeginPaint(m_paintTarget->m_hWnd, &ps);
        HDC memDC = CreateCompatibleDC(hDC);
        m_jpegRect.bottom=m_offsetY+m_currFrame->GetHeight(); //m_currFrame is a cximage object
        m_jpegRect.right=m_offsetX+m_currFrame->GetWidth();
        m_paintTarget->GetClientRect(m_clientRect);
        HBITMAP hMemBmp = CreateCompatibleBitmap(hDC,  m_clientRect.Width(),  m_clientRect.Height());
        HBITMAP hOldBmp = (HBITMAP)SelectObject(memDC, hMemBmp);
        FillRect(memDC,m_clientRect,(HBRUSH) (COLOR_WINDOW));
        if(m_playing)
                m_currFrame->Draw(memDC,m_jpegRect);
        BitBlt(hDC, 0, 0, m_clientRect.Width(), m_clientRect.Height(), memDC, 0, 0, SRCCOPY);
        SelectObject(memDC, hOldBmp);
        ::EndPaint(m_paintTarget->m_hWnd, &ps);
        DeleteObject(hMemBmp);
        if(!onPaint){
                m_paintTarget->InvalidateRect(m_jpegRect);
                m_paintTarget->RedrawWindow(m_jpegRect);
        }
        return TRUE;
}

this is the engine itself as a thread:

Code:

UINT MovieEngine::playThread(LPVOID engine)
{
        MovieEngine* thisEngine=(MovieEngine*)engine;
        if(thisEngine->m_buffComplete){
                while (thisEngine->m_movieBuff.size()>0)//m_movieBuff is a vector of pointers to cximages (hance the movie).
                {
                        thisEngine->m_currFrame=thisEngine->m_movieBuff.front();
                        thisEngine->m_movieBuff.pop();
                        thisEngine->paintCurrFrame(FALSE); //function above
                        delete thisEngine->m_currFrame;
                        Sleep(40);// 40 milisec is the time needed to get 25 fps rate but all the picture switching takes time, so i need 40-switch_time...
                }
        }
        return 0;
}

ofcourse there is a loading thread (to keep buffer full untill the movie ends) while playing but it is irelevant for now.
i hope the code is clear, couse i am new to mfc and visual at all.
i managed to make it play but nothing deterministic. sometimes it plays faster than 25 fps sometimes slower.... i donno what to do :(
Second year SE student.

shabbir 16Jan2007 09:42

Re: Display Bitmap in a Picture Box using MFC from a file
 
Cuckoo, please post your query into a seperate thread and try not jumping into a thread with your query as that does not help much. Its always good to go through your query but if that did not help you should be going with a new thread.

Nishant Desai 19Jan2007 16:31

Re: Display Bitmap in a Picture Box using MFC from a file
 
Quote:

Originally Posted by shabbir
Cuckoo, please post your query into a seperate thread and try not jumping into a thread with your query as that does not help much. Its always good to go through your query but if that did not help you should be going with a new thread.

Dear Shabbir,

I am a newbie to this forum, and I want to change the pictures as the boolean, by boolean mean when the variable is true, the picture box should show the green dot and if the variable is false then picturebox is false, then it should show the red dot.

I have bitmaps of both, red and green dots. but i dont know how to load them into the picture box when the event ocurs, please help me to sort out the fact.

Actually I have the big project, so i dont think that i have to create the picture box class, but i want to know that how to create the DC for the picture box, what should i write so that it creatres the DC for the picture box, i have taken.

Thanks,
Nishant


All times are GMT +5.5. The time now is 03:16.