I’m writing a code on microsoft visual c++ 6.0 for load *bmp file and save it to *bmp file too. But i got stuck on save to *bmp code. Help me please..

void WarnaToRGB(long int warna,int *Red,int *Green,int *Blue) 
{ 
 *Red=warna&0x000000FF; 
 *Green=(warna&0x0000FF00)>>8; 
 *Blue=(warna&0x00FF0000)>>16; 
}

long int RGBToWarna(int Red,int Green,int Blue) 
{ 
 return(Red+(Green<<8)+(Blue<<16)); 
}

/*This code used for load an image and display it on a picture box*/
void CSaveimageDlg::OnButton1() 
{
    static char BASED_CODE szFilter[]="Bitmap Files(*.bmp)|*.bmp||";
    CFileDialog m_ldFile(TRUE,"*.bmp",name,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
    if(m_ldFile.DoModal()==IDOK)
    {
        name=m_ldFile.GetPathName();
    }   
    CDC* pDC = m_picture1.GetDC();
    CDC dcMem;
    CRect rect;
    BITMAP bm;
    HBITMAP hBitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),name,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
    if(hBitmap)
    {
        if(m_bmpBitmap.DeleteObject())m_bmpBitmap.Detach();
        m_bmpBitmap.Attach(hBitmap);
    }
    m_picture1.GetClientRect(rect);
    m_bmpBitmap.GetBitmap(&bm);
    dcMem.CreateCompatibleDC(pDC);
    dcMem.SelectObject(&m_bmpBitmap);
    pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
}

/*This code used for display image on a picture box*/
void CSaveimageDlg::OnButton2() 
{
    int i,j,red,green,blue,r,g,b;
    long int warna,warnagray;
    CDC* pDC=m_picture2.GetDC();
    CDC dcMem;
    CRect rect;
    BITMAP bm;
    HBITMAP hBitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),name,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
    if(hBitmap)
    {
        if(m_bmpBitmap.DeleteObject())m_bmpBitmap.Detach();
        m_bmpBitmap.Attach(hBitmap);
    }
    m_picture2.GetClientRect(rect);
    m_bmpBitmap.GetBitmap(&bm);
    dcMem.CreateCompatibleDC(pDC);
    dcMem.SelectObject(&m_bmpBitmap);
    for(i=0;i<bm.bmHeight;i++)
    {
        for(j=0;j<bm.bmWidth;j++)
        {
            warna=dcMem.GetPixel(j,i);
            WarnaToRGB(warna,&red,&green,&blue);
            r=red;
            g=green;
            b=blue;
            warnagray=RGBToWarna(r,g,b);
            dcMem.SetPixel(j,i,warnagray);
        }
    }
    pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
}

/*I got stuck on this code,how to save it to a *bmp file? Please help me..*/
void CSaveimageDlg::OnButton3() 
{

??????????

}

I don't understand that code, put it between code syntax plox.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.