Foros del Web » Programación para mayores de 30 ;) » Programación General »

Error al redimensionar ventana WinAPI

Estas en el tema de Error al redimensionar ventana WinAPI en el foro de Programación General en Foros del Web. Hola, el objetivo es que quiero que se cargue una imagen y siempre quede en medio de la ventana, la imagen la carga bien pero ...
  #1 (permalink)  
Antiguo 10/06/2008, 05:47
 
Fecha de Ingreso: junio-2002
Ubicación: España
Mensajes: 348
Antigüedad: 24 años, 4 meses
Puntos: 8
Error al redimensionar ventana WinAPI

Hola, el objetivo es que quiero que se cargue una imagen y siempre quede en medio de la ventana, la imagen la carga bien pero al cambiar el tamaño de la ventana desaparece la imagen, ¿me podeis decir cual es el error? Os pongo la parte de código que corresponde:
Código PHP:
case WM_SIZE:
         
GetClientRect(hwnd, &coords); // obtenemos las coordenadas de la ventana
         
xCenter = ((coords.right - coords.left)/2) - (bm.bmWidth/2);
         
yCenter = ((coords.bottom - coords.top)/2) - (bm.bmHeight/2);

         
InvalidateRect(hwnd, NULL, TRUE);
         break;
case 
WM_PAINT:
         
hdc = BeginPaint( hwnd, &ps );  //obtiene el contexto de dispositivo de la ventana donde queremos dibujar
         
BitBlt( hdc, xCenter, yCenter, bm.bmWidth, bm.bmHeight, memDC, 0, 0, SRCCOPY );
         
EndPaint( hwnd, &ps );
         if (
memDC) DeleteObject(memDC);
         break;
case 
WM_COMMAND:
         switch(
LOWORD(wParam)) {
            case 
IDM_OPEN:
               
memset(&fname, 0, sizeof(OPENFILENAME));
               
fname.lStructSize = sizeof(OPENFILENAME);
               
fname.hwndOwner = hwnd;
               
fname.lpstrFilter = ("Bitmap Files (*.bmp)\0*.bmp\0\0");
               
fname.nFilterIndex = 1;
               
fname.lpstrFile = fn;
               
fname.nMaxFile = sizeof(fn);
               
fname.lpstrFileTitle = filename;
               
fname.nMaxFileTitle = sizeof(filename)-1;
               
fname.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;

               if(!
GetOpenFileName(&fname))
                  break;

               
hBitmap = LoadImage(NULL, fn, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
               
GetObject(hBitmap, sizeof(BITMAP), &bm);

               
xCenter = ((coords.right - coords.left)/2) - (bm.bmWidth/2);
               
yCenter = ((coords.bottom - coords.top)/2) - (bm.bmHeight/2);

               
hdc = GetDC(hwnd);
               
memDC = CreateCompatibleDC(hdc);
               
SelectObject(memDC, hBitmap);

               
InvalidateRect(hwnd, NULL, FALSE);
               break; 
Gracias
__________________
Bicis nuevas y de segunda mano: Bicibid
  #2 (permalink)  
Antiguo 11/06/2008, 07:37
 
Fecha de Ingreso: junio-2002
Ubicación: España
Mensajes: 348
Antigüedad: 24 años, 4 meses
Puntos: 8
Respuesta: Error al redimensionar ventana WinAPI

Arreglado, lo dejo por si a alguien le hace falta:

Código PHP:
 case WM_SIZE:
         
GetClientRect(hwnd, &coords); // obtenemos las coordenadas de la ventana
         
xCenter = ((coords.right - coords.left)/2) - (bm.bmWidth/2);
         
yCenter = ((coords.bottom - coords.top)/2) - (bm.bmHeight/2);
         if(
hBitmap){
            
RepintarImagen(hwnd, hBitmap);
         }
         break;
      case 
WM_PAINT:
         
hdc = BeginPaint(hwnd, &ps);  //obtiene el contexto de dispositivo de la ventana donde queremos dibujar
         
BitBlt(hdc, xCenter, yCenter, bm.bmWidth, bm.bmHeight, memDC, 0, 0, SRCCOPY);
         
EndPaint(hwnd, &ps);
         break;
......

void RepintarImagen(HWND hwnd, HBITMAP hBitmap){
   
HDC tempDC;

   if (
memDC) {
      
SelectObject(memDC, memBitmapOld);
      
DeleteObject(memBitmap);
      
DeleteObject(memDC);
   }

   
tempDC = GetDC(hwnd);
   
memDC = CreateCompatibleDC(tempDC);

   
memBitmapOld = SelectObject(memDC,hBitmap);

   
StretchBlt(memDC, 0,0, ancho, alto, tempDC, 0, 0, bm.bmWidth,bm.bmHeight,SRCCOPY);
   
InvalidateRect(hwnd, &coords, TRUE);

   
ReleaseDC(hwnd,tempDC);

} 
__________________
Bicis nuevas y de segunda mano: Bicibid
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:52.