JPG, GIF, BMP in ein PictureControl laden -> Bild erscheint erst nach Windowgößenveränderung.



  • Hi. Code:

    LRESULT CALLBACK PICTURE(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	hPicture = hWnd;
    	switch(message)
    	{
    		case WM_CREATE:
    		{
    			break;
    		}
    		case WM_LBUTTONDOWN:
    		{
    			OPENFILENAME ofn;
    			szPicFile[0] = '\0';
    			ofn.lStructSize       = sizeof(OPENFILENAME);
    			ofn.Flags             = OFN_LONGNAMES | OFN_FILEMUSTEXIST;
    			ofn.hInstance         = hInst;
    			ofn.hwndOwner         = hMainWnd;
    			ofn.lCustData         = NULL;
    			ofn.lpfnHook          = NULL;
    			ofn.lpstrCustomFilter = NULL;
    			ofn.lpstrDefExt		  = "hp2";
    			ofn.lpstrFile	      = szPicFile;
    			ofn.lpstrFileTitle	  = NULL;
    			ofn.lpstrFilter		  = "Unterstützte Bildvormate (*.jpg, *.jpeg, *.bmp, *.gif)\0*.jpg;*.jpeg;*.bmp;*.gif\0JPG (*.jpg, *.jpeg)\0*.jpg;*.jpeg\0Bitmap (*.bmp)\0*.bmp\0GIF (*.gif)\0*.gif\0Alle Dateien (*.*)\0*.*\0\0";
    			ofn.lpstrInitialDir   = NULL;
    			ofn.lpstrTitle        = "Bild auswählen";
    			ofn.lpTemplateName    = NULL;
    			ofn.nFileExtension    = NULL;
    			ofn.nFileOffset       = NULL;
    			ofn.nFilterIndex      = NULL;
    			ofn.nMaxCustFilter    = NULL;
    			ofn.nMaxFile          = MAX_PATH;
    			ofn.nMaxFileTitle     = NULL;
    			if(GetSaveFileName(&ofn) == IDOK)
    			{
    				COlePicture* pPicture = (COlePicture *)GetWindowLong(hWnd, GWL_USERDATA); 
    				if(pPicture != NULL) delete pPicture; 
    				COlePicture* pNewPicture = new COlePicture; 
    				pNewPicture->Load(szPicFile); 
    				SetWindowLong(hWnd, GWL_USERDATA, (LONG)pNewPicture); 
    			}
    			break;
    		}
    		case WM_PAINT: 
            { 
                PAINTSTRUCT ps; 
                HDC hDC = BeginPaint(hWnd, &ps); 
                COlePicture* pPicture = (COlePicture*)GetWindowLong(hWnd, GWL_USERDATA); 
                if(pPicture != NULL) pPicture->Show(hWnd, 0, 0);
                EndPaint(hWnd, &ps);
    			break;
            }
    		case WM_DESTROY: 
            { 
                COlePicture* pPicture = (COlePicture *)GetWindowLong(hWnd, GWL_USERDATA); 
                if(pPicture != NULL) delete pPicture; 
    			break;
            } 
    		default: 
    			return DefWindowProc(hWnd, message, wParam, lParam); 
    		break;
    	}
        return 0;
    }
    

    Das ist nach dem Beispiel der WinAPI FAQ und ich kann damit JPG, BMP, GIF etc. anzeigen. Allerdings erscheint das eben geladene Bild erst, wenn ich mein Fenster etwas verkleinere etc., weil das PictureControl dann neu gezeichnet wird und das Bild dann erscheint. Wenn ich die Größe des Programms nach dem Bildladen nicht verändere, bleibt das PictureControl leer. Mit welcher Funktion sollte ich das PictureControl in WM_PAINT updaten??

    Danke
    Gruß!



  • InvalidateRect



  • Jau! Habs auch grad rausgefunden, Danke trotzdem!

    InvalidateRect(hWnd, NULL, true);
    

    Gruß!


Anmelden zum Antworten