uo_xls_imflatbutton.sru 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. $PBExportHeader$uo_xls_imflatbutton.sru
  2. $PBExportComments$扁平按钮
  3. forward
  4. global type uo_xls_imflatbutton from commandbutton
  5. end type
  6. type tagrect from structure within uo_xls_imflatbutton
  7. end type
  8. type us_bitmap from structure within uo_xls_imflatbutton
  9. end type
  10. end forward
  11. type tagrect from structure
  12. long left
  13. long top
  14. long right
  15. long bottom
  16. end type
  17. type us_bitmap from structure
  18. long bmtype
  19. long bmwidth
  20. long bmheight
  21. long bmwidthbytes
  22. long bmplanes
  23. long bmbitspixel
  24. blob bmbits
  25. end type
  26. global type uo_xls_imflatbutton from commandbutton
  27. integer width = 302
  28. integer height = 100
  29. integer textsize = -9
  30. integer weight = 400
  31. fontcharset fontcharset = gb2312charset!
  32. fontpitch fontpitch = variable!
  33. string facename = "宋体"
  34. string text = "确定"
  35. event ue_paint pbm_paint
  36. event ue_lbuttondown pbm_lbuttondown
  37. event ue_mousemove pbm_mousemove
  38. event ue_lbuttonup pbm_lbuttonup
  39. event ue_size pbm_size
  40. event ue_dbclk pbm_lbuttondblclk
  41. event ue_keyup pbm_keyup
  42. event ue_keydown pbm_keydown
  43. event ue_enable pbm_enable
  44. event ue_textchange ( )
  45. end type
  46. global uo_xls_imflatbutton uo_xls_imflatbutton
  47. type prototypes
  48. //从指定窗口的结构中取得信息
  49. FUNCTION uLong GetWindowuLong(uLong hwnd, uLong nIndex) Alias For GetWindowLongA LIBRARY "USER32.DLL"
  50. //在窗口结构中为指定的窗口设置信息
  51. FUNCTION uLong SetWindowuLong(uLong hwnd, uLong nIndex,uLong dwNewLong) Alias For SetWindowLongA LIBRARY "USER32.DLL"
  52. //用指定的刷子填充一个矩形
  53. FUNCTION ulong FillRect(ulong hdc,ref tagrect lpRect,ulong hBrush) LIBRARY "user32.dll" alias for "FillRect;Ansi"
  54. //用纯色创建一个刷子
  55. FUNCTION ulong CreateSolidBrush(ulong crColor) LIBRARY "gdi32.dll"
  56. //为任何一种标准系统颜色取得一个刷子
  57. FUNCTION ulong GetSysColorBrush(ulong nIndex) LIBRARY "user32.dll"
  58. //判断指定windows显示对象的颜色
  59. FUNCTION ulong GetSysColor(ulong nIndex) LIBRARY "user32.dll"
  60. //指定阴影刷子、虚线画笔以及字符中的空隙的填充方式
  61. FUNCTION ulong SetBkMode(ulong hdc,ulong nBkMode) LIBRARY "gdi32.dll"
  62. //为指定的设备场景设置背景颜色。背景颜色用于填充阴影刷子、虚线画笔以及字符(如背景模式为OPAQUE)中的空隙。也在位图颜色转换期间使用
  63. FUNCTION ulong SetBkColor(ulong hdc,ulong crColor) LIBRARY "gdi32.dll"
  64. //设置当前文本颜色。这种颜色也称为“前景色”
  65. FUNCTION ulong SetTextColor(ulong hdc,ulong crColor) LIBRARY "gdi32.dll"
  66. ////将文本描绘到指定的矩形中
  67. FUNCTION ulong DrawText(ulong hdc,string lpStr,ulong nCount,ref tagrect lpRect,ulong wFormat) LIBRARY "user32.dll" ALIAS FOR "DrawTextA;Ansi"
  68. //用指定的样式描绘一个矩形的边框
  69. FUNCTION boolean DrawEdge(ulong hdc,ref tagrect qrc,ulong edge,ulong grfFlags) LIBRARY "user32.dll" alias for "DrawEdge;Ansi"
  70. //释放由调用GetDC或GetWindowDC函数获取的指定设备场景。它对类或私有设备场景无效(但这样的调用不会造成损害)
  71. FUNCTION ulong ReleaseDC(ulong hwnd,ulong hdc) LIBRARY "user32.dll"
  72. //删除专用设备场景或信息场景,释放所有相关窗口资源
  73. FUNCTION ulong DeleteDC(ulong hdc) LIBRARY "gdi32.dll"
  74. //每个设备场景都可能有选入其中的图形对象。其中包括位图、刷子、字体、画笔以及区域等等。一次选入设备场景的只能有一个对象。选定的对象会在设备场景的绘图操作中使用。例如,当前选定的画笔决定了在设备场景中描绘的线段颜色及样式
  75. FUNCTION ulong SelectObject(ulong hdc,ulong hObject) LIBRARY "gdi32.dll"
  76. //用这个函数删除GDI对象,比如画笔、刷子、字体、位图、区域以及调色板等等。对象使用的所有系统资源都会被释放
  77. FUNCTION ulong DeleteObject(ulong hObject) LIBRARY "gdi32.dll"
  78. //用指定的样式、宽度和颜色创建一个画笔
  79. FUNCTION ulong CreatePen(ulong nPenStyle,ulong nWidth,ulong crColor) LIBRARY "gdi32.dll"
  80. //为指定的设备场景指定一个新的当前画笔位置。前一个位置保存在lpPoint中
  81. FUNCTION ulong MoveToEx(ulong hdc,ulong ix,ulong iy,ulong lpPoint) LIBRARY "gdi32.dll"
  82. //用当前画笔画一条线,从当前位置连到一个指定的点。这个函数调用完毕,当前位置变成x,y点
  83. FUNCTION ulong LineTo(ulong hdc,ulong ix,ulong iy) LIBRARY "gdi32.dll"
  84. //校验窗口的全部或部分客户区。这样便可告之windows指定的区域不需要重画
  85. FUNCTION ulong ValidateRect(ulong hwnd,ref tagrect lpRect) LIBRARY "user32.dll" alias for "ValidateRect;Ansi"
  86. //获取指定窗口的设备场景
  87. FUNCTION ulong GetDC(ulong hwnd) LIBRARY "user32.dll"
  88. //载入一个位图、图标或指针
  89. FUNCTION ulong LoadImage(ulong hInst,string lpsz,ulong un1,ulong n1,ulong n2,ulong un2) LIBRARY "user32.dll" ALIAS FOR "LoadImageA;Ansi"
  90. //在指定的位置画一个图标
  91. FUNCTION boolean DrawIconEx(ulong hdc,ulong xLeft,ulong yTop,ulong hIcon,ulong cxWidth,ulong cyWidth,ulong istepIfAniCur,ulong hbrFlickerFreeDraw,ulong diFlags) LIBRARY "user32.dll"
  92. FUNCTION ulong GetTextFace(ulong hdc,ulong nCount,ref string lpFacename) LIBRARY "gdi32.dll" ALIAS FOR "GetTextFaceA;Ansi"
  93. FUNCTION boolean DrawState(ulong hDC,ulong hBrush,ulong lpDrawStateProc,ulong lParam,ulong wParam,ulong n1,ulong n2,ulong n3,ulong n4,ulong un) LIBRARY "user32.dll" ALIAS FOR "DrawStateA"
  94. FUNCTION ulong DestroyIcon(ulong hIcon) LIBRARY "user32.dll"
  95. FUNCTION ulong Rectangle(ulong hdc,ulong X1,ulong Y1,ulong X2,ulong Y2) LIBRARY "gdi32.dll"
  96. function long LoadLibrary( ref string lpLibFileName2 ) LIBRARY "KERNEL32" Alias For "LoadLibraryA;Ansi"
  97. function long FreeLibrary( long hinstance ) LIBRARY "KERNEL32"
  98. FUNCTION ulong LoadBitmap(ulong hInstance, long lpBitmapName) LIBRARY "user32.dll" ALIAS FOR "LoadBitmapA"
  99. FUNCTION ulong CreateDC(string lpDriverName,string lpDeviceName, string lpOutput, long lpInitData) LIBRARY "gdi32.dll" ALIAS FOR "CreateDCA;Ansi"
  100. FUNCTION ulong CreateCompatibleDC(ulong hdc) LIBRARY "gdi32.dll"
  101. FUNCTION ulong GetPixel(ulong hdc,ulong ix,ulong iy) LIBRARY "gdi32.dll"
  102. FUNCTION ulong LoadImage(ulong hInst,long lpsz,ulong un1,ulong n1,ulong n2,ulong un2) LIBRARY "user32.dll" ALIAS FOR "LoadImageA"
  103. //if it's use in other version ,please modify by hand.
  104. FUNCTION long FN_ResGetIconID(string lpLibFileName) LIBRARY "PBVM90.dll" alias for "FN_ResGetIconID;Ansi"
  105. FUNCTION long FN_ResGetBitmapID(string lpLibFileName) LIBRARY "PBVM90.dll" alias for "FN_ResGetBitmapID;Ansi"
  106. FUNCTION string FN_ResGetBitmapName(long lpLibFileName) LIBRARY "PBVM90.dll" alias for "FN_ResGetBitmapName;Ansi"
  107. Function Long ImageList_Create (Long MinCx , Long MinCy , Long flags ,Long cInitial ,Long cGrow) Library "PBVM90.dll" ALIAS FOR "PBImageList_Create"
  108. Function Long ImageList_AddMasked(Long hImageList ,Long hbmImage , Long crMask ) Library "PBVM90.dll" ALIAS FOR "PBImageList_AddMasked"
  109. Function Long ImageList_GetIcon(Long hImageList , Long ImgIndex , Long hbmMask ) Library "PBVM90.dll" ALIAS FOR "PBImageList_GetIcon"
  110. Function Long ImageList_Destroy(Long hImageList) Library "PBVM90.dll" ALIAS FOR "PBImageList_Destroy"
  111. //ImageList 函数
  112. //Function Long ImageList_Create (Long MinCx , Long MinCy , Long flags ,Long cInitial ,Long cGrow) Library "COMCTL32.DLL"
  113. //Function Long ImageList_AddMasked(Long hImageList ,Long hbmImage , Long crMask ) Library "COMCTL32.DLL"
  114. //Function Long ImageList_GetIcon(Long hImageList , Long ImgIndex , Long hbmMask ) Library "COMCTL32.DLL"
  115. FUNCTION ulong RoundRect(ulong hdc,ulong X1,ulong Y1,ulong X2,ulong Y2,ulong X3,ulong Y3) LIBRARY "gdi32.dll"
  116. FUNCTION ulong GetStockObject(ulong nIndex) LIBRARY "gdi32.dll"
  117. function ulong SetCapture(ulong hwnd) library "user32.dll"
  118. function boolean ReleaseCapture() library "user32.dll"
  119. function ulong GetCapture() library "user32.dll"
  120. //获得整个窗口的范围矩形,窗口的边框、标题栏、滚动条及菜单等都在这个矩形内
  121. FUNCTION ulong GetWindowRect(ulong hwnd,ref tagRECT lpRect) LIBRARY "user32.dll" alias for "GetWindowRect;Ansi"
  122. //移动矩形
  123. FUNCTION ulong OffsetRect(ref tagrect lpRect,ulong xs,ulong ys) LIBRARY "user32.dll" alias for "OffsetRect;Ansi"
  124. FUNCTION ulong GetClientRect(ulong hwnd,ref tagRECT lpRect) LIBRARY "user32.dll" alias for "GetClientRect;Ansi"
  125. FUNCTION ulong DefWindowProc(ulong hwnd,ulong wMsg,ulong wParam,ulong lParam) LIBRARY "user32.dll" ALIAS FOR "DefWindowProcA"
  126. FUNCTION ulong DrawFocusRect(ulong hdc,ref tagRECT lpRect) LIBRARY "user32.dll" alias for "DrawFocusRect;Ansi"
  127. Function long CreateCompatibleBitmap ( long hdc, long nwidth, long nheight ) library "gdi32"
  128. Function uLong BitBlt(uLong hDestDC,uLong xx,uLong yy,uLong nWidth,uLong nHeight,uLong hSrcDC,uLong xSrc,uLong ySrc,uLong dwRop) LIBRARY "gdi32.dll"
  129. Function uLong GetObjectBitmap( uLong hgdiobj, int cbBuffer, ref us_bitmap bm ) library "gdi32.dll" alias for "GetObjectA;Ansi"
  130. FUNCTION ulong FrameRect(ulong hdc,ref tagRECT lpRect,ulong hBrush) LIBRARY "user32.dll" alias for "FrameRect;Ansi"
  131. end prototypes
  132. type variables
  133. //public:
  134. string normalPicName
  135. protected:
  136. integer PicSize //customize pic's size
  137. String mMovePicName
  138. String BKBMPName
  139. //if PIC_Align is floating!,the button does't have Edge.
  140. ToolBarAlignment PIC_Align = Alignatleft!
  141. //if ParentColor = true,then COLOR_BK_OUT = ParentWindow's BackColor
  142. boolean ParentColor = false
  143. boolean Border = true
  144. long COLOR_BK_OUT = 14215660
  145. long COLOR_BK_IN = 8900092
  146. long COLOR_BK_DOWN = 12965593
  147. long BorderColor = rgb(0,0,0)
  148. long FontColor =rgb(0,0,0)
  149. long DisableFontColor=rgb(128,128,128)
  150. long MoveinFontColor =rgb(0,0,0)
  151. //TOOLTIP type,no suitable enumerate type ,so use rowfocusind
  152. rowfocusind TOOLTIPTYPE = focusrect!
  153. boolean HaveFocusRect=true
  154. private:
  155. ulong h_bmpBk,h_normalPic,h_movePic
  156. boolean ib_captured = false
  157. boolean ib_pushDown = false
  158. integer ii_picsize
  159. long il_BKDC =- 1
  160. integer ii_BKW
  161. integer ii_BKH
  162. tagRect winRect
  163. Private uo_xls_tooltip ToolTip //显示提示信息的用户对象实例
  164. //-------------------------------------
  165. //CONSTANT var
  166. //SetBkMode
  167. CONSTANT ulong TRANSPARENT = 1
  168. //DrawEdge
  169. CONSTANT uLong BDR_RAISEDOUTER = 1
  170. CONSTANT uLong BDR_SUNKENOUTER = 2
  171. CONSTANT uLong BDR_RAISEDINNER = 4
  172. CONSTANT uLong BDR_SUNKENINNER = 8
  173. CONSTANT uLong BDR_OUTER = 3
  174. CONSTANT uLong BDR_INNER = 12
  175. CONSTANT uLong BF_LEFT = 1
  176. CONSTANT uLong BF_RIGHT = 4
  177. CONSTANT uLong BF_TOP = 2
  178. CONSTANT uLong BF_BOTTOM = 8
  179. CONSTANT uLong BF_RECT = 1
  180. //GetSysColor GetSysColorBrush
  181. CONSTANT uLong COLOR_BACKGROUND=1
  182. CONSTANT uLong COLOR_HIGHLIGHT= 13
  183. CONSTANT uLong COLOR_HIGHLIGHTTEXT = 14
  184. CONSTANT uLong COLOR_MENU = 4
  185. CONSTANT uLong COLOR_WINDOW = 5
  186. CONSTANT uLong COLOR_MENUTEXT = 7
  187. CONSTANT uLong COLOR_WINDOWTEXT = 8
  188. CONSTANT uLong COLOR_ACTIVECAPTION = 2
  189. CONSTANT uLong COLOR_BTNFACE = 15
  190. CONSTANT uLong COLOR_INFOBK = 24
  191. Constant integer COLOR_BTNHIGHLIGHT = 20
  192. Constant integer COLOR_BTNSHADOW = 16
  193. //LoadImage
  194. CONSTANT uLong IMAGE_BITMAP = 0
  195. CONSTANT uLong IMAGE_ICON = 1
  196. CONSTANT uLong IMAGE_CURSOR = 2
  197. CONSTANT uLong IMAGE_ENHMETAFILE = 3
  198. CONSTANT uLong LR_DEFAULTCOLOR = 0
  199. CONSTANT uLong LR_MONOCHROME = 1
  200. CONSTANT uLong LR_COLOR = 2
  201. CONSTANT uLong LR_COPYRETURNORG = 4
  202. CONSTANT uLong LR_COPYDELETEORG = 8
  203. CONSTANT uLong LR_LOADFROMFILE = 16
  204. CONSTANT uLong LR_LOADTRANSPARENT = 32
  205. CONSTANT uLong LR_DEFAULTSIZE = 64
  206. CONSTANT uLong LR_VGACOLOR = 128
  207. CONSTANT uLong LR_LOADMAP3DCOLORS = 4096
  208. CONSTANT uLong LR_CREATEDIBSECTION = 8192
  209. CONSTANT uLong LR_COPYFROMRESOURCE = 16384
  210. CONSTANT uLong LR_SHARED = 32768
  211. //CreatePen
  212. CONSTANT uLong PS_SOLID = 0
  213. //DrawText
  214. CONSTANT uLong DT_LEFT = 0
  215. CONSTANT uLong DT_CENTER = 1
  216. CONSTANT uLong DT_RIGHT = 2
  217. CONSTANT uLong DT_VCENTER = 4
  218. CONSTANT uLong DT_BOTTOM = 8
  219. CONSTANT uLong DT_SINGLELINE = 32
  220. CONSTANT uLong DT_CALCRECT = 1024
  221. CONSTANT uLong DT_WORDBREAK = 16
  222. Constant integer DST_ICON = 3
  223. Constant integer DST_BITMAP =4
  224. Constant integer DSS_NORMAL =0
  225. Constant integer DSS_DISABLED = 32
  226. Constant integer DSS_MONO = 128
  227. Constant integer DSS_UNION = 16
  228. Constant int SM_CYMENU = 15
  229. Constant int SM_CXMENUCHECK = 71
  230. //use in GetStockObject
  231. Constant int WHITE_BRUSH=0
  232. Constant int GRAY_BRUSH =1
  233. Constant int LTGRAY_BRUSH=2
  234. Constant int DKGRAY_BRUSH=3
  235. Constant int BLACK_BRUSH=4
  236. Constant int NULL_BRUSH=5
  237. Constant int WHITE_PEN=6
  238. Constant int BLACK_PEN=7
  239. Constant int NULL_PEN=8
  240. Constant int OEM_FIXED_FONT=10
  241. Constant int ANSI_FIXED_FONT=11
  242. Constant int ANSI_VAR_FONT=12
  243. Constant int SYSTEM_FONT=13
  244. Constant int WM_GETFONT = 49
  245. //bitblt
  246. constant long SRCCOPY = 13369376
  247. constant long NOTSRCCOPY = 3342344
  248. constant long SRCAND = 8913094
  249. constant long SRCINVERT = 6684742
  250. end variables
  251. forward prototypes
  252. private function integer of_getpicsize ()
  253. private subroutine of_getrect (toolbaralignment aa_align, ref tagrect ast_cbrect, ref tagrect ast_picrect, ref tagrect ast_textrect, integer ai_picsize)
  254. protected function long of_getstockicon (string as_stockbitmap, ref integer ai_imagetype)
  255. public function window of_getparentwin ()
  256. protected subroutine of_drawborder (long hdc, tagrect ast_rect)
  257. protected function long of_geticonhandle (string as_iconname, integer ai_size)
  258. protected function long of_getmaskcolor (long al_bitmaphandle)
  259. private subroutine of_loadbkbmp (string as_bmp)
  260. private subroutine of_drawbmpbk (long hdc, tagrect ast_rect)
  261. protected subroutine of_destroyrc ()
  262. public subroutine of_paint ()
  263. public subroutine of_init_draw ()
  264. public subroutine of_drawbk (long hdc, ref tagrect ast_rect)
  265. end prototypes
  266. event ue_paint;of_paint()
  267. //validates the client area within a rectangle by removing the rectangle
  268. //from the update region of the specified window
  269. ValidateRect(handle(this),winRect)
  270. return 1
  271. end event
  272. event ue_lbuttondown;//draw pushdown state
  273. ib_pushDown = true
  274. this.setFocus()
  275. of_paint()
  276. //Don't processes this message
  277. return 1
  278. end event
  279. event ue_mousemove;if (XPos<0 or YPos<0) or (XPos>=this.Width or YPos>this.Height) then //not in region
  280. IF ib_Captured THEN //release mouse
  281. ib_Captured = false
  282. ib_PushDown= false
  283. ReleaseCapture()
  284. //draw normal state
  285. of_paint()
  286. END IF
  287. elseif GetCapture()<>handle(this) THEN
  288. SetCapture(handle(this))
  289. ib_Captured = true
  290. if KeyDown(KeyLeftButton!) THEN
  291. ib_PushDown= true
  292. end if
  293. //draw movein state
  294. of_paint()
  295. end if
  296. //registe hint
  297. if TOOLTIPTYPE =focusrect! then
  298. ToolTip.TIPSTYLE = ToolTip.STYLE_NORMAL
  299. ToolTip.ControlRegister(this,this.tag,0)
  300. ToolTip.Showtip(this)
  301. elseif TOOLTIPTYPE =Hand! then
  302. ToolTip.TIPSTYLE = ToolTip.STYLE_BALLOONTIP
  303. ToolTip.ControlRegister(this,this.tag,0)
  304. ToolTip.Showtip(this)
  305. end if
  306. end event
  307. event ue_lbuttonup;//draw pushup(normal) state
  308. if ib_pushDown then postevent("clicked") //as lbuttondown event was't processed
  309. ib_pushDown = false
  310. ib_captured = false
  311. ReleaseCapture()
  312. of_paint()
  313. end event
  314. event ue_size;of_destroyrc()
  315. of_init_draw()
  316. end event
  317. event ue_dbclk;//Don't processes this message
  318. //In order to remove default draw
  319. return 1
  320. end event
  321. event ue_keyup;
  322. ib_pushdown = false
  323. IF Key = KeySpaceBar! OR key= KeyEnter! THEN
  324. post of_paint()
  325. end if
  326. end event
  327. event ue_keydown;IF Keydown( KeySpaceBar!) OR keydown(KeyEnter!) THEN
  328. IF NOT ib_pushdown THEN
  329. ib_pushdown = true
  330. post of_paint()
  331. elseif (Keydown( KeySpaceBar!) and Key <> KeySpaceBar!) or( Key <> KeyEnter! and keydown(KeyEnter!)) then
  332. // KeySpaceBar is down and press other key
  333. post of_paint()
  334. end if
  335. END IF
  336. end event
  337. event ue_enable;post of_paint()
  338. end event
  339. event ue_textchange();//====================================================================
  340. // Function: uo_imflatbutton for ue_textchange()
  341. //--------------------------------------------------------------------
  342. // Description:按钮txt改变时触发
  343. //--------------------------------------------------------------------
  344. // Arguments:(None)
  345. //--------------------------------------------------------------------
  346. // Returns:
  347. //--------------------------------------------------------------------
  348. // Author: yyx Date: 2003.10.28
  349. //--------------------------------------------------------------------
  350. // Modify History:
  351. //
  352. //====================================================================
  353. this.of_paint()
  354. end event
  355. private function integer of_getpicsize ();integer li_refer,li_cbwidth,li_cbHeight
  356. li_cbwidth = UnitsToPixels ( width, XUnitsToPixels!)
  357. li_cbHeight = UnitsToPixels ( height, YUnitsToPixels!)
  358. if PicSize > 0 then
  359. if li_cbwidth<PicSize then width = PixelsToUnits (PicSize, XPixelsToUnits!) +2
  360. if li_cbHeight<PicSize then height = PixelsToUnits(PicSize, XPixelsToUnits!) +2
  361. return PicSize
  362. end if
  363. //if PicSize = 0 then calculate the pic's size
  364. li_refer = min(li_cbwidth,li_cbHeight) *0.9
  365. li_refer = li_refer /8
  366. li_refer = li_refer*8
  367. return li_refer
  368. end function
  369. private subroutine of_getrect (toolbaralignment aa_align, ref tagrect ast_cbrect, ref tagrect ast_picrect, ref tagrect ast_textrect, integer ai_picsize);//get the two rects that pic and text to occupy
  370. ast_textrect = ast_cbrect
  371. ast_picrect = ast_cbrect
  372. choose case aa_align
  373. case alignatbottom!
  374. ast_textrect.bottom = ast_cbrect.bottom - ai_picsize -1
  375. ast_picrect.top = ast_cbrect.bottom - ai_picsize
  376. case alignatleft!
  377. ast_textrect.left = ast_cbrect.left + ai_picsize +1
  378. ast_picrect.right = ast_cbrect.left + ai_picsize
  379. case alignatright!
  380. ast_textrect.right = ast_cbrect.right - ai_picsize -1
  381. ast_picrect.left = ast_cbrect.right - ai_picsize
  382. case alignattop!
  383. ast_textrect.top = ast_cbrect.top + ai_picsize +1
  384. ast_picrect.bottom = ast_cbrect.top + ai_picsize
  385. case floating!
  386. //no conduct
  387. end choose
  388. end subroutine
  389. protected function long of_getstockicon (string as_stockbitmap, ref integer ai_imagetype);//////////////////////////////////////////////////////////////////////////////
  390. //
  391. // 函数名称: Of_getstockicon
  392. // 访问级别: Public
  393. // 参数: as_stockbitmap stock位图名称
  394. // ai_imagetype 位图 or 图标标示
  395. // 返回值: Long
  396. // 功能描述: 得到系统stock位图相应的标识符
  397. //////////////////////////////////////////////////////////////////////////////
  398. Long ll_Identifier
  399. //检查参数
  400. If IsNull(as_StockBitmap) Or as_StockBitmap="" Then Return -1
  401. ll_Identifier = FN_ResGetBitmapID(as_stockbitmap)
  402. if ll_Identifier<=0 then
  403. ll_Identifier = FN_ResGetIconID(as_stockbitmap)
  404. ai_imagetype= IMAGE_ICON
  405. else //位图
  406. ai_imagetype = IMAGE_BITMAP
  407. end if
  408. return ll_Identifier
  409. end function
  410. public function window of_getparentwin ();powerobject lpo_tmp
  411. window lw_tmp
  412. lpo_tmp = this.getparent()
  413. DO While lpo_tmp.typeof() <> Window!
  414. lpo_tmp= lpo_tmp.getparent()
  415. LOOP
  416. lw_tmp = lpo_tmp
  417. return lw_tmp
  418. end function
  419. protected subroutine of_drawborder (long hdc, tagrect ast_rect);long hNewBrush
  420. if ib_pushDown then // Draw pressed state
  421. if PIC_Align<>floating! then
  422. DrawEdge(hdc,ast_rect, BDR_SUNKENOUTER, BF_LEFT+BF_RIGHT+BF_TOP+BF_BOTTOM)
  423. end if
  424. elseif ib_Captured then // Draw mousemove state
  425. if PIC_Align<>floating! then
  426. DrawEdge(hdc,ast_rect, BDR_RAISEDINNER, BF_LEFT+BF_RIGHT+BF_TOP+BF_BOTTOM)
  427. end if
  428. else // Draw normal state
  429. if Border then
  430. hnewBrush = CreateSolidBrush(BorderColor)
  431. FrameRect(hdc,ast_rect,hnewBrush)
  432. deleteObject(hnewBrush)
  433. end if
  434. end if
  435. end subroutine
  436. protected function long of_geticonhandle (string as_iconname, integer ai_size);//====================================================================
  437. // Function: of_geticonhandle()
  438. //--------------------------------------------------------------------
  439. // Description: Get the handle of icon from the toolbaritemname of the menu
  440. //--------------------------------------------------------------------
  441. // Arguments:
  442. // value string as_iconname
  443. //--------------------------------------------------------------------
  444. // Returns: long IconHandle
  445. //--------------------------------------------------------------------
  446. // Author: Dale Zheng Date: 2003.05.07
  447. //--------------------------------------------------------------------
  448. // Modify History:
  449. //
  450. //====================================================================
  451. Long ll_BitmapHandle , ll_IconHandle , ll_Library , ll_Index=-1
  452. Environment env
  453. Integer rtn,li_imagetype
  454. String ls_File
  455. Long ll_identier
  456. long ll_hIml
  457. if pos(lower(as_iconname),'.ico')>0 then
  458. ll_IconHandle= LoadImage(0,as_iconname,IMAGE_ICON,ai_size,ai_size,LR_LOADFROMFILE )
  459. elseif pos(lower(as_iconname),'.bmp')>0 then
  460. ll_BitmapHandle =LoadImage(0,as_iconname,IMAGE_BITMAP,ai_size,ai_size,LR_LOADFROMFILE + LR_DEFAULTSIZE)
  461. ll_hIml = ImageList_Create (ai_size , ai_size , 33, 4, 4)
  462. ll_Index = ImageList_AddMasked(ll_hIml , ll_BitmapHandle , Of_GetMaskColor(ll_BitmapHandle))
  463. ll_IconHandle= ImageList_GetIcon( ll_hIml , ll_Index , 1)
  464. //DeleteObject(ll_hIml)
  465. ImageList_Destroy(ll_hIml)
  466. DeleteObject(ll_BitmapHandle)
  467. elseif pos(as_iconname,'!')>0 then
  468. rtn = GetEnvironment(env)
  469. IF rtn <> 1 THEN
  470. MessageBox("TIP","Get the value is wrrong in the PowerBuilder Environment.",StopSign!,Ok!)
  471. Return -1
  472. End If
  473. ls_File = "PBVM" + String(env.PBMajorRevision) + "0.DLL"
  474. ll_Library = LoadLibrary(ls_File)
  475. ll_identier = Of_GetStockicon(as_iconname,li_imagetype)
  476. If ll_identier >0 and li_imagetype = IMAGE_BITMAP Then
  477. ll_BitmapHandle = LoadBitmap ( ll_Library , ll_identier)
  478. ll_hIml = ImageList_Create (16 , 16 , 33, 4, 4)
  479. ll_Index = ImageList_AddMasked(ll_hIml , ll_BitmapHandle , Of_GetMaskColor(ll_BitmapHandle))
  480. ll_IconHandle= ImageList_GetIcon( ll_hIml , ll_Index , 1)
  481. //DeleteObject(ll_hIml)
  482. ImageList_Destroy(ll_hIml)
  483. DeleteObject(ll_BitmapHandle)
  484. elseIf ll_identier >0 and li_imagetype = IMAGE_ICON Then
  485. ll_IconHandle= LoadImage(ll_Library,ll_identier,IMAGE_ICON,0,0, LR_DEFAULTSIZE )
  486. Else
  487. ll_index = -1
  488. End If
  489. FreeLibrary ( ll_Library )
  490. else
  491. return 0
  492. end if
  493. return ll_IconHandle
  494. end function
  495. protected function long of_getmaskcolor (long al_bitmaphandle);//////////////////////////////////////////////////////////////////////////////
  496. // 函数名称: Of_GetMaskColor
  497. // 访问级别: Public
  498. // 参数: al_BitmapHandle 位图句柄
  499. // 返回值: Long
  500. // 功能描述: 获得指定位图文件的Mask颜色,返回值为Mask颜色
  501. // 补充说明:
  502. //////////////////////////////////////////////////////////////////////////////
  503. // 修改记录:2001-11-15
  504. // 编码:何锐
  505. ////////////////////////////////////////////////////////////////////////////
  506. String ls_Null
  507. Long ll_Hdc,ll_HDCTemp,ll_HbmpTemp
  508. Long ll_MaskColor = -1
  509. ll_HDC = CreateDC("DISPLAY",ls_Null,ls_Null,0)
  510. If ll_HDC<>0 Then
  511. //创建一个与指定设备兼容的内存上下文环境
  512. ll_HDCTemp = CreateCompatibleDC(ll_HDC)
  513. If ll_HDCTemp<>0 Then
  514. //选择一个对象到指定的设备上下文环境
  515. ll_HbmpTemp = SelectObject(ll_HDCTemp, al_BitMapHandle)
  516. //获得位图坐标(0,0)颜色值
  517. ll_MaskColor = GetPixel(ll_HDCTemp,0,0)
  518. SelectObject(ll_HDCTemp,ll_HbmpTemp)
  519. DeleteDC(ll_HDCTemp)
  520. End If
  521. DeleteDC(ll_HDC)
  522. End If
  523. Return ll_MaskColor
  524. end function
  525. private subroutine of_loadbkbmp (string as_bmp);ulong ll_bmp,ll_new,ll_old,ll_rgb
  526. us_bitmap lus_bmp
  527. long ll_inst,ll_windc
  528. SetNull(ll_inst)
  529. //载入图片
  530. ll_bmp = LoadImage(ll_inst,as_bmp,0,0,0,16)
  531. if ll_bmp = 0 then
  532. il_BKDC = -1
  533. return
  534. end if
  535. GetObjectBitmap( ll_bmp, 28, lus_bmp )
  536. ii_BKW= lus_bmp.bmwidth
  537. ii_BKH= lus_bmp.bmheight
  538. ll_windc = getdc(handle(this))
  539. il_BKDC = CreateCompatibleDC(ll_windc)
  540. ll_old = SelectObject(il_BKDC,ll_bmp)
  541. //释放资源
  542. fillrect (ll_windc,winrect,ll_bmp)
  543. Deleteobject(ll_bmp)
  544. ReleaseDC(handle(this),ll_windc)
  545. end subroutine
  546. private subroutine of_drawbmpbk (long hdc, tagrect ast_rect);//if the button's background is a BMP ,then process this function.
  547. //the BMP's size had better be more larger then the button
  548. int li_cbwidth,li_cbHeight,li_W,li_H,li_srcx,li_srcy
  549. li_cbwidth = ast_rect.right - ast_rect.left
  550. li_cbHeight = ast_rect.bottom - ast_rect.top
  551. li_W = min(li_cbwidth,ii_BKW)
  552. li_H = min(li_cbHeight,ii_BKH)
  553. if ib_pushDown then
  554. li_srcx=1
  555. end if
  556. BitBlt(HDC, 0, 0,li_W,li_H, il_BKDC,li_srcx, 0, SrcCopy)
  557. li_cbwidth =li_cbwidth - ii_BKW -li_srcx
  558. int i
  559. DO WHILE li_cbwidth > 0 //button's width is more longer then the loaded bmp's
  560. i++
  561. BitBlt(HDC, (ii_BKW - li_srcx)*i,0, ii_BKW - li_srcx,li_H, il_BKDC,li_srcx, 0, SrcCopy)
  562. li_cbwidth= li_cbwidth - ii_BKW - li_srcx
  563. LOOP
  564. i=0
  565. li_cbHeight =li_cbHeight - ii_BKH -1
  566. DO WHILE li_cbHeight > 0 //button's Height is more longer then the loaded bmp's
  567. i++
  568. BitBlt(HDC, 0, (ii_BKH -1)* i ,ast_rect.right - ast_rect.left,ii_BKH,HDC,0, 1, SrcCopy)
  569. li_cbHeight= li_cbHeight - ii_BKH -1
  570. LOOP
  571. end subroutine
  572. protected subroutine of_destroyrc ();destroyicon(h_normalPic)
  573. destroyicon(h_MovePic)
  574. if il_BKDC<> - 1 then
  575. deleteDC(il_BKDC)
  576. il_BKDC= - 1
  577. end if
  578. end subroutine
  579. public subroutine of_paint ();
  580. long hdc
  581. tagRect picRect,textRect
  582. int li_x,li_y
  583. long ll_hFont,ll_oldFont,ll_oldFcolor
  584. hdc = getdc(handle(this))
  585. if h_normalPic>0 then
  586. of_getrect(PIC_Align,winRect,picRect,textRect,ii_picsize)
  587. else
  588. textRect = winRect
  589. end if
  590. if PIC_Align = alignatleft! then
  591. li_y = (picRect.bottom - picRect.top - ii_picsize) /2
  592. li_x = li_y
  593. elseif PIC_Align = alignatright! then
  594. li_y = (picRect.bottom - picRect.top - ii_picsize) /2
  595. li_x = picRect.left - li_y
  596. elseif PIC_Align = alignattop! then
  597. li_x = (picRect.right - picRect.left - ii_picsize) /2
  598. li_y = 4//li_x
  599. elseif PIC_Align = alignatbottom! then
  600. li_x = (picRect.right - picRect.left - ii_picsize) /2
  601. li_y = picRect.Top - li_x
  602. end if
  603. if ib_pushDown then
  604. li_y ++
  605. li_x ++
  606. offsetRect(textRect,1,1)
  607. end if
  608. if il_BKDC <> - 1 then
  609. of_drawBMPbk(hdc,winRect)
  610. else
  611. of_drawbk(hdc,winRect)
  612. end if
  613. of_drawBorder(hdc,winRect)
  614. if (ib_captured or ib_pushDown) and h_MovePic >0 then //mouse movein state
  615. DrawIconEx(hdc,li_x,li_y,h_MovePic,ii_picsize,ii_picsize,0,0,DST_ICON )
  616. elseif enabled and h_normalPic>0 then //normal state
  617. DrawIconEx(hdc,li_x,li_y,h_normalPic,ii_picsize,ii_picsize,0,0,DST_ICON )
  618. elseif not enabled then //disable state
  619. DrawState(hdc, 0, 0, h_normalPic, 0, li_x, li_y, 0 , 0, DST_ICON + DSS_DISABLED)
  620. end if
  621. SetBkMode(hdc,TRANSPARENT)
  622. // Get the font in use on the Button
  623. ll_hFont = Send(Handle(this), WM_GETFONT, 0, 0)
  624. // Select it into the device context
  625. ll_oldFont = SelectObject(Hdc, ll_hFont)
  626. if ib_captured then
  627. ll_oldFcolor = SetTextColor(hdc,MoveinFontColor)
  628. else
  629. if this.Enabled THEN
  630. ll_oldFcolor = SetTextColor(hdc,FontColor)
  631. else
  632. ll_oldFcolor = SetTextColor(hdc,DisableFontColor)
  633. end if
  634. end if
  635. DrawText(hdc,text,- 1,textRect,DT_CENTER+DT_VCENTER+DT_SINGLELINE)
  636. SetTextColor(hdc,ll_oldFcolor)
  637. SelectObject(Hdc, ll_oldFont)
  638. if getfocus()=this and HaveFocusRect then //draw FocusRect
  639. tagrect FocusRect
  640. //get FocusRect's size
  641. FocusRect.left = winRect.left +4
  642. FocusRect.top = winRect.top +4
  643. FocusRect.right = winRect.right -4
  644. FocusRect.bottom = winRect.bottom -4
  645. DrawFocusRect(hdc,FocusRect)
  646. end if
  647. releaseDC(handle(this),hdc)
  648. end subroutine
  649. public subroutine of_init_draw ();//initiate some instance vars
  650. if ParentColor then COLOR_BK_OUT = of_getParentWin().backColor
  651. ii_picsize = of_getpicsize()
  652. if normalPicName<>"" then h_normalPic = of_geticonhandle(normalPicName,ii_picsize)
  653. if mMovePicName<>"" then h_MovePic = of_geticonhandle(mMovePicName,ii_picsize)
  654. GetClientRect(handle(this),winRect)
  655. if BKBMPName<>"" then
  656. of_loadbkbmp(BKBMPName)
  657. end if
  658. end subroutine
  659. public subroutine of_drawbk (long hdc, ref tagrect ast_rect);long hNewBrush,hnewPen,holdPen,holdBrush
  660. if ib_pushDown then // Draw pressed state
  661. if PIC_Align=floating! then
  662. hNewBrush =CreateSolidBrush(COLOR_BK_OUT)
  663. else
  664. hNewBrush =CreateSolidBrush(COLOR_BK_DOWN)
  665. end if
  666. FillRect(hdc,ast_rect,hNewBrush)
  667. DeleteObject(hNewBrush)
  668. elseif ib_Captured then // Draw mousemove state
  669. if PIC_Align=floating! then
  670. hNewBrush =CreateSolidBrush(COLOR_BK_OUT)
  671. else
  672. hNewBrush =CreateSolidBrush(COLOR_BK_IN)
  673. end if
  674. FillRect(hdc,ast_rect,hNewBrush)
  675. DeleteObject(hNewBrush)
  676. else // Draw normal state
  677. hNewBrush =CreateSolidBrush(COLOR_BK_OUT)
  678. FillRect(hdc,ast_rect,hNewBrush)
  679. DeleteObject(hNewBrush)
  680. end if
  681. end subroutine
  682. event constructor;//----------------------------------------------------------------*
  683. // UserObject: uo_imflatbutton *
  684. // Description: flatbutton (ONLY WINDOW MENU SUPPORTED) *
  685. // known bugs:
  686. // if one or more buttons are checked "default" or "Cancel" properties,
  687. // as the button use default CommandButtonWnd to try to refresh,
  688. // maybe can see default appearance.
  689. //----------------------------------------------------------------*
  690. // Author(s): Date Remark *
  691. // bluetlck 2003.05.20 Develop *
  692. // rjh 2003.05.20 fixed a few bugs *
  693. // *
  694. //----------------------------------------------------------------*
  695. constant long BS_OWNERDRAW = 11
  696. constant long GWL_STYLE = -16
  697. //constant long BS_GROUPBOX = 7
  698. constant long BS_PUSHBUTTON = 0
  699. //BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP
  700. //constant long WS_CHILD =1073741824
  701. //constant long WS_TABSTOP = 65536
  702. //constant long WS_VISIBLE = 268435456
  703. //nStyle =BS_PUSHBUTTON + WS_CHILD + WS_VISIBLE + WS_TABSTOP
  704. long nStyle
  705. //将按钮设置为OWNERDRAW button
  706. nStyle = GetWindowuLong(handle(this), GWL_STYLE)
  707. nStyle = nStyle + BS_OWNERDRAW
  708. SetWindowuLong(handle(this), GWL_STYLE, nStyle)
  709. //载入图标
  710. of_init_draw()
  711. end event
  712. on uo_xls_imflatbutton.create
  713. end on
  714. on uo_xls_imflatbutton.destroy
  715. end on
  716. event destructor;of_destroyRC() //释放图标资源
  717. end event
  718. event getfocus;post of_paint()
  719. end event