Functions.DIBCreateFromPTR 方法 |
命名空间: VOGUIClasses
1METHOD Start() CLASS App 2LOCAL oWin AS MyWindow 3LOCAL hf AS PTR 4LOCAL nSize AS INT 5LOCAL pDib AS PTR 6 7WCSetCoordinateSystem(WCWindowsCoordinates) 8InitializeCAPaint() 9 10hf := FOpen("test.jpg") 11 12IF hf != F_ERROR 13 nSize := FSeek(hf, 0, FS_END) 14 FSeek(hf, 0, FS_SET) 15 pDib := MemAlloc(nSize) 16 17 IF FRead3(hf, pDib, nSize) == nSize 18 oWin := MyWindow{ SELF, pDib, nSize } 19 oWin:Show(SHOWCENTERED) 20 ENDIF 21 22 FClose(hf) 23 SELF:Exec() 24 oWin:Axit() 25 MemFree(pDib) 26ENDIF 27 28CLASS MyWindow INHERIT TopAppWindow 29 PROTECT pBitMap AS PTR 30 PROTECT lBitMap AS LOGIC 31 32 CONSTRUCTOR(oParent, xFile, nSize) 33 LOCAL pBmiH AS _WINBITMAPINFO 34 LOCAL nHeight AS INT 35 LOCAL nWidth AS INT 36 LOCAL oPOint AS POINT 37 LOCAL hWnd AS PTR 38 LOCAL cx AS INT 39 LOCAL cy AS INT 40 LOCAL cr IS _WINRECT 41 LOCAL wr IS _WINRECT 42 43 SUPER:Init(oParent) 44 SELF:QuitOnClose := TRUE 45 46 IF IsPtr(xFile) .AND. IsNumeric(nSize) 47 SELF:pBitMap := DIBCreateFromPtr(xFile, nSize) 48 ENDIF 49 50 IF pBitMap = NULL_PTR 51 MessageBox(0, "Error reading image", "ERROR ", MB_ICONSTOP) 52 ELSE 53 SELF:lBitmap := .T. 54 oPoint := SELF:Origin 55 pBmiH := DIBGetInfo(pBitMap) 56 nHeight := pBmiH.bmiHeader.biHeight 57 nWidth := pBmiH.bmiHeader.biWidth 58 hWnd := SELF:Handle() 59 GetWindowRect(hWnd, @wr) 60 GetClientRect(hWnd, @cr) 61 cx := wr.right - wr.left - cr.right 62 cy := wr.bottom - wr.top - cr.bottom 63 SELF:Size := DIMension{nWidth + cx, nHeight + cy} 64 SELF:Origin := oPoint 65 ENDIF 66 67 RETURN SELF 68 69 METHOD Expose(oExposeEvent) 70 SUPER:Expose(oExposeEvent) 71 72 IF SELF:lBitMap 73 DIBShow( SELF:pBitMap, NULL_PTR ) 74 ENDIF 75 76 DESTRUCTOR() CLASS MyWindow 77 DIBDelete(SELF:pBitmap) 78END CLASS