RealICQSkinFrm.pas 38 KB

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