(或类似的东西,在Windows新闻组中询问) lpPal ^ .palVersion:= 300; lpPal-> palVersion = 0x300; lpPal ^ .palNumEntries:= GetSystemPaletteEntries(dc, 0,256,lpPal ^ .palPalEntry); lpPal-> palNumEntries = GetSystemPaletteEntries(dc,0,256, lpPal-> palPalEntry); if(lpPal ^ .PalNumEntries< 0)然后开始 if(lpPal-> PalNumEntries!= 0) { bm.Palette:= CreatePalette(lpPal ^); bm.Palette = CreatePalette(lpPal); end; } FreeMem(lpPal,sizeof(TLOGPALETTE)+ (255 * sizeof(TPALETTEENTRY))); GlobalFree(lpPal); end; } BitBlt(bm.Canvas.Handle,0,0,Width,Height,Dc , x,y,SRCCOPY); BitBlt(bm.Canvas.Handle,0,0,Width,Height,dc,x,y,SRCCOPY); ReleaseDc(0,dc); ReleaseDC(dc,0); end; } 我相信它第一次不能工作,你需要调整它。 我收费 Hi! I''m a programmer in Delphi (and not good in English).But a friend asked me for a proceure in C++for a part of then Screen. In Delphi is the proceure: show button.I''m seraching for the aequivalent in C++. THx Joachim - - - - Procedure in Delphi - - -function ScreenShot(x, y ,Width, Height: integer; bm: TBitMap):boolean;vardc: HDC;lpPal : PLOGPALETTE;begin{H?he und Breite testen}result := false;if ((Width <= 0) OR(Height <= 0)) then beginresult := true;exit;end;bm.Width := Width;bm.Height := Height;{ScreenDC holen}dc := GetDc(0);if (dc = 0) then beginresult := true;exit;end;if (GetDeviceCaps(dc, RASTERCAPS) ANDRC_PALETTE = RC_PALETTE) then beginGetMem(lpPal, sizeof(TLOGPALETTE) +(255 * sizeof(TPALETTEENTRY)));FillChar(lpPal^, sizeof(TLOGPALETTE) +(255 * sizeof(TPALETTEENTRY)), #0);lpPal^.palVersion := $300;lpPal^.palNumEntries :=GetSystemPaletteEntries(dc,0, 256, lpPal^.palPalEntry);if (lpPal^.PalNumEntries <0) then beginbm.Palette := CreatePalette(lpPal^);end;FreeMem(lpPal, sizeof(TLOGPALETTE) +(255 * sizeof(TPALETTEENTRY)));end;BitBlt(bm.Canvas.Handle, 0, 0, Width, Height, Dc,x, y, SRCCOPY);ReleaseDc(0, dc);end;--Joachim Mohr Tübingen http://www.joachimmohr.de/neu.html 解决方案 300;lpPal^.palNumEntries :=GetSystemPaletteEntries(dc,0, 256, lpPal^.palPalEntry);if (lpPal^.PalNumEntries <0) then beginbm.Palette := CreatePalette(lpPal^);end;FreeMem(lpPal, sizeof(TLOGPALETTE) +(255 * sizeof(TPALETTEENTRY)));end;BitBlt(bm.Canvas.Handle, 0, 0, Width, Height, Dc,x, y, SRCCOPY);ReleaseDc(0, dc);end;--Joachim Mohr Tübingen http://www.joachimmohr.de/neu.htmlJoachim Mohr wrote:I''m a programmer in Delphi (and not good in English).But a friend asked me for a proceure in C++for a part of then Screen.In Delphi is the proceure: show button.I''m seraching for the aequivalent in C++.THx Joachim- - - - Procedure in Delphi - - -function ScreenShot(x, y ,Width, Height: integer; bm:TBitMap):boolean; varbool ScreenShot(int x, int y, int Width, int Height,TBitMap& bm) { dc: HDC; lpPal : PLOGPALETTE;begin {H?he und Breite testen}// H?he und Breite testen result := false;bool result = false; if ((Width <= 0) ORif (Width <= 0 or (Height <= 0)) then beginHeight <= 0) { result := true; exit;return true; end;} bm.Width := Width; bm.Height := Height;bm.Width = Width;bm.Height = Height; {ScreenDC holen}// ScreenDC holen dc := GetDc(0);HDC dc = GetDC(0); if (dc = 0) then beginif (dc == 0) { result := true; exit;return true; end;} if (GetDeviceCaps(dc, RASTERCAPS) ANDif (GetDeviceCaps(dc, RASTERCAPS) and RC_PALETTE = RC_PALETTE) then beginRC_PALETTE == RC_PALETTE) { // WHAT??? A==A? GetMem(lpPal, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY))); FillChar(lpPal^, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)), #0);lpPal = GlobalAlloc(sizeof(TLOGPALETTE) + 255 *sizeof(TPALETTEENTRY), GMEM); (or something like that, ask in a Windows newsgroup) lpPal^.palVersion :=300;lpPal->palVersion = 0x300; lpPal^.palNumEntries :=GetSystemPaletteEntries(dc, 0, 256, lpPal^.palPalEntry);lpPal->palNumEntries = GetSystemPaletteEntries(dc, 0, 256,lpPal->palPalEntry); if (lpPal^.PalNumEntries <0) then beginif (lpPal->PalNumEntries != 0) { bm.Palette := CreatePalette(lpPal^);bm.Palette = CreatePalette(lpPal); end;} FreeMem(lpPal, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)));GlobalFree(lpPal); end;} BitBlt(bm.Canvas.Handle, 0, 0, Width, Height, Dc, x, y, SRCCOPY);BitBlt(bm.Canvas.Handle, 0, 0, Width, Height, dc, x, y, SRCCOPY); ReleaseDc(0, dc);ReleaseDC(dc, 0); end;} I am sure it won''t work the first time, you''ll need to tweak it.I charge 这篇关于截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 15:59