1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144:
| program BitmapToWindow;
{$APPTYPE GUI}
uses WinProcs,System.SysUtils;
var FMem:Pointer; FH:THandle; FileLength: Int64; FR:LongInt; BMem:Pointer; WinX, WinY, WinWidth, WinHeight, PicWidth,PicHeight:Integer;
HWnd1:HWND; WCls1:WndClassEx; WinDC:HDC; PS:TPaintStruct; WinBP:HDC; PB:Boolean;
BmpH:HBitmap; CDC: HDC; SelO:HGDIObj; BmpT:TBitmapInfo; Procedure WinOpen; Var WCN,WT:PChar; WReg:Integer; WH1:HWnd; dx,dy: Integer; Begin WCls1.cbSize:=sizeof(WCls1); WCls1.style:=CS_HREDRAW Or CS_VREDRAW; WCls1.lpfnWndProc:=Addr(DefWindowProc); WCls1.cbclsExtra:=0; WCls1.cbWndExtra:=0; WCls1.hInstance:=GetModuleHandle(nil);; WCls1.hIcon:=winprocs.LoadIcon(0, IDI_APPLICATION); WCls1.hCursor:=0; WCls1.hbrBackground:=(14 + 1); WCls1.lpszMenuName:=NiL; WCls1.lpszClassName:='My Window'#0; WCls1.hIconSm:=LoadIcon(WCls1.hInstance, IDI_APPLICATION);
WReg:=RegisterClassEx(WCls1);
WT:='My Program'#0; WCN:='My Window'#0;
dx := WinWidth + GetSystemMetrics(SM_CXFIXEDFRAME)*2; dy := WinHeight + GetSystemMetrics(SM_CYFIXEDFRAME)*2 + GetSystemMetrics(SM_CYCAPTION); WinX:=(1920-dx) Div 2; WinY:=(1080-dy) Div 2;
HWnd1:=CreateWindow(WCN,WT, WS_OVERLAPPED+WS_SIZEBOX, WinX,WinY,dx,dy, 0,0,GetModuleHandle(NiL),NiL);
ShowWindow(HWnd1,sw_show); UpdateWindow(HWnd1); End;
Procedure PaintOpen; Begin WinDC:=GetDC(HWnd1); PS.hdc:=WinDC; PS.ferase:=false; PS.rcpaint.left:=0; PS.rcpaint.top:=0; PS.rcpaint.right:=WinWidth; PS.rcpaint.bottom:=WinHeight; WinBP:=BeginPaint(HWnd1,PS); End;
Procedure PaintRect(RX,RY,RWidth,RHeight:Integer;R,G,B:Byte); Var R1:TRect;B1:HBrush; Begin R1.left:=RX; R1.right:=RX+RWidth; R1.top:=RY; R1.bottom:=RY+RHeight; B1:=CreateSolidBrush(((B*256)+G)*256+R); fillrect(WinDC,r1,b1); DeleteObject(B1); End;
Begin FH:=FileOpen('D:\Picture.bmp',fmOpenReadWrite); if FH = INVALID_HANDLE_VALUE then Exit; try FileLength := FileSeek(FH,0,2); FileSeek(FH,0,0); FMem:=GetMemory(FileLength); FR:=FileRead(FH,FMem^, FileLength); finally FileClose(FH); end;
Longint(BMem):=longint(FMem)+Longint(Pointer(longint(FMem)+10)^); PicWidth:=LongInt(Pointer(longint(FMem)+18)^); PicHeight:=LongInt(Pointer(longint(FMem)+22)^);
WinWidth:=PicWidth+30; WinHeight:=PicHeight+30; WinOpen; PaintOpen; PaintRect(0,0,WinWidth,WinHeight,0,200,0); PaintRect(10,10,PicWidth,PicHeight,200,0,0);
BmpT.bmiHeader.biSize:= SizeOf(BmpT.bmiHeader); BmpT.bmiHeader.biWidth:=PicWidth; BmpT.bmiHeader.biHeight:=PicHeight; BmpT.bmiHeader.biPlanes:=1; BmpT.bmiHeader.biBitCount:=24;
CDC:=CreateCompatibleDC(WinDC); try BmpH := CreateCompatibleBitmap(WinDC, BmpT.bmiHeader.biWidth, BmpT.bmiHeader.biHeight); if BmpH = 0 then Exit; try SelO:=SelectObject(CDC,BmpH); try if SetDIBits(CDC, BmpH, 0, BmpT.bmiHeader.biHeight, BMem, BmpT, DIB_RGB_COLORS ) <= 0 Then Exit;
PB:=BitBlT(WinDC,10,10,PicWidth,PicHeight,CDC,00,00,SRCCopy); finally SelectObject(CDC,SelO); end; finally DeleteObject(BmpH); end; finally DeleteObject(CDC); end;
Repeat Until GetAsyncKeyState(32)=-32768; end. |