Click here to Skip to main content
15,887,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to load bitmap correctly?

it's my button, i'm typing file name in edit control, reading it:
C#
case button:
    {
        buffer.resize(GetWindowTextLength(GetDlgItem(hWnd,text_edit))+1);

        GetWindowText(GetDlgItem(hWnd,text_edit),&buffer[0],buffer.size()+1);

        for(int i=0;i<buffer.size();i++)
            img_name+=buffer[i];

        WndProc(hWnd,WM_PAINT,NULL,NULL);

    }
    break;


then trying to load bmp file(263*289) and draw it, but it doesn't work

C#
case WM_PAINT:
		{

			hdc = BeginPaint(hWnd, &ps);

			HDC tdc =CreateCompatibleDC(hdc);

						
HBITMAP bitmap=(HBITMAP)LoadImage(NULL,img_name,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);


			HBITMAP old = (HBITMAP) SelectObject(tdc,bitmap);

			BitBlt(hdc,0,0,263,289,tdc,0,0,SRCCOPY);

			SelectObject(tdc,old);

			DeleteObject(bitmap);

			DeleteDC(tdc);

			EndPaint(hWnd, &ps);

		}
		break;
Posted

1 solution

You did not explain your problem, saying "it doesn't work" is not much help. So anything I write here is guesswork.

I'm not sure what the following lines are supposed to do
C++
for(int i=0;i<buffer.size();i++)>
    img_name+=buffer[i];

are you sure they produced the desired result?

This is wrong:
C++
WndProc(hWnd,WM_PAINT,NULL,NULL);

if you wish to signal an update to the window's content you should call InvalidateRect[^].
 
Share this answer
 
Comments
positivcheg 18-Dec-11 11:37am    
thanks, problem was in this code path:
WndProc(hWnd,WM_PAINT,NULL,NULL);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900