Window Redraw

I wrote a program which gets an image from the clipboard and draw's it inside the program window.But my problem is that the window itself is not redrawing.I'm using the WM_DRAW message
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
PAINTSTRUCT ps;
		hdc = BeginPaint(hWnd, &ps);
		if(!hdc){
			MessageBox(NULL,TEXT("Error painting!"),TEXT("Error"),MB_OK);
			break;
		}
		hdcMem = CreateCompatibleDC( hdc );
		if(!hdcMem){
			MessageBox(NULL,TEXT("Error creating compatible DC!"),TEXT("Error"),MB_OK);
			break;
		}
		if(!OpenClipboard(NULL)){
			MessageBox(NULL,TEXT("Unable to access clipborad!"),TEXT("Error"),MB_OK);
			break;
		}
		hndl = GetClipboardData(CF_BITMAP);
		CloseClipboard();
		if(!hndl){
			MessageBox(NULL,TEXT("Unable to read from clipboard!"),TEXT("Error"),MB_OK);
			TCHAR str[255];
			_stprintf(str, _T("Error code:%d"), GetLastError());
			MessageBox(0, str, TEXT("ERROR CODE!"), MB_OK);
			//MessageBox(NULL,(LPCTSTR)GetLastError(),TEXT("Error code!"),MB_OK);
			break;
		}
		cbmp = (HBITMAP)hndl;
		if(!cbmp){
			MessageBox(NULL,TEXT("Unable to read image from the clipboard!"),TEXT("Error"),MB_OK);
			break;
		}
		SelectObject(hdcMem,cbmp);
		GetObject(hndl,sizeof(bmp),&bmp);
		BitBlt(hdc,0,0,bmp.bmWidth,bmp.bmHeight,hdcMem,0,0,SRCCOPY);
		DeleteDC(hdcMem);
		EndPaint(hWnd, &ps);
		break;

Tried using updatewindow and redrawwindow but nothing worked :(
Last edited on
#define RePaintWidow(a,b) InvalidateRect(a,NULL,b);

Then call RePaintWindow (a, b)

a = the window handle to clear
b = a bool to clear the screen (true), or not (false)

try that.
WM_DRAW message ??

The follwing worked for me.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
case WM_PAINT:
        {

        PAINTSTRUCT ps = {0};
       HDC hdc, hdcMem;
        
        HBITMAP cbmp, hOldBitmap;
        BITMAP bmp;
        HANDLE hndl;
        
        hdc = BeginPaint(hwnd, &ps );
        hdcMem = CreateCompatibleDC( hdc );
            
        OpenClipboard(hwnd);
        hndl = GetClipboardData(CF_BITMAP);

        cbmp = (HBITMAP)hndl;

        hOldBitmap = (HBITMAP) SelectObject(hdcMem,cbmp);
        GetObject(cbmp,sizeof(bmp),&bmp);
        BitBlt(hdc,0,0,bmp.bmWidth,bmp.bmHeight,hdcMem,0,0,SRCCOPY);
        
        SelectObject(hdcMem, hOldBitmap);
        DeleteDC(hdcMem);
        
        CloseClipboard();
        
        EndPaint(hwnd, &ps);

            return 1;
        }


EDIT: - Some notes
Changed my mind about adding notes - if you have any issues you can always ask
Last edited on
Topic archived. No new replies allowed.