{"id":431,"date":"2009-05-28T15:32:00","date_gmt":"2009-05-28T07:32:00","guid":{"rendered":""},"modified":"2013-11-17T17:33:41","modified_gmt":"2013-11-17T09:33:41","slug":"delphi%e4%b8%80%e4%b8%aa%e6%8a%93%e5%b1%8f%e7%9a%84%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/431.html","title":{"rendered":"Delphi\u4e00\u4e2a\u6293\u5c4f\u7684\u51fd\u6570"},"content":{"rendered":"<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nprocedure TMainFrm.ScreenShot(x : integer; y : integer; Width : integer; Height : integer; bm : TBitMap);\r\nvar\r\ndc: HDC; lpPal : PLOGPALETTE;\r\nbegin\r\n  \/\/ \u68c0\u6d4b\u6240\u9700\u6293\u5c4f\u7684\u533a\u57df\r\n  if ((Width = 0) or (Height = 0)) then exit;\r\n  bm.Width := Width;\r\n  bm.Height := Height;\r\n  \/\/\u83b7\u53d6\u8bbe\u5907\u4e0a\u4e0b\u6587\r\n  dc := GetDc(0);\r\n  if (dc = 0) then exit;\r\n  {do we have a palette device?}\r\n  if (GetDeviceCaps(dc, RASTERCAPS) AND\r\n    RC_PALETTE = RC_PALETTE) then\r\n    begin\r\n    {allocate memory for a logical palette}\r\n    GetMem(lpPal, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)));\r\n    {zero it out to be neat}\r\n    FillChar(lpPal^, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)), #0);\r\n    {fill in the palette version}\r\n    lpPal^.palVersion := $300;\r\n    {grab the system palette entries}\r\n    lpPal^.palNumEntries :=\r\n      GetSystemPaletteEntries(dc,0,256,lpPal^.palPalEntry);\r\n    if (lpPal^.PalNumEntries &lt;&gt; 0) then\r\n    begin\r\n      {create the palette}\r\n      bm.Palette := CreatePalette(lpPal^);\r\n    end;\r\n    FreeMem(lpPal, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)));\r\n    end;\r\n  {copy from the screen to the bitmap}\r\n  BitBlt(bm.Canvas.Handle,0,0,Width,Height,Dc,x,y,SRCCOPY);\r\n  {release the screen dc}\r\n  ReleaseDc(0, dc);\r\nend;\r\n\r\n\/\/\u8c03\u7528\u65b9\u6cd5\r\nprocedure TMainFrm.Button1Click(Sender: TObject);\r\nvar\r\n  tBM : TBitmap;\r\nbegin\r\n  try\r\n    tBM := TBitmap.Create;\r\n    ScreenShot(0,0,Screen.Width,Screen.height,tBM);\r\n    tBM.SaveToFile('c:\\ScreenShot.BMP');\r\n  finally\r\n    tBm.FreeImage;\r\n    FreeAndNil(tBM);\r\n  end;\r\nend;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>procedure TMainFrm.ScreenShot(x : integer; y : integer; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-431","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=431"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/431\/revisions"}],"predecessor-version":[{"id":4750,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/431\/revisions\/4750"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}