BaseForm.pas 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. unit BaseForm;
  2. interface
  3. uses
  4. Windows,
  5. Messages,
  6. SysUtils,
  7. Variants,
  8. Classes,
  9. Graphics,
  10. Controls,
  11. Forms,
  12. Dialogs,
  13. StdCtrls,
  14. XMLDoc,
  15. XMLIntf,
  16. ExtCtrls,
  17. RealICQColors,
  18. RealICQUIColor,
  19. StrUtils;
  20. const
  21. SkinPath: String = 'Skins';
  22. SkinConfigXMLFile: String = 'SkinConfig.XML';
  23. type
  24. TOSVersion =(osWinNT351, osWin95, osWinNT40, osWin98, osWinMe, osWin2000, osWinXP, osWin2003, osOther);
  25. TBaseForm = class(TForm, IRealICQUIColor)
  26. private
  27. FSkinName: String;
  28. FCanDraw: Boolean;
  29. FCustomCaption: String;
  30. BmpIcon,
  31. BmpLeft,
  32. BmpCaption,
  33. BmpRight,
  34. BmpBottom,
  35. BmpMin,
  36. BmpRestore,
  37. BmpMax,
  38. BmpClose,
  39. BufBmpTop,
  40. BufBmpLeft,
  41. BufBmpRight,
  42. BufBmpBottom,
  43. BmpLeftRGN,
  44. BmpCaptionRGN,
  45. BmpRightRGN,
  46. BmpBottomRGN: TBitMap;
  47. CaptionActiveColor,
  48. CaptionDeActiveColor,
  49. TextColor,
  50. FFormColor,
  51. TransparentColor: TColor;
  52. CaptionFont: String;
  53. CaptionFontSize: Integer;
  54. LeftCaptionWidth,
  55. RightCaptionWidth,
  56. LeftBottomWidth,
  57. RightBottomWidth: Integer;
  58. IconLeft,
  59. IconTop,
  60. CaptionTextLeft,
  61. CaptionTop,
  62. LeftBorderWidth,
  63. CaptionHeight,
  64. RightBorderWidth,
  65. BottomHeight,
  66. MinButtonWidth,
  67. MinButtonHeight,
  68. MaxAndRestoreButtonWidth,
  69. MaxAndRestoreButtonHeight,
  70. CloseButtonWidth,
  71. CloseButtonHeight: Integer;
  72. CloseBtnTop,
  73. CloseBtnRight,
  74. MaxAndRestoreBtnTop,
  75. MaxAndRestoreBtnRight,
  76. MinBtnTop,
  77. MinBtnRight: Integer;
  78. AllowDeactivateSkin,
  79. AllowChangeSkinColor,
  80. AllowChangeFormColor,
  81. FSettedDragFullWindows,
  82. FLastIsActived: Boolean;
  83. BaseImgNumber, {从第几个图像开始画(用于绘制边框)}
  84. BaseImgButtomNumber: Integer; {从第几个按钮开始画(用于绘制按钮)}
  85. SystemMenuRect,
  86. TitleBarRect,
  87. MinBtnRect,
  88. MaxBtnRect,
  89. CloseBtnRect: TRect;
  90. MinBtnHover,
  91. MaxBtnHover,
  92. CloseBtnHover: Boolean;
  93. FCanResizeWindow: Boolean;
  94. FCanMoveWindow: Boolean;
  95. FCanFullWindow: Boolean;
  96. FRevokeMaxButton:Boolean;
  97. FMinButtonForClose: Boolean;
  98. FShowCloseButton:Boolean;
  99. FTimerForReDrawNormalButton: TTimer;
  100. procedure FTimerForReDrawNormalButtonTimer(Sender: TObject);
  101. procedure MakeBufferBMP;
  102. procedure SetRegion;
  103. procedure SetSkinName(Value: String);
  104. procedure SetCustomCaption(Value: String);
  105. procedure LoadSkinConfigs;
  106. procedure SetCanResizeWindow(Value: Boolean);
  107. function GetOSVersion: TOSVersion;
  108. procedure DrawWindow(DC: HDC);
  109. protected
  110. procedure CreateParams(var Params: TCreateParams); override;
  111. procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
  112. procedure WndProc(var Message: TMessage); override;
  113. procedure WMNCHitTest(var msg: TWMNCHITTEST); message WM_NCHITTEST;
  114. procedure WMNCMouseMove(var msg: TWMNCMousemove); message WM_NCMOUSEMOVE;
  115. procedure WMNCLButtonDown(var msg: TWMNCLButtonDown); message WM_NCLBUTTONDOWN;
  116. procedure WMNCLButtonUp(var msg: TWMNCLButtonUp); message WM_NCLBUTTONUP;
  117. procedure AdjustClientRect(var Rect: TRect); override;
  118. public
  119. constructor Create(AOwner: TComponent); override;
  120. destructor Destroy; override;
  121. procedure ChangeUIColor(AColor: TColor); virtual;
  122. property CaptionBaseTop: Integer read CaptionTop;
  123. property SkinName: String read FSkinName write SetSkinName;
  124. property OSVersion: TOSVersion read GetOSVersion;
  125. property FormColor: TColor read FFormColor;
  126. property RevokeMaxButton: Boolean read FRevokeMaxButton write FRevokeMaxButton;
  127. property CanResizeWindow: Boolean read FCanResizeWindow write SetCanResizeWindow;
  128. property CanMoveWindow: Boolean read FCanMoveWindow write FCanMoveWindow;
  129. property CanFullWindow: Boolean read FCanFullWindow write FCanFullWindow;
  130. property MinButtonForClose: Boolean read FMinButtonForClose write FMinButtonForClose;
  131. property ShowCloseButton:Boolean read FShowCloseButton write FShowCloseButton;
  132. published
  133. property CustomCaption: String read FCustomCaption write SetCustomCaption;
  134. end;
  135. implementation
  136. var
  137. FOSVersion: TOSVersion;
  138. FDragFullWindows,
  139. FGettedDragFullWindows: Boolean;
  140. //------------------------------------------------------------------------------
  141. procedure GetDragFullWindows;
  142. begin
  143. if FGettedDragFullWindows then Exit;
  144. SystemParametersInfo(SPI_GETDRAGFULLWINDOWS , 0, @FDragFullWindows , 0);
  145. end;
  146. //------------------------------------------------------------------------------
  147. function TBaseForm.GetOSVersion: TOSVersion;
  148. begin
  149. Result := FOSVersion;
  150. end;
  151. //------------------------------------------------------------------------------
  152. procedure TBaseForm.ChangeUIColor(AColor: TColor);
  153. begin
  154. if AllowChangeFormColor then
  155. begin
  156. FFormColor := ConvertColorToColor(FormColor, AColor);
  157. Color := FFormColor;
  158. end;
  159. if AllowChangeSkinColor and FCanDraw then
  160. begin
  161. ConvertBitmapToColor(BmpLeft, AColor);
  162. ConvertBitmapToColor(BmpCaption, AColor);
  163. ConvertBitmapToColor(BmpRight, AColor);
  164. ConvertBitmapToColor(BmpBottom, AColor);
  165. ConvertBitmapToColor(BmpClose, AColor);
  166. ConvertBitmapToColor(BmpMin, AColor);
  167. ConvertBitmapToColor(BmpMax, AColor);
  168. ConvertBitmapToColor(BmpRestore, AColor);
  169. MakeBufferBMP;
  170. DrawWindow(Canvas.Handle);
  171. end;
  172. end;
  173. //------------------------------------------------------------------------------
  174. procedure TBaseForm.AdjustClientRect(var Rect: TRect);
  175. begin
  176. inherited AdjustClientRect(Rect);
  177. Rect.Left := LeftBorderWidth;
  178. Rect.Top := CaptionHeight;
  179. Rect.Right := ClientWidth - RightBorderWidth;
  180. Rect.Bottom := ClientHeight - BottomHeight;
  181. end;
  182. //------------------------------------------------------------------------------
  183. procedure TBaseForm.SetCanResizeWindow(Value: Boolean);
  184. begin
  185. FCanResizeWindow := Value;
  186. PostMessage(Handle, WM_SIZE, 0, 0);
  187. end;
  188. //------------------------------------------------------------------------------
  189. procedure TBaseForm.SetRegion;
  190. var
  191. Region1,
  192. Region2 :HRGN;
  193. BaseLeft,
  194. BaseTop: Integer;
  195. TempBmp: TBitmap;
  196. begin
  197. if not FCanDraw then Exit;
  198. //将窗体限制在窗体的工作区之内(即ClientWidth,ClientHeight之内)
  199. //窗体的非工作区(边框)将会被排除在外(不被Windows处理)
  200. BaseLeft := (Width - ClientWidth) div 2;
  201. BaseTop := (Height - ClientHeight) div 2;
  202. Region1 := GetRegionFromBitmap(BaseLeft + 0,
  203. BaseTop + 0,
  204. BmpLeftRGN,
  205. TransparentColor);
  206. if LeftCaptionWidth > 0 then
  207. begin
  208. TempBmp := TBitmap.Create;
  209. TempBmp.Assign(BmpCaptionRGN);
  210. TempBmp.SetSize(LeftCaptionWidth, TempBmp.Height);
  211. Region2 := GetRegionFromBitmap(BaseLeft + LeftBorderWidth,
  212. BaseTop + 0,
  213. TempBmp,
  214. TransparentColor);
  215. CombineRgn(Region1, Region1, Region2, RGN_OR);
  216. DeleteObject(Region2);
  217. TempBmp.Free;
  218. end;
  219. Region2 := CreateRectRgn(BaseLeft + LeftBorderWidth + LeftCaptionWidth,
  220. BaseTop + CaptionTop + 0,
  221. BaseLeft + (ClientWidth - RightBorderWidth - RightCaptionWidth),
  222. BaseTop + CaptionHeight);
  223. CombineRgn(Region1, Region1, Region2, RGN_OR);
  224. DeleteObject(Region2);
  225. if RightCaptionWidth > 0 then
  226. begin
  227. Region2 := GetRegionFromBitmap(BaseLeft + (ClientWidth - RightBorderWidth - BmpCaption.Width),
  228. BaseTop + 0,
  229. BmpCaptionRGN,
  230. TransparentColor);
  231. CombineRgn(Region1, Region1, Region2, RGN_OR);
  232. DeleteObject(Region2);
  233. end;
  234. Region2 := GetRegionFromBitmap(BaseLeft + (ClientWidth - RightBorderWidth),
  235. BaseTop + 0,
  236. BmpRightRGN,
  237. TransparentColor);
  238. CombineRgn(Region1, Region1, Region2, RGN_OR);
  239. DeleteObject(Region2);
  240. Region2 := CreateRectRgn(BaseLeft + 0,
  241. BaseTop + CaptionHeight,
  242. BaseLeft + LeftBorderWidth,
  243. BaseTop + (ClientHeight - BottomHeight));
  244. CombineRgn(Region1, Region1, Region2, RGN_OR);
  245. DeleteObject(Region2);
  246. Region2 := GetRegionFromBitmap(BaseLeft + 0,
  247. BaseTop + (ClientHeight - BmpLeft.Height),
  248. BmpLeftRGN,
  249. TransparentColor);
  250. CombineRgn(Region1, Region1, Region2, RGN_OR);
  251. DeleteObject(Region2);
  252. Region2 := CreateRectRgn(BaseLeft + (ClientWidth - RightBorderWidth),
  253. BaseTop + CaptionHeight,
  254. BaseLeft + ClientWidth,
  255. BaseTop + (ClientHeight - BottomHeight));
  256. CombineRgn(Region1, Region1, Region2, RGN_OR);
  257. DeleteObject(Region2);
  258. Region2 := GetRegionFromBitmap(BaseLeft + (ClientWidth - RightBorderWidth),
  259. BaseTop + (ClientHeight - BmpRight.Height),
  260. BmpRightRGN,
  261. TransparentColor);
  262. CombineRgn(Region1, Region1, Region2, RGN_OR);
  263. DeleteObject(Region2);
  264. if LeftBottomWidth > 0 then
  265. begin
  266. Region2 := GetRegionFromBitmap(BaseLeft + LeftBorderWidth,
  267. BaseTop + (ClientHeight - BottomHeight),
  268. BmpBottomRGN,
  269. TransparentColor);
  270. CombineRgn(Region1, Region1, Region2, RGN_OR);
  271. DeleteObject(Region2);
  272. end;
  273. if RightBottomWidth > 0 then
  274. begin
  275. Region2 := GetRegionFromBitmap(BaseLeft + (ClientWidth - RightBorderWidth - BmpBottom.Width),
  276. BaseTop + (ClientHeight - BottomHeight),
  277. BmpBottomRGN,
  278. TransparentColor);
  279. CombineRgn(Region1, Region1, Region2, RGN_OR);
  280. DeleteObject(Region2);
  281. end;
  282. Region2 := CreateRectRgn(BaseLeft + LeftBorderWidth + LeftBottomWidth,
  283. BaseTop + (ClientHeight - BottomHeight),
  284. BaseLeft + (ClientWidth - RightBorderWidth - RightBottomWidth),
  285. BaseTop + ClientHeight);
  286. CombineRgn(Region1, Region1, Region2, RGN_OR);
  287. DeleteObject(Region2);
  288. Region2 := CreateRectRgn(BaseLeft + LeftBorderWidth,
  289. BaseTop + CaptionHeight,
  290. BaseLeft + (ClientWidth - RightBorderWidth),
  291. BaseTop + (ClientHeight - BottomHeight));
  292. CombineRgn(Region1, Region1, Region2, RGN_OR);
  293. DeleteObject(Region2);
  294. SetWindowRgn(Handle, Region1, True);
  295. DeleteObject(Region1);
  296. if FCanFullWindow then
  297. begin
  298. Constraints.MaxHeight := Screen.Height + BaseTop * 2;
  299. Constraints.MaxWidth := Screen.Width + BaseLeft * 2;
  300. end
  301. else
  302. begin
  303. Constraints.MaxHeight := Screen.WorkAreaHeight + BaseTop * 2;
  304. Constraints.MaxWidth := Screen.WorkAreaWidth + BaseLeft * 2;
  305. end;
  306. end;
  307. //------------------------------------------------------------------------------
  308. procedure TBaseForm.MakeBufferBMP;
  309. var
  310. CVSCaption: TCanvas;
  311. ICO: HICON;
  312. CaptionWidth: Integer;
  313. CaptionStr: WideString;
  314. MaxAndRestoreHandle: THandle;
  315. CaptionRect: TRect;
  316. begin
  317. if not FCanDraw then Exit;
  318. if Active or not AllowDeactivateSkin then
  319. begin
  320. BaseImgNumber := 0;
  321. BaseImgButtomNumber := 0;
  322. end
  323. else
  324. begin
  325. BaseImgNumber := 1;
  326. BaseImgButtomNumber := 3;
  327. end;
  328. BufBmpTop.Width := ClientWidth;
  329. BufBmpTop.Height := CaptionHeight;
  330. //画左上角
  331. BitBlt(BufBmpTop.Canvas.Handle, 0, 0, LeftBorderWidth, CaptionHeight, BmpLeft.Canvas.Handle, BaseImgNumber * LeftBorderWidth , 0, SRCCOPY);
  332. if LeftCaptionWidth >0 then BitBlt(BufBmpTop.Canvas.Handle, LeftBorderWidth, 0, LeftCaptionWidth, CaptionHeight, BmpCaption.Canvas.Handle, 0, BaseImgNumber * CaptionHeight, SRCCOPY);
  333. //画标题栏
  334. StretchBlt(BufBmpTop.Canvas.Handle, LeftBorderWidth + LeftCaptionWidth, 0, (ClientWidth - RightBorderWidth - LeftBorderWidth - LeftCaptionWidth - RightCaptionWidth), CaptionHeight, BmpCaption.Canvas.Handle, LeftCaptionWidth, BaseImgNumber * CaptionHeight, BmpCaption.Width - LeftCaptionWidth - RightCaptionWidth, CaptionHeight, SRCCOPY);
  335. //画右上角
  336. BitBlt(BufBmpTop.Canvas.Handle, (ClientWidth - RightBorderWidth), 0, RightBorderWidth, CaptionHeight, BmpRight.Canvas.Handle, BaseImgNumber * rightBorderWidth, 0, SRCCOPY);
  337. if RightCaptionWidth >0 then BitBlt(BufBmpTop.Canvas.Handle, (ClientWidth - RightBorderWidth - RightCaptionWidth), 0, RightCaptionWidth, CaptionHeight, BmpCaption.Canvas.Handle, BmpCaption.Width - RightCaptionWidth, BaseImgNumber * CaptionHeight, SRCCOPY);
  338. if (Icon <> nil) and (Icon.Handle > 0) then
  339. begin
  340. ICO := Icon.Handle; //画图标
  341. if ICO > 0 then DrawIconEx(BufBmpTop.Canvas.Handle, LeftBorderWidth + 2, (CaptionHeight - 16) div 2, ICO, 16, 16, 0, 0, DI_NORMAL);
  342. end
  343. else
  344. begin
  345. BmpIcon.Transparent := True;
  346. BmpIcon.TransparentColor := TransparentColor;
  347. BmpIcon.TransparentMode := tmFixed;
  348. BufBmpTop.Transparent := True;
  349. BufBmpTop.TransparentColor := TransparentColor;
  350. BufBmpTop.TransparentMode := tmFixed;
  351. BufBmpTop.Canvas.Brush.Style := bsClear;
  352. BufBmpTop.Canvas.BrushCopy(Rect(IconLeft, IconTop, IconLeft + BmpIcon.Width, IconTop + BmpIcon.Height),
  353. BmpIcon,
  354. Rect(0, 0, BmpIcon.Width, BmpIcon.Height),
  355. TransparentColor);
  356. SystemMenuRect.Left := IconLeft;
  357. SystemMenuRect.Top := IconTop;
  358. SystemMenuRect.Right := BmpIcon.Width;
  359. SystemMenuRect.Bottom := BmpIcon.Height;
  360. end;
  361. //标题文字
  362. CVSCaption := TCanvas.Create;
  363. try
  364. CVSCaption.Brush.Style := bsClear;
  365. CVSCaption.Handle := BufBmpTop.Canvas.Handle;
  366. //CVSCaption.Font.Name := captionFont;
  367. CVSCaption.Font := self.Font;
  368. //CVSCaption.Font.Style := [fsbold];
  369. CVSCaption.Font.Size := captionFontSize;
  370. if Active then
  371. CVSCaption.Font.Color := captionActiveColor
  372. else
  373. CVSCaption.Font.Color := captionDeActiveColor;
  374. CaptionRect.Left := CaptionTextLeft;
  375. CaptionRect.Top := (CaptionHeight - CaptionFontSize) div 2 - 1 + (CaptionTop div 2);
  376. CaptionRect.Right := CaptionRect.Left + CVSCaption.TextWidth(Caption);
  377. CaptionRect.Bottom := CaptionRect.Top + CVSCaption.TextHeight(Caption);
  378. CaptionWidth := (ClientWidth - MinBtnRight - MinButtonWidth - 2) - CaptionRect.Left;
  379. if Length(Trim(FCustomCaption)) = 0 then
  380. CaptionStr := Caption
  381. else
  382. CaptionStr := FCustomCaption;
  383. while CVSCaption.TextWidth(CaptionStr) > CaptionWidth do
  384. begin
  385. if Length(CaptionStr) > 3 then
  386. begin
  387. if Copy(CaptionStr, Length(CaptionStr) - 2, Length(CaptionStr)) = '...' then
  388. CaptionStr := Copy(CaptionStr, 1, Length(CaptionStr) - 3);
  389. CaptionStr := Copy(CaptionStr, 1, Length(CaptionStr) - 1) + '...';
  390. end
  391. else
  392. begin
  393. CaptionStr := Copy(CaptionStr, 1, Length(CaptionStr) - 1);
  394. end;
  395. end;
  396. DrawText(CVSCaption.Handle, PChar(AnsiString(CaptionStr)), Length(AnsiString(CaptionStr)), CaptionRect, DT_LEFT);
  397. finally
  398. CVSCaption.Free;
  399. end;
  400. TitleBarRect.Left := LeftBorderWidth;
  401. TitleBarRect.Top := 4 + CaptionTop;
  402. TitleBarRect.Right := ClientWidth - RightBorderWidth;
  403. TitleBarRect.Bottom := CaptionHeight;
  404. //关闭按钮
  405. if self.FShowCloseButton then
  406. begin
  407. CloseBtnRect.Left := ClientWidth - CloseBtnRight - CloseButtonWidth;
  408. CloseBtnRect.Top := CloseBtnTop;
  409. CloseBtnRect.Right := CloseBtnRect.Left + CloseButtonWidth;
  410. CloseBtnRect.Bottom := CloseBtnRect.Top + CloseButtonHeight;
  411. BitBlt(BufBmpTop.Canvas.Handle, CloseBtnRect.Left, CloseBtnRect.Top, CloseButtonWidth, CloseButtonHeight , BmpClose.Canvas.Handle, BaseImgButtomNumber * CloseButtonWidth, 0, SRCCOPY);
  412. end;
  413. if FCanResizeWindow then
  414. begin
  415. //最大化或还原按钮
  416. if FRevokeMaxButton then
  417. MinBtnRect.Left := ClientWidth - MinBtnRight-MinButtonWidth+MaxAndRestoreButtonWidth
  418. else
  419. begin
  420. MaxBtnRect.Left := ClientWidth - MaxAndRestoreBtnRight - MaxAndRestoreButtonWidth;
  421. MaxBtnRect.Top := MaxAndRestoreBtnTop;
  422. MaxBtnRect.Right := MaxBtnRect.Left + MaxAndRestoreButtonWidth;
  423. MaxBtnRect.Bottom := MaxBtnRect.Top + MaxAndRestoreButtonHeight;
  424. MaxAndRestoreHandle := BmpMax.Canvas.Handle;
  425. if WindowState = wsMaximized then MaxAndRestoreHandle := BmpRestore.Canvas.Handle;
  426. BitBlt(BufBmpTop.Canvas.Handle, MaxBtnRect.Left, MaxBtnRect.Top, MaxAndRestoreButtonWidth, MaxAndRestoreButtonHeight , MaxAndRestoreHandle, BaseImgButtomNumber * MaxAndRestoreButtonWidth, 0, SRCCOPY);
  427. MinBtnRect.Left := ClientWidth - MinBtnRight-MinButtonWidth;
  428. end;
  429. //最小化按钮
  430. MinBtnRect.Top := MinBtnTop;
  431. MinBtnRect.Right := MinBtnRect.Left + MinButtonWidth;
  432. MinBtnRect.Bottom := MinBtnRect.Top + MinButtonHeight;
  433. BitBlt(BufBmpTop.Canvas.Handle, MinBtnRect.Left, MinBtnRect.Top, MinButtonWidth, MinButtonHeight , BmpMin.Canvas.Handle, BaseImgButtomNumber * MinButtonWidth, 0, SRCCOPY);
  434. end;
  435. BufBmpLeft.Width := LeftBorderWidth;
  436. BufBmpLeft.Height := ClientHeight - CaptionHeight;
  437. //画左边
  438. StretchBlt(BufBmpLeft.Canvas.Handle, 0, 0, LeftBorderWidth, BufBmpLeft.Height, BmpLeft.Canvas.Handle, BaseImgNumber * LeftBorderWidth, CaptionHeight, LeftBorderWidth, 1, SRCCOPY);
  439. //画左下角
  440. BitBlt(BufBmpLeft.Canvas.Handle, 0, (BufBmpLeft.Height - BottomHeight), LeftBorderWidth, BottomHeight, BmpLeft.Canvas.Handle, BaseImgNumber * LeftBorderWidth, BmpLeft.Height - bottomHeight, SRCCOPY);
  441. BufBmpRight.Width := RightBorderWidth;
  442. BufBmpRight.Height := ClientHeight - CaptionHeight;
  443. //画右边
  444. StretchBlt(BufBmpRight.Canvas.Handle, 0, 0, RightBorderWidth, (BufBmpRight.Height - BottomHeight), BmpRight.Canvas.Handle, BaseImgNumber * RightBorderWidth, CaptionHeight, RightBorderWidth, 1, SRCCOPY);
  445. //画右下角
  446. BitBlt(BufBmpRight.Canvas.Handle, 0, (BufBmpRight.Height - BottomHeight), RightBorderWidth, BottomHeight, BmpRight.Canvas.Handle, BaseImgNumber * RightBorderWidth, BmpRight.Height - BottomHeight, SRCCOPY);
  447. BufBmpBottom.Width := ClientWidth - LeftBorderWidth - RightBorderWidth;
  448. BufBmpBottom.Height := BottomHeight;
  449. //画下边
  450. if LeftBottomWidth > 0 then BitBlt(BufBmpBottom.Canvas.Handle, 0, 0, LeftBottomWidth, BottomHeight, BmpBottom.Canvas.Handle, 0, BaseImgNumber * CaptionHeight, SRCCOPY);
  451. StretchBlt(BufBmpBottom.Canvas.Handle, LeftBottomWidth, 0, BufBmpBottom.Width - LeftBottomWidth - RightBottomWidth, BottomHeight , BmpBottom.Canvas.Handle, LeftBottomWidth, BaseImgNumber * BottomHeight, 1, BottomHeight, SRCCOPY);
  452. if RightBottomWidth > 0 then BitBlt(BufBmpBottom.Canvas.Handle, BufBmpBottom.Width - RightBottomWidth, 0, RightBottomWidth, BottomHeight, BmpBottom.Canvas.Handle, BmpBottom.Width - RightBottomWidth, BaseImgNumber * CaptionHeight, SRCCOPY);
  453. end;
  454. //------------------------------------------------------------------------------
  455. procedure TBaseForm.DrawWindow(DC: HDC);
  456. begin
  457. if not FCanDraw then Exit;
  458. SetStretchBltMode(Canvas.Handle, STRETCH_DELETESCANS);
  459. BitBlt(DC, 0, 0, ClientWidth, CaptionHeight, BufBmpTop.Canvas.Handle, 0 , 0, SRCCOPY);
  460. BitBlt(DC, 0, CaptionHeight, LeftBorderWidth, ClientHeight - BottomHeight, BufBmpLeft.Canvas.Handle, 0 , 0, SRCCOPY);
  461. BitBlt(DC, ClientWidth - RightBorderWidth, CaptionHeight, ClientWidth, ClientHeight, BufBmpRight.Canvas.Handle, 0 , 0, SRCCOPY);
  462. BitBlt(DC, LeftBorderWidth, ClientHeight - BottomHeight, ClientWidth - RightBorderWidth, ClientHeight, BufBmpBottom.Canvas.Handle, 0 , 0, SRCCOPY);
  463. MinBtnHover := False;
  464. MaxBtnHover := False;
  465. CloseBtnHover := False;
  466. end;
  467. //------------------------------------------------------------------------------
  468. procedure TBaseForm.WMNCHitTest(var msg: TWMNCHITTEST);
  469. var
  470. P: TPoint;
  471. begin
  472. DefaultHandler(msg);
  473. if not FCanDraw then
  474. begin
  475. Exit;
  476. end;
  477. P.X := ScreenToClient(Mouse.CursorPos).X;
  478. P.Y := ScreenToClient(Mouse.CursorPos).Y;
  479. if PtInRect(SystemMenuRect, P) then
  480. begin
  481. msg.Result := HTCAPTION;
  482. Cursor := crDefault;
  483. end
  484. else if PtInRect(MinBtnRect, P) and FCanResizeWindow then
  485. begin
  486. msg.Result := HTMINBUTTON;
  487. Cursor := crDefault;
  488. end
  489. else if PtInRect(MaxBtnRect, P) and FCanResizeWindow and not FRevokeMaxButton then
  490. begin
  491. msg.Result := HTMAXBUTTON;
  492. Cursor := crDefault;
  493. end
  494. else if PtInRect(CloseBtnRect, P) and FShowCloseButton then
  495. begin
  496. msg.Result := HTCLOSE;
  497. Cursor := crDefault;
  498. end
  499. else if PtInRect(TitleBarRect, P) and CanMoveWindow then
  500. begin
  501. msg.Result := HTCAPTION;
  502. Cursor := crDefault;
  503. end
  504. else if ((P.X < LeftBorderWidth + 6) and (P.Y < 20) or
  505. (P.X < LeftBorderWidth + 20) and (P.Y < 4)) and FCanResizeWindow then
  506. begin
  507. msg.Result := HTTOPLEFT;
  508. end
  509. else if ((P.X > ClientWidth - RightBorderWidth - 6) and (P.Y < 20) or
  510. (P.X > ClientWidth - RightBorderWidth - 20) and (P.Y < 4)) and FCanResizeWindow then
  511. begin
  512. msg.Result := HTTOPRIGHT;
  513. end
  514. else if ((P.X < LeftBorderWidth) and (P.Y > ClientHeight - 20) or
  515. (P.X < LeftBorderWidth + 20) and (P.Y > ClientHeight - BottomHeight)) and FCanResizeWindow then
  516. begin
  517. msg.Result := HTBOTTOMLEFT;
  518. end
  519. else if ((P.X > ClientWidth - RightBorderWidth - 6) and (P.Y > ClientHeight - 20) or
  520. (P.X > ClientWidth - RightBorderWidth - 20) and (P.Y > ClientHeight - BottomHeight)) and FCanResizeWindow then
  521. begin
  522. msg.Result := HTBOTTOMRIGHT;
  523. end
  524. else if (P.X < LeftBorderWidth) and FCanResizeWindow then
  525. begin
  526. msg.Result := HTLEFT;
  527. end
  528. else if (P.X > ClientWidth - RightBorderWidth - 8) and FCanResizeWindow then
  529. begin
  530. msg.Result := HTRIGHT;
  531. end
  532. else if (P.Y < 4 + CaptionTop) and FCanResizeWindow then
  533. begin
  534. msg.Result := HTTOP;
  535. end
  536. else if (P.Y > ClientHeight - BottomHeight) and FCanResizeWindow then
  537. begin
  538. msg.Result := HTBOTTOM;
  539. end
  540. else
  541. begin
  542. //DefaultHandler(msg);
  543. end;
  544. end;
  545. //------------------------------------------------------------------------------
  546. procedure TBaseForm.FTimerForReDrawNormalButtonTimer(Sender: TObject);
  547. var
  548. P: TPoint;
  549. MaxAndRestoreHandle :THandle;
  550. begin
  551. if not FCanDraw then Exit;
  552. P.X := ScreenToClient(Mouse.CursorPos).X;
  553. P.Y := ScreenToClient(Mouse.CursorPos).Y;
  554. if not PtInRect(MinBtnRect, P) then
  555. begin
  556. if MinBtnHover then
  557. begin
  558. BitBlt(Canvas.Handle,
  559. MinBtnRect.Left,
  560. MinBtnRect.Top,
  561. MinBtnRect.Right - MinBtnRect.Left,
  562. MinBtnRect.Bottom - MinBtnRect.Top,
  563. BmpMin.Canvas.Handle,
  564. (BaseImgButtomNumber) * MinButtonWidth,
  565. 0,
  566. SRCCOPY);
  567. MinBtnHover := False;
  568. FTimerForReDrawNormalButton.Enabled := False;
  569. end;
  570. end;
  571. if not PtInRect(MaxBtnRect, P) then
  572. begin
  573. if MaxBtnHover then
  574. begin
  575. MaxAndRestoreHandle := BmpMax.Canvas.Handle;
  576. if WindowState = wsMaximized then MaxAndRestoreHandle := BmpRestore.Canvas.Handle;
  577. BitBlt(Canvas.Handle,
  578. MaxBtnRect.Left,
  579. MaxBtnRect.Top,
  580. MaxBtnRect.Right - MaxBtnRect.Left,
  581. MaxBtnRect.Bottom - MaxBtnRect.Top ,
  582. MaxAndRestoreHandle,
  583. (BaseImgButtomNumber) * MaxAndRestoreButtonWidth,
  584. 0,
  585. SRCCOPY);
  586. MaxBtnHover := False;
  587. FTimerForReDrawNormalButton.Enabled := False;
  588. end;
  589. end;
  590. if not PtInRect(CloseBtnRect, P) then
  591. begin
  592. if CloseBtnHover then
  593. begin
  594. BitBlt(Canvas.Handle,
  595. CloseBtnRect.Left,
  596. CloseBtnRect.Top,
  597. CloseBtnRect.Right - CloseBtnRect.Left,
  598. CloseBtnRect.Bottom - CloseBtnRect.Top ,
  599. BmpClose.Canvas.Handle,
  600. (BaseImgButtomNumber) * CloseButtonWidth,
  601. 0,
  602. SRCCOPY);
  603. CloseBtnHover := False;
  604. FTimerForReDrawNormalButton.Enabled := False;
  605. end;
  606. end;
  607. end;
  608. //------------------------------------------------------------------------------
  609. procedure TBaseForm.WMNCMouseMove(var msg: TWMNCMousemove);
  610. var
  611. MaxAndRestoreHandle: THandle;
  612. begin
  613. DefaultHandler(msg);
  614. if not FCanDraw then
  615. begin
  616. //DefaultHandler(msg);
  617. Exit;
  618. end;
  619. if msg.HitTest = HTMINBUTTON then
  620. begin
  621. if not MinBtnHover then
  622. begin
  623. BitBlt(Canvas.Handle,
  624. MinBtnRect.Left,
  625. MinBtnRect.Top,
  626. MinBtnRect.Right - MinBtnRect.Left,
  627. MinBtnRect.Bottom - MinBtnRect.Top,
  628. BmpMin.Canvas.Handle,
  629. (BaseImgButtomNumber + 2) * MinButtonWidth,
  630. 0,
  631. SRCCOPY);
  632. MinBtnHover := True;
  633. FTimerForReDrawNormalButton.Enabled := True;
  634. end;
  635. end
  636. else
  637. begin
  638. if MinBtnHover then
  639. begin
  640. BitBlt(Canvas.Handle,
  641. MinBtnRect.Left,
  642. MinBtnRect.Top,
  643. MinBtnRect.Right - MinBtnRect.Left,
  644. MinBtnRect.Bottom - MinBtnRect.Top,
  645. BmpMin.Canvas.Handle,
  646. (BaseImgButtomNumber) * MinButtonWidth,
  647. 0,
  648. SRCCOPY);
  649. MinBtnHover := False;
  650. FTimerForReDrawNormalButton.Enabled := False;
  651. end;
  652. end;
  653. if msg.HitTest = HTMAXBUTTON then
  654. begin
  655. if not MaxBtnHover then
  656. begin
  657. MaxAndRestoreHandle := BmpMax.Canvas.Handle;
  658. if WindowState = wsMaximized then MaxAndRestoreHandle := BmpRestore.Canvas.Handle;
  659. BitBlt(Canvas.Handle,
  660. MaxBtnRect.Left,
  661. MaxBtnRect.Top,
  662. MaxBtnRect.Right - MaxBtnRect.Left,
  663. MaxBtnRect.Bottom - MaxBtnRect.Top ,
  664. MaxAndRestoreHandle,
  665. (BaseImgButtomNumber + 2) * MaxAndRestoreButtonWidth,
  666. 0,
  667. SRCCOPY);
  668. MaxBtnHover := True;
  669. FTimerForReDrawNormalButton.Enabled := True;
  670. end;
  671. end
  672. else
  673. begin
  674. if MaxBtnHover then
  675. begin
  676. MaxAndRestoreHandle := BmpMax.Canvas.Handle;
  677. if WindowState = wsMaximized then MaxAndRestoreHandle := BmpRestore.Canvas.Handle;
  678. BitBlt(Canvas.Handle,
  679. MaxBtnRect.Left,
  680. MaxBtnRect.Top,
  681. MaxBtnRect.Right - MaxBtnRect.Left,
  682. MaxBtnRect.Bottom - MaxBtnRect.Top ,
  683. MaxAndRestoreHandle,
  684. (BaseImgButtomNumber) * MaxAndRestoreButtonWidth,
  685. 0,
  686. SRCCOPY);
  687. MaxBtnHover := False;
  688. FTimerForReDrawNormalButton.Enabled := False;
  689. end;
  690. end;
  691. if msg.HitTest = HTCLOSE then
  692. begin
  693. if not CloseBtnHover then
  694. begin
  695. BitBlt(Canvas.Handle,
  696. CloseBtnRect.Left,
  697. CloseBtnRect.Top,
  698. CloseBtnRect.Right - CloseBtnRect.Left,
  699. CloseBtnRect.Bottom - CloseBtnRect.Top ,
  700. BmpClose.Canvas.Handle,
  701. (BaseImgButtomNumber + 2) * CloseButtonWidth,
  702. 0,
  703. SRCCOPY);
  704. CloseBtnHover := True;
  705. FTimerForReDrawNormalButton.Enabled := True;
  706. end;
  707. end
  708. else
  709. begin
  710. if CloseBtnHover then
  711. begin
  712. BitBlt(Canvas.Handle,
  713. CloseBtnRect.Left,
  714. CloseBtnRect.Top,
  715. CloseBtnRect.Right - CloseBtnRect.Left,
  716. CloseBtnRect.Bottom - CloseBtnRect.Top ,
  717. BmpClose.Canvas.Handle,
  718. (BaseImgButtomNumber) * CloseButtonWidth,
  719. 0,
  720. SRCCOPY);
  721. CloseBtnHover := False;
  722. FTimerForReDrawNormalButton.Enabled := False;
  723. end;
  724. end;
  725. //DefaultHandler(msg);
  726. end;
  727. //------------------------------------------------------------------------------
  728. procedure TBaseForm.WMNCLButtonDown(var msg: TWMNCLButtonDown);
  729. var
  730. MaxAndRestoreHandle: THandle;
  731. begin
  732. if not FCanDraw then
  733. begin
  734. DefaultHandler(msg);
  735. Exit;
  736. end;
  737. if msg.HitTest = HTMINBUTTON then
  738. begin
  739. BitBlt(Canvas.Handle,
  740. MinBtnRect.Left,
  741. MinBtnRect.Top,
  742. MinBtnRect.Right - MinBtnRect.Left,
  743. MinBtnRect.Bottom - MinBtnRect.Top,
  744. BmpMin.Canvas.Handle,
  745. (BaseImgButtomNumber + 1) * MinButtonWidth,
  746. 0,
  747. SRCCOPY);
  748. end
  749. else if (msg.HitTest = HTMAXBUTTON) and (not FRevokeMaxButton) then
  750. begin
  751. MaxAndRestoreHandle := BmpMax.Canvas.Handle;
  752. if WindowState = wsMaximized then MaxAndRestoreHandle := BmpRestore.Canvas.Handle;
  753. BitBlt(Canvas.Handle,
  754. MaxBtnRect.Left,
  755. MaxBtnRect.Top,
  756. MaxBtnRect.Right - MaxBtnRect.Left,
  757. MaxBtnRect.Bottom - MaxBtnRect.Top ,
  758. MaxAndRestoreHandle,
  759. (BaseImgButtomNumber + 1) * MaxAndRestoreButtonWidth,
  760. 0,
  761. SRCCOPY);
  762. end
  763. else if msg.HitTest = HTCLOSE then
  764. begin
  765. BitBlt(Canvas.Handle,
  766. CloseBtnRect.Left,
  767. CloseBtnRect.Top,
  768. CloseBtnRect.Right - CloseBtnRect.Left,
  769. CloseBtnRect.Bottom - CloseBtnRect.Top ,
  770. BmpClose.Canvas.Handle,
  771. (BaseImgButtomNumber + 1) * CloseButtonWidth,
  772. 0,
  773. SRCCOPY);
  774. end
  775. else
  776. DefaultHandler(msg);
  777. end;
  778. //------------------------------------------------------------------------------
  779. procedure TBaseForm.WMNCLButtonUp(var msg: TWMNCLButtonUp);
  780. begin
  781. if not FCanDraw then
  782. begin
  783. DefaultHandler(msg);
  784. Exit;
  785. end;
  786. if msg.HitTest = HTMINBUTTON then
  787. begin
  788. if FMinButtonForClose then
  789. Close
  790. else
  791. WindowState := wsMinimized;
  792. end
  793. else if (msg.HitTest = HTMAXBUTTON) and (not FRevokeMaxButton) then
  794. begin
  795. if WindowState = wsMaximized then
  796. WindowState := wsNormal
  797. else if WindowState = wsNormal then
  798. WindowState := wsMaximized;
  799. end
  800. else if msg.HitTest = HTCLOSE then
  801. begin
  802. Close;
  803. end
  804. else
  805. DefaultHandler(msg);
  806. end;
  807. //------------------------------------------------------------------------------
  808. procedure TBaseForm.WndProc(var Message: TMessage);
  809. begin
  810. {
  811. if (message.msg = WM_NCPAINT) then
  812. begin
  813. Message.Result := 1;
  814. Exit;
  815. end;
  816. }
  817. inherited;
  818. if not FCanDraw then Exit;
  819. if (message.msg = WM_PRINTCLIENT) then
  820. begin
  821. PaintTo(HDC(Message.WParam), 0, 0);
  822. DrawWindow(HDC(Message.WParam));
  823. end;
  824. if (message.msg = WM_SIZE) or
  825. (message.msg = WM_WININICHANGE) or
  826. (message.msg = WM_DISPLAYCHANGE) then
  827. begin
  828. MakeBufferBMP;
  829. SetRegion;
  830. DrawWindow(Canvas.Handle);
  831. if message.msg = WM_WININICHANGE then
  832. begin
  833. FLastIsActived := False;
  834. FGettedDragFullWindows := False;
  835. GetDragFullWindows;
  836. end;
  837. end;
  838. if (message.msg = WM_PAINT) then
  839. begin
  840. DrawWindow(Canvas.Handle);
  841. //Message.Result := 1;
  842. end;
  843. if message.msg = WM_ACTIVATE then
  844. begin
  845. case message.WParamLo of
  846. WA_ACTIVE, WA_CLICKACTIVE:
  847. begin
  848. if (Integer(OSVersion) > Integer(osWinMe)) or (not FSettedDragFullWindows) then
  849. begin
  850. if not FLastIsActived then
  851. begin
  852. SystemParametersInfo(SPI_SETDRAGFULLWINDOWS , 0, nil , 0);
  853. FSettedDragFullWindows := True;
  854. FLastIsActived := True;
  855. end;
  856. end;
  857. end;
  858. WA_INACTIVE:
  859. begin
  860. if Integer(OSVersion) > Integer(osWinMe) then
  861. begin
  862. FLastIsActived := False;
  863. if FDragFullWindows then
  864. SystemParametersInfo(SPI_SETDRAGFULLWINDOWS , 1, nil , 0)
  865. else
  866. SystemParametersInfo(SPI_SETDRAGFULLWINDOWS , 0, nil , 0);
  867. end;
  868. end;
  869. end;
  870. end;
  871. end;
  872. //------------------------------------------------------------------------------
  873. procedure TBaseForm.SetCustomCaption(Value: String);
  874. begin
  875. FCustomCaption := Value;
  876. DisableAlign;
  877. try
  878. PostMessage(Handle, WM_SIZE, 0, 0);
  879. Height := Height - 1;
  880. Height := Height + 1;
  881. finally
  882. EnableAlign;
  883. end;
  884. end;
  885. //------------------------------------------------------------------------------
  886. procedure TBaseForm.SetSkinName(Value: String);
  887. begin
  888. FSkinName := Value;
  889. LoadSkinConfigs;
  890. DisableAlign;
  891. try
  892. PostMessage(Handle, WM_SIZE, 0, 0);
  893. Height := Height - 1;
  894. Height := Height + 1;
  895. finally
  896. EnableAlign;
  897. end;
  898. end;
  899. //------------------------------------------------------------------------------
  900. procedure TBaseForm.LoadSkinConfigs;
  901. var
  902. XMLFile: String;
  903. XMLDocument: TXMLDocument;
  904. TopNode,
  905. FilesNode,
  906. ColorsNode,
  907. FontsNode,
  908. OthersNode,
  909. PositionsNode: IXMLNode;
  910. begin
  911. XMLFile := ExtractFilePath(paramstr(0)) + SkinPath + '\' + SkinName + '\'+ SkinConfigXMLFile;
  912. if not FileExists(XMLFile) then raise Exception.Create('没有找到指定的界面配置文件');
  913. XMLDocument := TXMLDocument.Create(Self);
  914. try
  915. XMLDocument.Active := True;
  916. XMLDocument.LoadFromFile(XMLFile);
  917. TopNode := XMLDocument.DocumentElement;
  918. FilesNode := TopNode.ChildNodes[0];
  919. ColorsNode := TopNode.ChildNodes[1];
  920. FontsNode := TopNode.ChildNodes[2];
  921. OthersNode := TopNode.ChildNodes[3];
  922. PositionsNode := TopNode.ChildNodes[4];
  923. BmpIcon.LoadFromFile(ExtractFilePath(XMLFile) + FilesNode.ChildNodes.FindNode('BmpIcon').Text);
  924. BmpLeft.LoadFromFile(ExtractFilePath(XMLFile) + FilesNode.ChildNodes.FindNode('BmpLeft').Text);
  925. BmpCaption.LoadFromFile(ExtractFilePath(XMLFile) + FilesNode.ChildNodes.FindNode('BmpCaption').Text);
  926. BmpRight.LoadFromFile(ExtractFilePath(XMLFile) + FilesNode.ChildNodes.FindNode('BmpRight').Text);
  927. BmpBottom.LoadFromFile(ExtractFilePath(XMLFile) + FilesNode.ChildNodes.FindNode('BmpBottom').Text);
  928. BmpMin.LoadFromFile(ExtractFilePath(XMLFile) + FilesNode.ChildNodes.FindNode('BmpMin').Text);
  929. BmpRestore.LoadFromFile(ExtractFilePath(XMLFile) + FilesNode.ChildNodes.FindNode('BmpRestore').Text);
  930. BmpMax.LoadFromFile(ExtractFilePath(XMLFile) + FilesNode.ChildNodes.FindNode('BmpMax').Text);
  931. BmpClose.LoadFromFile(ExtractFilePath(XMLFile) + FilesNode.ChildNodes.FindNode('BmpClose').Text);
  932. BmpLeftRGN.Assign(BmpLeft);
  933. BmpLeftRGN.SetSize(BmpLeft.Width div 2, BmpLeft.Height);
  934. BmpCaptionRGN.Assign(BmpCaption);
  935. BmpCaptionRGN.SetSize(BmpCaption.Width, BmpCaption.Height div 2);
  936. BmpRightRGN.Assign(BmpRight);
  937. BmpRightRGN.SetSize(BmpRight.Width div 2, BmpRight.Height);
  938. BmpBottomRGN.Assign(BmpBottom);
  939. BmpBottomRGN.SetSize(BmpBottom.Width, BmpBottom.Height div 2);
  940. LeftBorderWidth := (BmpLeft.Width) div 2;
  941. CaptionHeight := (BmpCaption.Height) div 2;
  942. RightBorderWidth := (BmpRight.Width) div 2;
  943. BottomHeight := (BmpBottom.Height) div 2;
  944. MinButtonWidth := (BmpMin.Width) div 6;
  945. MinButtonHeight := BmpMin.Height;
  946. MaxAndRestoreButtonWidth := (BmpMax.Width) div 6;
  947. MaxAndRestoreButtonHeight := BmpMax.Height;
  948. CloseButtonWidth := (BmpClose.Width) div 6;
  949. CloseButtonHeight := BmpClose.Height;
  950. try
  951. CaptionActiveColor := StrToInt(ColorsNode.ChildNodes.FindNode('CaptionActiveColor').Text);
  952. except
  953. CaptionActiveColor := clCaptionText;
  954. end;
  955. try
  956. CaptionDeActiveColor := StrToInt(ColorsNode.ChildNodes.FindNode('CaptionDeActiveColor').Text);
  957. except
  958. CaptionDeActiveColor := clInactiveCaptionText;
  959. end;
  960. try
  961. TextColor := StrToInt(ColorsNode.ChildNodes.FindNode('TextColor').Text);
  962. except
  963. TextColor := clWindowText;
  964. end;
  965. Font.Color := TextColor;
  966. try
  967. FFormColor := StrToInt(ColorsNode.ChildNodes.FindNode('FormColor').Text);
  968. except
  969. FFormColor := clBtnFace;
  970. end;
  971. try
  972. TransparentColor := StrToInt(ColorsNode.ChildNodes.FindNode('TransparentColor').Text);
  973. except
  974. TransparentColor := $00FF00FF;
  975. end;
  976. CaptionFont := FontsNode.ChildNodes.FindNode('CaptionFont').Text;
  977. CaptionFontSize := StrToInt(FontsNode.ChildNodes.FindNode('CaptionFontSize').Text);
  978. IconLeft := StrToInt(OthersNode.ChildNodes.FindNode('ImageIconLeft').Text);
  979. IconTop := StrToInt(OthersNode.ChildNodes.FindNode('ImageIconTop').Text);
  980. CaptionTextLeft := StrToInt(OthersNode.ChildNodes.FindNode('CaptionTextLeft').Text);
  981. CaptionTop := StrToInt(OthersNode.ChildNodes.FindNode('CaptionTop').Text);
  982. LeftCaptionWidth := StrToInt(OthersNode.ChildNodes.FindNode('LeftCaptionWidth').Text);
  983. RightCaptionWidth := StrToInt(OthersNode.ChildNodes.FindNode('RightCaptionWidth').Text);
  984. LeftBottomWidth := StrToInt(OthersNode.ChildNodes.FindNode('LeftBottomWidth').Text);
  985. RightBottomWidth := StrToInt(OthersNode.ChildNodes.FindNode('RightBottomWidth').Text);
  986. AllowChangeSkinColor := OthersNode.ChildNodes.FindNode('AllowChangeSkinColor').Attributes['Value'];
  987. AllowChangeFormColor := OthersNode.ChildNodes.FindNode('AllowChangeFormColor').Attributes['Value'];
  988. AllowDeactivateSkin := OthersNode.ChildNodes.FindNode('AllowDeactivateSkin').Attributes['Value'];
  989. CloseBtnTop := StrToInt(PositionsNode.ChildNodes.FindNode('CloseBtnTop').Text) + CaptionTop;
  990. CloseBtnRight := StrToInt(PositionsNode.ChildNodes.FindNode('CloseBtnRight').Text);
  991. MaxAndRestoreBtnTop := StrToInt(PositionsNode.ChildNodes.FindNode('MaxAndRestoreBtnTop').Text) + CaptionTop;
  992. MaxAndRestoreBtnRight := StrToInt(PositionsNode.ChildNodes.FindNode('MaxAndRestoreBtnRight').Text);
  993. MinBtnTop := StrToInt(PositionsNode.ChildNodes.FindNode('MinBtnTop').Text) + CaptionTop;
  994. MinBtnRight := StrToInt(PositionsNode.ChildNodes.FindNode('MinBtnRight').Text);
  995. SetRegion;
  996. MakeBufferBMP;
  997. finally
  998. XMLDocument.Free;
  999. end;
  1000. end;
  1001. constructor TBaseForm.Create(AOwner: TComponent);
  1002. begin
  1003. inherited Create(AOwner);
  1004. FSettedDragFullWindows := False;
  1005. FLastIsActived := False;
  1006. DoubleBuffered := True;
  1007. FCustomCaption := '';
  1008. BmpIcon := TBitMap.Create;
  1009. BmpLeft := TBitMap.Create;
  1010. BmpCaption := TBitMap.Create;
  1011. BmpRight := TBitMap.Create;
  1012. BmpBottom := TBitMap.Create;
  1013. BmpMin := TBitMap.Create;
  1014. BmpRestore := TBitMap.Create;
  1015. BmpMax := TBitMap.Create;
  1016. BmpClose := TBitMap.Create;
  1017. BmpLeftRGN := TBitMap.Create;
  1018. BmpCaptionRGN := TBitMap.Create;
  1019. BmpRightRGN := TBitMap.Create;
  1020. BmpBottomRGN := TBitMap.Create;
  1021. BufBmpTop := TBitMap.Create;
  1022. BufBmpLeft := TBitMap.Create;
  1023. BufBmpRight := TBitMap.Create;
  1024. BufBmpBottom := TBitMap.Create;
  1025. FTimerForReDrawNormalButton := TTimer.Create(Self);
  1026. FTimerForReDrawNormalButton.Enabled := False;
  1027. FTimerForReDrawNormalButton.Interval := 500;
  1028. FTimerForReDrawNormalButton.OnTimer := FTimerForReDrawNormalButtonTimer;
  1029. FCanResizeWindow := True;
  1030. FCanMoveWindow := True;
  1031. FCanFullWindow := False;
  1032. FMinButtonForClose := False;
  1033. SkinName := 'Vista';
  1034. FCanDraw := True;
  1035. FShowCloseButton:=True;
  1036. Application.ProcessMessages;
  1037. end;
  1038. //------------------------------------------------------------------------------
  1039. destructor TBaseForm.Destroy;
  1040. begin
  1041. try
  1042. if Integer(OSVersion) > Integer(osWinMe) then
  1043. begin
  1044. if FDragFullWindows then
  1045. SystemParametersInfo(SPI_SETDRAGFULLWINDOWS , 1, nil , 0)
  1046. else
  1047. SystemParametersInfo(SPI_SETDRAGFULLWINDOWS , 0, nil , 0);
  1048. end;
  1049. FCanDraw := False;
  1050. FreeAndNil(FTimerForReDrawNormalButton);
  1051. FreeAndNil(BufBmpTop);
  1052. FreeAndNil(BufBmpLeft);
  1053. FreeAndNil(BufBmpRight);
  1054. FreeAndNil(BufBmpBottom);
  1055. FreeAndNil(BmpLeftRGN);
  1056. FreeAndNil(BmpCaptionRGN);
  1057. FreeAndNil(BmpRightRGN);
  1058. FreeAndNil(BmpBottomRGN);
  1059. FreeAndNil(BmpLeft);
  1060. FreeAndNil(BmpCaption);
  1061. FreeAndNil(BmpRight);
  1062. FreeAndNil(BmpBottom);
  1063. FreeAndNil(BmpMin);
  1064. FreeAndNil(BmpRestore);
  1065. FreeAndNil(BmpMax);
  1066. FreeAndNil(BmpClose);
  1067. FreeAndNil(BmpIcon);
  1068. finally
  1069. try
  1070. inherited Destroy;
  1071. except
  1072. end;
  1073. end;
  1074. end;
  1075. //------------------------------------------------------------------------------
  1076. procedure TBaseForm.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
  1077. var
  1078. ACanvas: TCanvas;
  1079. begin
  1080. ACanvas := TCanvas.Create;
  1081. try
  1082. ACanvas.Handle := Msg.DC;
  1083. ACanvas.Pen.Color := FormColor;
  1084. ACanvas.Brush.Color := FormColor;
  1085. ACanvas.FillRect(Rect((Width - ClientWidth) div 2, (Height - ClientHeight) div 2, ClientWidth, ClientHeight));
  1086. finally
  1087. ACanvas.Free;
  1088. end;
  1089. Msg.Result := 1; // 已处理
  1090. end;
  1091. //------------------------------------------------------------------------------
  1092. procedure TBaseForm.CreateParams(var Params: TCreateParams);
  1093. begin
  1094. inherited;
  1095. with Params do
  1096. begin
  1097. Style := (Style - WS_CAPTION) or WS_POPUP or WS_THICKFRAME or WS_SYSMENU;
  1098. if (biMinimize in BorderIcons) then Style := Style or WS_MINIMIZEBOX;
  1099. if biMaximize in BorderIcons then Style := Style or WS_MAXIMIZEBOX;
  1100. end;
  1101. end;
  1102. //------------------------------------------------------------------------------
  1103. function GetOSVersion: TOSVersion;
  1104. var
  1105. P: OSVERSIONINFO;
  1106. OSVer: TOSVersion;
  1107. begin
  1108. OSVer := osOther;
  1109. P.dwOSVersionInfoSize := SizeOf(P);
  1110. GetVersionEx(P);
  1111. case P.dwMajorVersion of
  1112. 3: OSVer := osWinNT351;
  1113. 4: begin
  1114. case P.dwMinorVersion of
  1115. 0: if P.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS then
  1116. OSVer := osWin95
  1117. else
  1118. OSVer := osWinNT40;
  1119. 10: OSVer := osWin98;
  1120. 90: OSVer := osWinMe;
  1121. end;
  1122. end;
  1123. 5:
  1124. begin
  1125. case p.dwMinorVersion of
  1126. 0: OSVer := osWin2000;
  1127. 1: OSVer := osWinXP;
  1128. 2: OSVer := osWin2003;
  1129. end;
  1130. end;
  1131. end;
  1132. Result := OSVer;
  1133. end;
  1134. initialization
  1135. FOSVersion := GetOSVersion;
  1136. FGettedDragFullWindows := False;
  1137. GetDragFullWindows;
  1138. finalization
  1139. end.