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

C / C++ / MFC

 
GeneralRe: saving bitmap to a file Pin
subramanyeswari4-Jun-08 21:30
subramanyeswari4-Jun-08 21:30 
QuestionGetting rid of the following warnings.. Pin
pl_kode4-Jun-08 20:09
pl_kode4-Jun-08 20:09 
AnswerRe: Getting rid of the following warnings.. Pin
Cedric Moonen4-Jun-08 20:23
Cedric Moonen4-Jun-08 20:23 
AnswerRe: Getting rid of the following warnings.. Pin
toxcct4-Jun-08 21:11
toxcct4-Jun-08 21:11 
Questionstatic Lib gives Link Error - Migrating to VC 2005 from VC 2003 Pin
zameer.kh4-Jun-08 18:45
zameer.kh4-Jun-08 18:45 
AnswerRe: static Lib gives Link Error - Migrating to VC 2005 from VC 2003 Pin
toxcct4-Jun-08 21:05
toxcct4-Jun-08 21:05 
GeneralRe: static Lib gives Link Error - Migrating to VC 2005 from VC 2003 Pin
zameer.kh5-Jun-08 4:38
zameer.kh5-Jun-08 4:38 
QuestionQuestion about painting and scrolling in wxWidgets!! Pin
Rohde4-Jun-08 12:36
Rohde4-Jun-08 12:36 
So this isn't really Visual C++ but still I hope it's ok I "pollute" the board Smile | :)

I need some help with some paint-related issues.

I'm trying to build a simple image viewer/editor - just for fun.

I have some problems when painting the bitmap though.

If the bitmap is smaller than the client area it works nice; it gets painted in the center of the area as I want.

If the bitmap is bigger than the client area both horizontally and vertically it also works beautifully. I can use the scrollbars in both directions and the image scrolls correctly.

The problem arises when the image is larger than the client area in only one of the two dimensions. In this case when I scroll I only get to see the background; in other words the newly exposed image area doesn't repaint when scrolling.

My pain handler is as follows:

void MyScrolledWindow::OnPaint(wxPaintEvent& event)
{       
    wxPaintDC dc(this);   

    // Only paint if we have a valid bitmap
    if(m_theBitmap && m_theBitmap->Ok())
    {
        // Get the outer bounds of the region of the window that has been damaged.
        const wxRect rectUpdate = GetUpdateRegion().GetBox();
        // Translate the device coordinates of the upper left corner of the invalid region to logical coordinates.
        const wxPoint ptVirt = CalcUnscrolledPosition(rectUpdate.GetTopLeft());
        // The memory device context we are using for double buffering.
        wxMemoryDC mdc;       
        // Select the bitmap into the device context so we are ready for double buffering.
        mdc.SelectObject(*m_theBitmap);       
       
        // Get the size of the client area.
        const wxRect rcClient = GetClientSize();

        // This will be the point of where to draw the upper left corner of our image.
        wxPoint upperLeft;

        // If the client area is bigger than the bitmap in either width or height...
        if(rcClient.GetWidth() > m_theBitmap->GetWidth() || rcClient.GetHeight() > m_theBitmap->GetHeight())
        {
            // ...draw the background...
            PaintBackground(dc);

            // ... and get the width and height of the image...
            wxCoord w = m_theBitmap->GetWidth();
            wxCoord h = m_theBitmap->GetHeight();           

            // ...so we can use that for calculating the position of the upper left corner of the image.
            int x = wxMax(0, (rcClient.width-w)/2);
            int y = wxMax(0, (rcClient.height-h)/2);

            // Save the just calculated coordinates.
            upperLeft.x = x;
            upperLeft.y = y;           
        }
        else
        {
            // We have a huge image, so we simple paint it at the top left of the client region.
            upperLeft = rectUpdate.GetTopLeft();
        }

        // Now switch the device context so we show the bitmap.
        dc.Blit(upperLeft, rectUpdate.GetSize(), &mdc, ptVirt, wxCOPY);
        // Select in a null object to clear the memory device context.
        mdc.SelectObject(wxNullBitmap);
    }
    else
    {
        // We have no valid bitmap so simply paint the background.
        PaintBackground(dc);       
    }
} 


I have fought with this problem the whole bloody day without being any nearer a solution so I really hope someone can spot what I'm doing wrong here.



"When you have made evil the means of survival, do not expect men to remain good. Do not expect them to stay moral and lose their lives for the purpose of becoming the fodder of the immoral. Do not expect them to produce, when production is punished and looting rewarded. Do not ask, `Who is destroying the world?' You are."

-Atlas Shrugged, Ayn Rand

AnswerRe: Question about painting and scrolling in wxWidgets!! Pin
Rohde4-Jun-08 12:45
Rohde4-Jun-08 12:45 
QuestionHelp! Need source code for _isnan and _finite Pin
Jesse Evans4-Jun-08 12:26
Jesse Evans4-Jun-08 12:26 
AnswerRe: Help! Need source code for _isnan and _finite Pin
Saurabh.Garg4-Jun-08 16:31
Saurabh.Garg4-Jun-08 16:31 
GeneralRe: Help! Need source code for _isnan and _finite Pin
Jesse Evans5-Jun-08 6:33
Jesse Evans5-Jun-08 6:33 
GeneralRe: Help! Need source code for _isnan and _finite Pin
Saurabh.Garg5-Jun-08 16:54
Saurabh.Garg5-Jun-08 16:54 
AnswerRe: Help! Need source code for _isnan and _finite Pin
Jijo.Raj4-Jun-08 20:16
Jijo.Raj4-Jun-08 20:16 
GeneralRe: Help! Need source code for _isnan and _finite Pin
Jesse Evans5-Jun-08 6:34
Jesse Evans5-Jun-08 6:34 
AnswerRe: Help! Need source code for _isnan and _finite Pin
toxcct4-Jun-08 20:58
toxcct4-Jun-08 20:58 
GeneralRe: Help! Need source code for _isnan and _finite Pin
Jesse Evans5-Jun-08 6:19
Jesse Evans5-Jun-08 6:19 
GeneralRe: Help! Need source code for _isnan and _finite Pin
toxcct5-Jun-08 6:29
toxcct5-Jun-08 6:29 
GeneralRe: Help! Need source code for _isnan and _finite Pin
Jesse Evans5-Jun-08 6:39
Jesse Evans5-Jun-08 6:39 
QuestionBlock Printer Pin
zoiomon4-Jun-08 10:42
zoiomon4-Jun-08 10:42 
QuestionRe: Block Printer Pin
David Crow5-Jun-08 3:12
David Crow5-Jun-08 3:12 
QuestionMultilanguage support [modified] Pin
Nelek4-Jun-08 7:44
protectorNelek4-Jun-08 7:44 
AnswerRe: Multilanguage support Pin
Maximilien4-Jun-08 8:19
Maximilien4-Jun-08 8:19 
GeneralRe: Multilanguage support Pin
Nelek4-Jun-08 12:55
protectorNelek4-Jun-08 12:55 
GeneralRe: Multilanguage support Pin
Nelek4-Jun-08 13:50
protectorNelek4-Jun-08 13:50 

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.