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: 21 años, 10 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(hwndNULLTRUE);
         break;
case 
WM_PAINT:
         
hdc BeginPainthwnd, &ps );  //obtiene el contexto de dispositivo de la ventana donde queremos dibujar
         
BitBlthdcxCenteryCenterbm.bmWidthbm.bmHeightmemDC00SRCCOPY );
         
EndPainthwnd, &ps );
         if (
memDCDeleteObject(memDC);
         break;
case 
WM_COMMAND:
         switch(
LOWORD(wParam)) {
            case 
IDM_OPEN:
               
memset(&fname0sizeof(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(NULLfnIMAGE_BITMAP00LR_LOADFROMFILE);
               
GetObject(hBitmapsizeof(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(memDChBitmap);

               
InvalidateRect(hwndNULLFALSE);
               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: 21 años, 10 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(hwndhBitmap);
         }
         break;
      case 
WM_PAINT:
         
hdc BeginPaint(hwnd, &ps);  //obtiene el contexto de dispositivo de la ventana donde queremos dibujar
         
BitBlt(hdcxCenteryCenterbm.bmWidthbm.bmHeightmemDC00SRCCOPY);
         
EndPaint(hwnd, &ps);
         break;
......

void RepintarImagen(HWND hwndHBITMAP hBitmap){
   
HDC tempDC;

   if (
memDC) {
      
SelectObject(memDCmemBitmapOld);
      
DeleteObject(memBitmap);
      
DeleteObject(memDC);
   }

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

   
memBitmapOld SelectObject(memDC,hBitmap);

   
StretchBlt(memDC0,0anchoaltotempDC00bm.bmWidth,bm.bmHeight,SRCCOPY);
   
InvalidateRect(hwnd, &coordsTRUE);

   
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 17:49.