HBITMAP StretchBitmap  (HBITMAP hBitmap1 )  
{  
  BITMAP bm1 , bm2  ;  
  HBITMAP hBitmap2  ;  
  HDC  hdc , hdcMem1, hdcMem2 ;  
  int cxChar, cyChar ;  
   
  // Get the width and height of a system font character  
   
  cxChar  =  LOWORD  (GetDialogBaseUnits  ()) ;  
  cyChar  =  HIWORD  (GetDialogBaseUnits  ()) ;  
   
  // Create 2 memory DCs compatible with the display  
  hdc  =  CreateIC  (TEXT ("DISPLAY"),  NULL, NULL, NULL) ;  
  hdcMem1 =  CreateCompatibleDC  (hdc ) ;  
  hdcMem2 =  CreateCompatibleDC  (hdc ) ;  
  DeleteDC  (hdc ) ;  
   
  // Get the dimensions of the bitmap to be stretched  
  GetObject (hBitmap1 , sizeof (BITMAP), ( PTSTR ) & bm1 ) ;  
  // Scale these dimensions based on the system font size  
  bm2  =  bm1  ;  
  bm2 .bmWidth = (cxChar  *  bm2 .bmWidth) / 4 ;  
  bm2 .bmHeight  = (cyChar  *  bm2 .bmHeight ) / 8 ;  
  bm2 .bmWidthBytes = (( bm2 .bmWidth + 15) / 16) * 2 ;  
   
  // Create a new bitmap of larger size   
   
  hBitmap2  =  CreateBitmapIndirect  (& bm2 ) ;  
  // Select the bitmaps in the memory DCs and do a StretchBlt  
  SelectObject (hdcMem1, hBitmap1 ) ;  
  SelectObject (hdcMem2, hBitmap2 ) ;  
  StretchBlt  (hdcMem2, 0, 0,  bm2 .bmWidth, bm2 .bmHeight ,  
    hdcMem1, 0, 0,  bm1 .bmWidth, bm1 .bmHeight , SRCCOPY) ;  
  // Clean up  
  DeleteDC  (hdcMem1) ;  
  DeleteDC  (hdcMem2) ;  
  DeleteObject (hBitmap1 ) ;  
   
  return hBitmap2  ;  
} 在windows程序设计位图那部分看到这段代码,请问
bm2 .bmWidth = (cxChar  *  bm2 .bmWidth) / 4 ;  
bm2 .bmHeight  = (cyChar  *  bm2 .bmHeight ) / 8 ;
这两句转换是什么意思?

解决方案 »

  1.   

    其目的是:
    当我们需要缩放字体以适应不同显示分辨率或纵横比时,内存设备内容也能解决问题。在GRAFMENU程序中,
    我建立了四个位图,这些位图只适用于系统字体高8图素、宽4图素的显示。对于其它尺寸的系统字体,
    只能缩放位图。GRAFMENU中的StretchBitmap函数完成此功能。这是《windows程序设计》位图 部分的原话。
      

  2.   

    不太明白书上原话的意思。
    除以4和除以8指的是字体的大小,那么前面的cxChar和cyChar呢?希望指点一下