﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-tianzhihua-文章分类-JAVA SWT</title><link>http://www.blogjava.net/tianzhihua/category/19900.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 11 Apr 2007 16:28:54 GMT</lastBuildDate><pubDate>Wed, 11 Apr 2007 16:28:54 GMT</pubDate><ttl>60</ttl><item><title>SWT 中实现自绘按钮</title><link>http://www.blogjava.net/tianzhihua/articles/99703.html</link><dc:creator>gyb</dc:creator><author>gyb</author><pubDate>Tue, 13 Feb 2007 07:34:00 GMT</pubDate><guid>http://www.blogjava.net/tianzhihua/articles/99703.html</guid><description><![CDATA[本文参考网上一些网友的文章后改进而成，下面的代码不做详细的说明，只是简单的说明一下。<br />1、定义一个自绘按钮绘制动作的接口OwnerDrawButtonStyleImp ，代码如下：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> org.eclipse.swt.widgets;<br /><br /></span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br /> * 自绘按钮绘制接口<br /> * <br /> *<br /> </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">interface</span><span style="COLOR: #000000"> OwnerDrawButtonStyleImp {<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> drawButton(OwnerDrawButton button,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> wParam, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> lParam);<br />}<br /></span></div><br />2、创建一个OwnerDrawButton类来作为自绘按钮类，构造为：<br />      public OwnerDrawButton(Composite parent,OwnerDrawButtonStyleImp buttonStyle)<br />其中OwnerDrawButtonStyleImp 为具体实现绘制工作的接口，完整代码如下：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> org.eclipse.swt.widgets;<br /><br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.eclipse.swt.SWT;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.eclipse.swt.graphics.Image;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.eclipse.swt.internal.win32.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">;<br /><br /></span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br /> * 使用此类来生成一个自绘按钮，根据构造中OwnerDrawButtonStyleImp按钮样式的不同画出不一样的按钮<br /> * <br /> *<br /> </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> OwnerDrawButton </span><span style="COLOR: #0000ff">extends</span><span style="COLOR: #000000"> Button<br />{<br />    OwnerDrawButtonStyleImp buttonStyle </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">;<br />    <br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> OwnerDrawButton(Composite parent,OwnerDrawButtonStyleImp buttonStyle){<br />        </span><span style="COLOR: #0000ff">super</span><span style="COLOR: #000000">( parent, SWT.DBCS );<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.buttonStyle </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> buttonStyle;<br />        <br />        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> osStyle </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> OS.GetWindowLong( handle, OS.GWL_STYLE );<br />        osStyle </span><span style="COLOR: #000000">|=</span><span style="COLOR: #000000"> OS.BS_OWNERDRAW;<br />        OS.SetWindowLong( handle, OS.GWL_STYLE, osStyle );<br />    }<br />    <br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setImage(Image image){<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.image </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> image;<br />    }<br />    <br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setText(String text){<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.text </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> text;<br />    }<br /><br />    LRESULT wmDrawChild( </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> wParam, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> lParam )<br />    {<br />        </span><span style="COLOR: #0000ff">super</span><span style="COLOR: #000000">.wmDrawChild( wParam, lParam );<br /><br />        buttonStyle.drawButton(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">,wParam, lParam);<br />        <br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">;<br />    }<br /><br />}<br /></span></div><br />3、实现一个自绘按钮的样式，代码如下：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> org.eclipse.swt.widgets;<br /><br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.eclipse.swt.SWT;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.eclipse.swt.graphics.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.eclipse.swt.internal.win32.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">;<br /><br /></span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br /> * 一个自绘按钮的测试样式，实现自绘按钮绘制接口<br /> * <br /> *<br /> </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> TestButtonStyle </span><span style="COLOR: #0000ff">implements</span><span style="COLOR: #000000"> OwnerDrawButtonStyleImp {<br /><br />    OwnerDrawButton button;<br />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> wParam;<br />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> lParam;<br /><br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> initParam(OwnerDrawButton button,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> wParam, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> lParam){<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.button </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> button;<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.wParam </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> wParam;<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.lParam </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> lParam;<br />    }<br /><br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> drawButton(OwnerDrawButton button,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> wParam, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> lParam){<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.initParam(button, wParam, lParam);<br /><br />        DRAWITEMSTRUCT dis </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> DRAWITEMSTRUCT();<br />        OS.MoveMemory( dis, lParam, DRAWITEMSTRUCT.sizeof );<br /><br />        Rectangle rc </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Rectangle( dis.left, dis.top, dis.right </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> dis.left,dis.bottom </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> dis.top );<br />        Color clr1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Color( button.display, </span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">255</span><span style="COLOR: #000000"> );<br />        Color clr2 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Color( button.display, </span><span style="COLOR: #000000">203</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">224</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">221</span><span style="COLOR: #000000"> );<br />        fillGradientRectangle( dis.hDC, rc, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">, clr1, clr2 );<br />        clr1.dispose();<br />        clr2.dispose();<br /><br />        Rectangle leftBorder </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Rectangle( rc.x, rc.y, </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,rc.height );<br />        Rectangle topBorder </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Rectangle( rc.x, rc.y, rc.width,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> );<br />        Rectangle rightBorder </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Rectangle( rc.width</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, rc.y, </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,rc.height );<br />        Rectangle bottomBorder </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Rectangle( rc.x, rc.height</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, rc.width,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> );<br />        Color clr3 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Color( button.display, </span><span style="COLOR: #000000">69</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">134</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">134</span><span style="COLOR: #000000"> );<br />        fillGradientRectangle( dis.hDC, leftBorder, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">, clr3, clr3 );<br />        fillGradientRectangle( dis.hDC, topBorder, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">, clr3, clr3 );<br />        fillGradientRectangle( dis.hDC, rightBorder, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">, clr3, clr3 );<br />        fillGradientRectangle( dis.hDC, bottomBorder, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">, clr3, clr3 );<br />        clr3.dispose();<br /><br />        leftBorder </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Rectangle( rc.x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, rc.y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,rc.height</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000"> );<br />        topBorder </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Rectangle( rc.x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, rc.y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, rc.width</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> );<br />        rightBorder </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Rectangle( rc.width</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">, rc.y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,rc.height</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000"> );<br />        bottomBorder </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Rectangle( rc.x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, rc.height</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">, rc.width</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> );<br />        Color clr4 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Color( button.display, </span><span style="COLOR: #000000">231</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">231</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">231</span><span style="COLOR: #000000"> );<br />        fillGradientRectangle( dis.hDC, leftBorder, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">, clr4, clr4 );<br />        fillGradientRectangle( dis.hDC, topBorder, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">, clr4, clr4 );<br />        fillGradientRectangle( dis.hDC, rightBorder, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">, clr4, clr4 );<br />        fillGradientRectangle( dis.hDC, bottomBorder, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">, clr4, clr4 );<br />        clr4.dispose();<br />        <br />        <br />        Image image </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> button.getImage();<br />        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> x </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, y </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000"> ,wh </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(image</span><span style="COLOR: #000000">!=</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">){<br />            x </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">;<br />            y </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">;<br />            wh </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> dis.bottom </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> dis.top</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">;<br />            OS.DrawIconEx(dis.hDC, x, y, image.handle, wh, wh, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, dis.hDC, SWT.IMAGE_BMP);<br />        }<br /><br />        SIZE size </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> SIZE();<br />        </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">[] chars </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> button.text.toCharArray();<br />        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> oldFont </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> OS.SelectObject( dis.hDC, button.getFont().handle );<br />        OS.GetTextExtentPoint32W( dis.hDC, chars, chars.length, size );<br />        RECT rcText </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> RECT();<br />        rcText.left </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">wh</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">x;<br />        rcText.top </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.y;<br />        rcText.right </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.x </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> rc.width;<br />        rcText.bottom </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.y </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> rc.height;<br /><br />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> ( (dis.itemState </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> OS.ODS_SELECTED) </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000"> ){<br />            OS.OffsetRect( rcText, </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> );<br />        }<br />        OS.SetBkMode( dis.hDC, OS.TRANSPARENT );<br />        OS.DrawTextW( dis.hDC, chars, </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, rcText, OS.DT_SINGLELINE </span><span style="COLOR: #000000">|</span><span style="COLOR: #000000"> OS.DT_CENTER </span><span style="COLOR: #000000">|</span><span style="COLOR: #000000"> OS.DT_VCENTER );<br /><br />        RECT focusRect </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> RECT();<br />        focusRect.left </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.x;<br />        focusRect.top </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.y;<br />        focusRect.right </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.x </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> rc.width;<br />        focusRect.bottom </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.y </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> rc.height;<br /><br />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(button.isFocusControl()){<br />            focusRect.left </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br />            focusRect.top </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br />            focusRect.right </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.x </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> rc.width</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br />            focusRect.bottom </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.y </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> rc.height</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">;<br />        }<br /><br />        OS.DrawFocusRect(dis.hDC, focusRect);<br /><br />        OS.SelectObject( dis.hDC, oldFont );<br />    }<br /><br /><br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> fillGradientRectangle( </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> handle, Rectangle rc,<br />            </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> vertical, Color clr1, Color clr2 )<br />    {<br />        </span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> hHeap </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> OS.GetProcessHeap();<br />        </span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> pMesh </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> OS.HeapAlloc( hHeap, OS.HEAP_ZERO_MEMORY,<br />                GRADIENT_RECT.sizeof </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> TRIVERTEX.sizeof </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000"> );<br />        </span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> pVertex </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> pMesh </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> GRADIENT_RECT.sizeof;<br /><br />        GRADIENT_RECT gradientRect </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> GRADIENT_RECT();<br />        gradientRect.UpperLeft </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br />        gradientRect.LowerRight </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br />        OS.MoveMemory( pMesh, gradientRect, GRADIENT_RECT.sizeof );<br /><br />        TRIVERTEX trivertex </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> TRIVERTEX();<br />        trivertex.x </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.x;<br />        trivertex.y </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.y;<br />        trivertex.Red </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">short</span><span style="COLOR: #000000">)(clr1.getRed() </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">);<br />        trivertex.Green </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">short</span><span style="COLOR: #000000">)(clr1.getGreen() </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">);<br />        trivertex.Blue </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">short</span><span style="COLOR: #000000">)(clr1.getBlue() </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">);<br />        trivertex.Alpha </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br />        OS.MoveMemory( pVertex, trivertex, TRIVERTEX.sizeof );<br /><br />        trivertex.x </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.x </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> rc.width;<br />        trivertex.y </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> rc.y </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> rc.height;<br />        trivertex.Red </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">short</span><span style="COLOR: #000000">)(clr2.getRed() </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">);<br />        trivertex.Green </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">short</span><span style="COLOR: #000000">)(clr2.getGreen() </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">);<br />        trivertex.Blue </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">short</span><span style="COLOR: #000000">)(clr2.getBlue() </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">);<br />        trivertex.Alpha </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br />        OS.MoveMemory( pVertex </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> TRIVERTEX.sizeof, trivertex, TRIVERTEX.sizeof );<br /><br />        OS.GradientFill( handle, pVertex, </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">, pMesh, </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, vertical </span><span style="COLOR: #000000">?</span><span style="COLOR: #000000"> OS.GRADIENT_FILL_RECT_V : OS.GRADIENT_FILL_RECT_H );<br />        OS.HeapFree( hHeap, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, pMesh );<br />    }<br /><br />}<br /></span></div><br />4、使用自绘按钮，代码如下：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">package</span><span style="COLOR: #000000"> com.gu.control.swt;<br /><br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.eclipse.swt.events.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> org.eclipse.swt.widgets.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">;<br /><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> Window{<br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> Display display </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Display();;<br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> Shell shell;<br />    <br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Window(){<br />        shell </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Shell(display);<br />        shell.setLayout(</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">);<br />        init();<br />        <font color="#008000">//使窗口永远在最前面<br /></font>        OS.SetWindowPos(shell.handle , OS.HWND_TOPMOST, 0 , 0 , 800 , 600 , SWT.NULL);<br />        shell.open();<br />        </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">shell.isDisposed()){<br />            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">display.readAndDispatch()){<br />                display.sleep();<br />            }<br />        }<br />        display.dispose();<br />    }<br />    <br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> init(){<br />        Button button;<br />        <br />        button </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> OwnerDrawButton(shell,</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> TestButtonStyle());<br />        button.setBounds(new Rectangle(20,20,180,25));<br />        button.setText("Click Me");<br />        button.setImage(image);<br /></span><span style="COLOR: #000000"><br />        button.addSelectionListener(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> SelectionListener(){<br />                </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> widgetSelected(SelectionEvent event){<br />                    shell.setText(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">你好啊，你点了自绘按钮了!</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />                }<br />                </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> widgetDefaultSelected(SelectionEvent event){<br />                    widgetSelected(event);<br />                }<br />            }<br />        );<br /><br /><br />    }<br />}<br /></span></div><br />5、效果：<img height="94" alt="6.JPG" src="http://www.blogjava.net/images/blogjava_net/tianzhihua/6.JPG" width="269" border="0" /><img height="94" alt="7.JPG" src="http://www.blogjava.net/images/blogjava_net/tianzhihua/7.JPG" width="269" border="0" /><br /><img height="1" src="/WebResource.axd?d=pLXXeGbWF7eXU8SMs2-GFZvUWY2JNH05dFx5YzJhGUYAYJAFEaTEq36NAhTPy7_KekvzDFwt8wvQWdByvJIGWdEq6x2KpKD80&amp;t=633043190666685000" width="1" /><img src ="http://www.blogjava.net/tianzhihua/aggbug/99703.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/tianzhihua/" target="_blank">gyb</a> 2007-02-13 15:34 <a href="http://www.blogjava.net/tianzhihua/articles/99703.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SWT中操作ActiveX控件</title><link>http://www.blogjava.net/tianzhihua/articles/98829.html</link><dc:creator>gyb</dc:creator><author>gyb</author><pubDate>Thu, 08 Feb 2007 09:32:00 GMT</pubDate><guid>http://www.blogjava.net/tianzhihua/articles/98829.html</guid><description><![CDATA[
		<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080"> 1</span>
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">package</span>
				<span style="COLOR: #000000"> com;<br /></span>
				<span style="COLOR: #008080"> 2</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 3</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080"> 4</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.eclipse.swt.</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">;<br /></span>
				<span style="COLOR: #008080"> 5</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.eclipse.swt.layout.</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">;<br /></span>
				<span style="COLOR: #008080"> 6</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.eclipse.swt.widgets.</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">;<br /></span>
				<span style="COLOR: #008080"> 7</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.eclipse.swt.ole.win32.</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">;<br /></span>
				<span style="COLOR: #008080"> 8</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080"> 9</span>
				<span style="COLOR: #000000">
						<img id="Codehighlighter1_167_1719_Open_Image" onclick="this.style.display='none'; Codehighlighter1_167_1719_Open_Text.style.display='none'; Codehighlighter1_167_1719_Closed_Image.style.display='inline'; Codehighlighter1_167_1719_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_167_1719_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_167_1719_Closed_Text.style.display='none'; Codehighlighter1_167_1719_Open_Image.style.display='inline'; Codehighlighter1_167_1719_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> ActiveX </span>
				<span id="Codehighlighter1_167_1719_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.blogjava.net/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_167_1719_Open_Text">
						<span style="COLOR: #000000">{<br /></span>
						<span style="COLOR: #008080">10</span>
						<span style="COLOR: #000000">
								<img id="Codehighlighter1_210_371_Open_Image" onclick="this.style.display='none'; Codehighlighter1_210_371_Open_Text.style.display='none'; Codehighlighter1_210_371_Closed_Image.style.display='inline'; Codehighlighter1_210_371_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_210_371_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_210_371_Closed_Text.style.display='none'; Codehighlighter1_210_371_Open_Image.style.display='inline'; Codehighlighter1_210_371_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">private</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">static</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">final</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">class</span>
						<span style="COLOR: #000000"> FLASH_CONTROL</span>
						<span id="Codehighlighter1_210_371_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.blogjava.net/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_210_371_Open_Text">
								<span style="COLOR: #000000">{<br /></span>
								<span style="COLOR: #008080">11</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">private</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">static</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">final</span>
								<span style="COLOR: #000000"> String PROG_ID </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">ShockwaveFlash.ShockwaveFlash</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">;<br /></span>
								<span style="COLOR: #008080">12</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										<br />
								</span>
								<span style="COLOR: #008080">13</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_323_368_Open_Image" onclick="this.style.display='none'; Codehighlighter1_323_368_Open_Text.style.display='none'; Codehighlighter1_323_368_Closed_Image.style.display='inline'; Codehighlighter1_323_368_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_323_368_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_323_368_Closed_Text.style.display='none'; Codehighlighter1_323_368_Open_Image.style.display='inline'; Codehighlighter1_323_368_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">private</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">static</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">final</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">class</span>
								<span style="COLOR: #000000"> PROPERTY</span>
								<span id="Codehighlighter1_323_368_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.blogjava.net/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_323_368_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080">14</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
										<span style="COLOR: #0000ff">private</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">static</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">final</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> MOVIE </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">120</span>
										<span style="COLOR: #000000">;<br /></span>
										<span style="COLOR: #008080">15</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">16</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
						</span>
						<span style="COLOR: #008080">17</span>
						<span style="COLOR: #000000">
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
						</span>
						<span style="COLOR: #008080">18</span>
						<span style="COLOR: #000000">
								<img id="Codehighlighter1_414_1717_Open_Image" onclick="this.style.display='none'; Codehighlighter1_414_1717_Open_Text.style.display='none'; Codehighlighter1_414_1717_Closed_Image.style.display='inline'; Codehighlighter1_414_1717_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_414_1717_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_414_1717_Closed_Text.style.display='none'; Codehighlighter1_414_1717_Open_Image.style.display='inline'; Codehighlighter1_414_1717_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">static</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> main(String[] args) </span>
						<span id="Codehighlighter1_414_1717_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.blogjava.net/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_414_1717_Open_Text">
								<span style="COLOR: #000000">{<br /></span>
								<span style="COLOR: #008080">19</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">final</span>
								<span style="COLOR: #000000"> Display display </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> Display();<br /></span>
								<span style="COLOR: #008080">20</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  Shell shell </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> Shell(display);<br /></span>
								<span style="COLOR: #008080">21</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  shell.setLayout(</span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> FillLayout());<br /></span>
								<span style="COLOR: #008080">22</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  OleControlSite controlSite;<br /></span>
								<span style="COLOR: #008080">23</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  OleFrame frame </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> OleFrame(shell, SWT.NONE);<br /></span>
								<span style="COLOR: #008080">24</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  controlSite </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> OleControlSite(frame, SWT.NONE, FLASH_CONTROL.PROG_ID);<br /></span>
								<span style="COLOR: #008080">25</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />   <br /></span>
								<span style="COLOR: #008080">26</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);<br /></span>
								<span style="COLOR: #008080">27</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										<br />
								</span>
								<span style="COLOR: #008080">28</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">final</span>
								<span style="COLOR: #000000"> OleAutomation oleActiveX </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> OleAutomation(controlSite);<br /></span>
								<span style="COLOR: #008080">29</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  controlSite.dispose();<br /></span>
								<span style="COLOR: #008080">30</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_841_845_Open_Image" onclick="this.style.display='none'; Codehighlighter1_841_845_Open_Text.style.display='none'; Codehighlighter1_841_845_Closed_Image.style.display='inline'; Codehighlighter1_841_845_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_841_845_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_841_845_Closed_Text.style.display='none'; Codehighlighter1_841_845_Open_Image.style.display='inline'; Codehighlighter1_841_845_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">try</span>
								<span style="COLOR: #000000"> </span>
								<span id="Codehighlighter1_841_845_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.blogjava.net/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_841_845_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080">31</span>
										<span style="COLOR: #000000">
												<img id="Codehighlighter1_867_939_Open_Image" onclick="this.style.display='none'; Codehighlighter1_867_939_Open_Text.style.display='none'; Codehighlighter1_867_939_Closed_Image.style.display='inline'; Codehighlighter1_867_939_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_867_939_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_867_939_Closed_Text.style.display='none'; Codehighlighter1_867_939_Open_Image.style.display='inline'; Codehighlighter1_867_939_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  }</span>
								</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">catch</span>
								<span style="COLOR: #000000"> (Exception e) </span>
								<span id="Codehighlighter1_867_939_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.blogjava.net/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_867_939_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080">32</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />   System.out.println(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">Unable to open activeX control</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">);<br /></span>
										<span style="COLOR: #008080">33</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
										<span style="COLOR: #0000ff">return</span>
										<span style="COLOR: #000000">;<br /></span>
										<span style="COLOR: #008080">34</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">35</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										<br />
								</span>
								<span style="COLOR: #008080">36</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  shell.open();<br /></span>
								<span style="COLOR: #008080">37</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  <br /></span>
								<span style="COLOR: #008080">38</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_1029_1062_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1029_1062_Open_Text.style.display='none'; Codehighlighter1_1029_1062_Closed_Image.style.display='inline'; Codehighlighter1_1029_1062_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_1029_1062_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1029_1062_Closed_Text.style.display='none'; Codehighlighter1_1029_1062_Open_Image.style.display='inline'; Codehighlighter1_1029_1062_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  oleActiveX.setProperty(FLASH_CONTROL.PROPERTY.MOVIE, </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> Variant[]</span>
								<span id="Codehighlighter1_1029_1062_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.blogjava.net/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_1029_1062_Open_Text">
										<span style="COLOR: #000000">{</span>
										<span style="COLOR: #0000ff">new</span>
										<span style="COLOR: #000000"> Variant(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">file:///t|/ee.flv</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">)}</span>
								</span>
								<span style="COLOR: #000000">)<br /></span>
								<span style="COLOR: #008080">39</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										<br />
								</span>
								<span style="COLOR: #008080">40</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_1068_1576_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1068_1576_Open_Text.style.display='none'; Codehighlighter1_1068_1576_Closed_Image.style.display='inline'; Codehighlighter1_1068_1576_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_1068_1576_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1068_1576_Closed_Text.style.display='none'; Codehighlighter1_1068_1576_Open_Image.style.display='inline'; Codehighlighter1_1068_1576_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span>
								<span id="Codehighlighter1_1068_1576_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span>
								<span id="Codehighlighter1_1068_1576_Open_Text">
										<span style="COLOR: #008000">/*</span>
										<span style="COLOR: #008000">得到ActiveX中的方法和属性<br /></span>
										<span style="COLOR: #008080">41</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />   * for(int i=-1000; i&lt;10000; i++){<br /></span>
										<span style="COLOR: #008080">42</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />   try{<br /></span>
										<span style="COLOR: #008080">43</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    String name = oleActiveX.getName(i);<br /></span>
										<span style="COLOR: #008080">44</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    if(name!=null){<br /></span>
										<span style="COLOR: #008080">45</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     System.out.print(""+i+"  ");<br /></span>
										<span style="COLOR: #008080">46</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     <br /></span>
										<span style="COLOR: #008080">47</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     Variant v = oleActiveX.getProperty(i);<br /></span>
										<span style="COLOR: #008080">48</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     if(v==null){<br /></span>
										<span style="COLOR: #008080">49</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />      System.out.print("method       :"+name+":");<br /></span>
										<span style="COLOR: #008080">50</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />      System.out.print("     ");<br /></span>
										<span style="COLOR: #008080">51</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     }else{<br /></span>
										<span style="COLOR: #008080">52</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />      System.out.print("property     :"+name+":");<br /></span>
										<span style="COLOR: #008080">53</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />      System.out.print(v);<br /></span>
										<span style="COLOR: #008080">54</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     }<br /></span>
										<span style="COLOR: #008080">55</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
										</span>
										<span style="COLOR: #008080">56</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     System.out.println("    "+oleActiveX.getDocumentation(i));<br /></span>
										<span style="COLOR: #008080">57</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    }<br /></span>
										<span style="COLOR: #008080">58</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />   }catch(Exception e){}<br /></span>
										<span style="COLOR: #008080">59</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span>
										<span style="COLOR: #008000">*/</span>
								</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">60</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										<br />
								</span>
								<span style="COLOR: #008080">61</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_1609_1669_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1609_1669_Open_Text.style.display='none'; Codehighlighter1_1609_1669_Closed_Image.style.display='inline'; Codehighlighter1_1609_1669_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_1609_1669_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1609_1669_Closed_Text.style.display='none'; Codehighlighter1_1609_1669_Open_Image.style.display='inline'; Codehighlighter1_1609_1669_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">while</span>
								<span style="COLOR: #000000"> (</span>
								<span style="COLOR: #000000">!</span>
								<span style="COLOR: #000000">shell.isDisposed()) </span>
								<span id="Codehighlighter1_1609_1669_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.blogjava.net/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_1609_1669_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080">62</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />   </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (</span>
										<span style="COLOR: #000000">!</span>
										<span style="COLOR: #000000">display.readAndDispatch())<br /></span>
										<span style="COLOR: #008080">63</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    display.sleep();<br /></span>
										<span style="COLOR: #008080">64</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">65</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  oleActiveX.dispose();<br /></span>
								<span style="COLOR: #008080">66</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />  display.dispose();<br /></span>
								<span style="COLOR: #008080">67</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
						</span>
						<span style="COLOR: #008080">68</span>
						<span style="COLOR: #000000">
								<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080">69</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
<img src ="http://www.blogjava.net/tianzhihua/aggbug/98829.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/tianzhihua/" target="_blank">gyb</a> 2007-02-08 17:32 <a href="http://www.blogjava.net/tianzhihua/articles/98829.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>