mfc >> picture box

by susi » Tue, 16 Sep 2003 13:54:55 GMT

hi,
im able to load bitmap from bmp file into the dialog.i
have a picture box in my mfc application.what i want to do
is display the file in the picture box control.how shall i
do it.i dont know where to pass the handle as picture box
control.my code is ,
CString szFilename ("D:\\abc2.bmp");
HBITMAP hBmp = (HBITMAP)::LoadImage(
NULL,
szFilename,
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION
);
CBitmap bmp;
bmp.Attach(hBmp);
CClientDC dc(this);
CDC bmDC;
bmDC.CreateCompatibleDC(&dc);
CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
BITMAP bi;
bmp.GetBitmap(&bi);
dc.StretchBlt
(0,0,500,720,&bmDC,0,0,bi.bmWidth,bi.bmHeight,SRCCOPY);
bmDC.SelectObject(pOldbmp);
where should i change the handle or what should i do?
thanks for spending ur time
susi.


mfc >> picture box

by Ajay Kalra » Tue, 16 Sep 2003 14:09:12 GMT


I am not sure what is wrong with your code. Your bmp object seems to be
getting destroyed as soon you exit the scope. I would take a different
approach. This sample code/article would do what you want:
http://msdn.microsoft.com/msdnmag/issues/01/10/c/default.aspx

You can also use GDI+ to do this, which would be way simpler.

mfc >> picture box

by susi » Tue, 16 Sep 2003 14:37:45 GMT

hi,
i actually want to display the image in picture box and
does not wants its scope to be destroyed.i want to do this
only in vc++6 and does not want to do with any third party
tools.how can i do it?
thanks a lot to Ajay kalra for a very great support given
to this group.
thanks in advance
susi.

mfc >> picture box

by Ajay Kalra » Tue, 16 Sep 2003 15:02:27 GMT

The MSDN link I mentioned would work for you. It shows how to put picture in
a static control(A picture box is a static control). In the example shown,
IDC_IMAGE is a static control on a dialog.

As far as GDI+ is concerned, it is not a 3rd party library. Microsoft ships
it and it works with VC6 as well.

mfc >> picture box

by Ed » Wed, 19 Apr 2006 08:07:09 GMT

I am using VC++6.0 and I draw a picture box with the dimensions of 450 X 320
When I check the dimensions using cr.Width() and cr.Height() I get a
dimension of 675 X 520
Why is this?
Below is my code.

char ed[10];
CBrush wht(RGB(255,255,255));
CRect cr;

GetDlgItem(IDC_PIC1)->GetClientRect(cr);
CWnd* pWnd=GetDlgItem(IDC_PIC1);
pControlDC=pWnd->GetDC();
pControlDC->SelectObject(wht); // select White for
background color
pControlDC->Rectangle(0,0,cr.Width(), cr.Height()); // fill background
color
_itoa(cr.Width(), ed, 10);
AfxMessageBox(ed);
_itoa(cr.Height(), ed, 10);
AfxMessageBox(ed);

This does fill the picture box in white for my background color which is
what I need.
But the size isnt what I set it to.

mfc >> picture box

by Scott McPhillips [MVP] » Wed, 19 Apr 2006 08:34:27 GMT


Where did you set the size to 450 x 320? I'll guess that is the size
you set in the dialog editor. If so, you don't understand that the
dialog editor and Windows work in "dialog units,", not pixels. But
GetClientRect returns units of pixels. Dialogs are automatically
resized by Windows on different machines, depending on screen resolution
and the user-selected default font size. Check out what happens if you
change your system font (DPI) in Control Panel, Display, Advanced.

Usually you should do what your're doing, which is to measure sizes in
the code.

--
Scott McPhillips [VC++ MVP]

Similar Threads

1. Move the picture inside a picture box

Hello,

I have an Image Box in the asp.net page, which contains an Image. Is there 
anyway I can move that image with the mouse in any direction inside the 
picture box??
If anything is unclear, please let me know.

Any help would be greatly appreciated!

Regards
Steven 


2. Newebie: How do I change a Picture Box on a Visual C++ / CLR managed form into a picture box array?

3. WebCam Highest resolution in a picture Box

Hello,


I wrote a program in C# that displays a webcam capture in a picture
box. I used windows API for this task. The program works well but the
picture of the webcam capture in my program is not as clear as that of
the webcam viewer.

I need to have a very good resolution from my webcam. I bought the
webcam that I think it has the clearest view and the highest
resolution (Logitech QuickCam Pro 9000). I thought the first time that
the problem is in my webcam device, but after a long search I realized
that the problem is in my C# program..

Here is a summary of the program that I wrote. Please tell me which
part of the program has to be changed in order to have a better view
of my webcam.


public class WebCamCapture
    {

        [DllImport("user32.dll", EntryPoint = "SendMessageA")]
        public static extern bool SendMessage(
            int hWnd,      // handle to destination window
            int Msg,       // message
            int wParam,  // first message parameter
            CAPSTATUS lParam   // second message parameter
            );

        [DllImport("user32.dll", EntryPoint = "SendMessageA")]
        public static extern bool SendMessage(
            int hWnd,      // handle to destination window
            int Msg,       // message
            bool wParam,  // first message parameter
            int lParam   // second message parameter
            );

        [DllImport("user32.dll", EntryPoint = "SendMessageA")]
        public static extern bool SendMessage(
            int hWnd,      // handle to destination window
            int Msg,       // message
            int wParam,  // first message parameter
            int lParam   // second message parameter
            );

        [DllImport("user32.dll")]
        public static extern int SetWindowPos(
            int hWnd,
            int hWndInsertAfter,
            int x,
            int y,
            int cx,
            int cy,
            int wFlags
            );

        [DllImport("user32.dll")]
        public static extern bool SetWindowPos(int hndw);


        public struct POINTAPI
        {
            int x;
            int y;
        }

        [DllImport("user32.dll")]
        public static extern bool DestroyWindow(int hWnd);

        public struct CAPSTATUS
        {
            public int uiImageWidth;                    // Width of
the image
            public int uiImageHeight;                  // Height of
the image
            int fLiveWindow;                    // Now Previewing
video?
            int fOverlayWindow;                  // Now Overlaying
video?
            int fScale;                       // Scale image to
client?
            POINTAPI ptScroll;                   // Scroll position
            int fUsingDefaultPalette;          // Using default driver
palette?
            int fAudioHardware;                 // Audio hardware
present?
            int fCapFileExists;                 // Does capture file
exist?
            int dwCurrentVideoFrame;             // # of video frames
cap'td
            int dwCurrentVideoFramesDropped;    // # of video frames
dropped
            int dwCurrentWaveSamples;            // # of wave samples
cap'td
            int dwCurrentTimeElapsedMS;          // Elapsed capture
duration
            int hPalCurrent;                     // Current palette in
use
            int fCapturingNow;                  // Capture in
progress?
            int dwReturn;                    // Error value after any
operation
            int wNumVideoAllocated;              // Actual number of
video buffers
            int wNumAudioAllocated;             // Actual number of
audio buffers
        }


        [DllImport("avicap32.dll")]
        public static extern int capCreateCaptureWindowA(
            string lpszWindowName,
            int dwStyle,
            int x,
            int y,
            int nWidth,
            short nHeight,
            int hWndParent,
            int nID
            );

        [DllImport("avicap32.dll")]
        public static extern bool capGetDriverDescriptionA(
            short wDriver,
            string lpszName,
            int cbName,
            string lpszVer,
            int cbVer
            );

        [DllImport("kernel32.Dll")]
        public static extern int DeleteFile(string lpPathName);

    }


And here the program that displays my webcam capture in a picture box.


bReturn = WebCamCapture.capGetDriverDescriptionA(x, strName, 100,
strVer, 100);
OpenPreviewWindow();
 WebCamCapture.CAPSTATUS s = new WebCamCapture.CAPSTATUS();
bReturn = WebCamCapture.SendMessage(hHwnd, WM_CAP_GET_STATUS,
Marshal.SizeOf(s), s);
Debug.WriteLine(String.Format("Video Size {0} x {1}", s.uiImageWidth,
s.uiImageHeight));



private void OpenPreviewWindow()
        {
            int iHeight = this.pictureBox.Height;
            int iWidth = this. pictureBox.Width;

      // Open Preview window in picturebox
hHwnd = WebCamCapture.capCreateCaptureWindowA(iDevice.ToString(),
WS_VISIBLE | WS_CHILD, 0, 0, 1280, 1024, this.
pictureBox.Handle.ToInt32(), 0);

     // Connect to device
if (WebCamCapture.SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice,
0))
{
 // Set the preview scale
 WebCamCapture.SendMessage(hHwnd, WM_CAP_SET_SCALE, true, 0);

//Set the preview rate in milliseconds
WebCamCapture.SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);

//Start previewing the image from the camera
WebCamCapture.SendMessage(hHwnd, WM_CAP_SET_PREVIEW, true, 0);

// Resize window to fit in picturebox
WebCamCapture.SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, this.
pictureBox.Width, this. pictureBox.Height, SWP_NOMOVE | SWP_NOZORDER);
}
else
{
// Error connecting to device close window
hHwnd = 0;
}
}

4. Compact Framework 2.0, transparent label over picture box - CSharp/C#

5. Dimensions of an image in the picture box

How can I retrieve the dimentions of the image that's been loaded into a 
picture box?

Thanks

6. 1 Context Menu for mutiple Picture Boxes - CSharp/C#

7. create ActiveX control with a picture box

Hi ,
  Can anybody give me some information on how to create an activeX Control 
in C# with a Picturebox.
         Thank you,
           Supriya
 


8. Scrolling picture box - CSharp/C#