
COMPUTER ENGINEERING
1999 25 12 vol.25 No.12 1999



VBеWindows APIǿý

VBһȫλıԣ͵Ӧó򣬵ǣЩҲע⣬VBһЩδֱֵ֧Ӧ߳ӴЩ֧֡I/0˿ڵַԼλͼ㶼VBһɲ֡ʵVBе๦ǹʡȥģΪǺ״Windows APIеõVBԱ漰Windows APIǺźġAPIǳԱĲƱչʾAPIýеɫһɫ嶯ơ
1 оVBеɫ
ҪȤӾЧԲ˽ʹɫWindowsVBԼдVB˴صɫϸڣֻͼƬʾλͼVBWindowsɫɫ塣VBװһԼĵɫλͼʱԶװͻõɫ塣װһλͼɫٴθı䣬һжں̨еġȻҪVBܣû׼ͼʱסɫ͵ɫӵơ磬ҪָVBòͬĵɫͬʱ׼ȷʾͼԣҪͼִжЧʹӾȤζ˽WindowsͼιɫģӦֱɫ򽻵
⣬VBṩһΪRGB( )ĺѡ񱳾ıǰɫRGB( )ɫΪڲͬ½仯ʽȱʡRGB( )Զɫʾɫı20ִ̬ɫʹ֮ɺ졢̡ɫֵָɫվھʾһĵطɫһɫ޵ķƣʵͼβرáҪʾһɫ򣬻ῴһһɫƽȹɵɫװɫʱɴɫˣΪ˻ñȶɫõʾɫ塣VBûṩӵɫѡָɫķʹWindows API
2 APIɫ
Windows API( رGDI)ܶWindowsɫʹõĺVBԱܹʹһЩ
APIͼһɫʱõɫֵ3ֽڣһһֵĵ4ֽڡ4ֽڵɫֵΪCOLORREFλֽڰԪصֵλֽڰһ־ʾֵǷΪһֶɫһֵɫƥɫһȷĵɫֽڵֵȷʹ3ֽѡɫ1ʾ
1 ѡɫ
ֽڽ
&H00ڸƶʱ,Windows20ֱɫ,RGBɫֵ
&H01λָֽ˵ɫĿֵ,ɫֵ
&H02WindowsѰӽƥĵɫֵ,ƥɫ3ֽ֬к졢̡3ԪؾɫRGBֵ

ڵɫ嶯еAPIУAnimatePalette CreatePaletteCreateSolidBrushDeleteObjectRectangleGetStockObjectRealizePaletteSelectObject SelectPalette
3 ɫ嶯
öϵͳɫֱӷʣʵĳЩ͵Ķɫ嶯һʹʾɫܿطʽתļּΪɫԱ仯ͨƣܲ˶ļּʹûʹøڲԴͶ֡Ҳģˮ󡢹߱仯˶塣
ʹǰᵽЩWindows APIģҺƪƣֻҪּ˵£
(1) һļΪWaterFlow.FrmĴ壬ûпɼĿơ
(2) ȫ˵
WaterFlow.BASеȫ˵
Type PALETTEENTRY
peRedAsByte
peGreenAsByte
peBlue AsByte
peFLAGSAsByte
End Type
Type LOGPALETTE
palversionAsInteger
palNumEntries AsInteger
palPalEntry(4)  AsPALETTEENTRY
End Type
Global Const BLACK_BRUSH = 4
Global Const PC_PESERVED = &H1
(3)봰弶˵
ǰгAPIʡԣ
 Dim hSystemPalette As Long
 Dim hCurrentPalette As Long 
 Dim PaletteEnties (4) As PALETTENTRY 
 Dim hPaintBrush(3) As Long 
 Dim LogicalPalette As LOGPALETTE
(4) 4¼̣Form-Load Form-Paint Form-Resize(ʡ)Form-QueryUnload(ʡ) 
Form-Loadйһ4ɫ߼ɫ壬4ɫΪͬǳɫ 
For Colorlndex = 0 To 3 
Logicalpalette.palPalEntry(Colorlndex).peRed=0 
Logicalpalette.palPalEntry(Colorlndex).peGreen=0 
Logicalpalette.palPalEntry(Colorlndex).peBlue= 
127+ Colorlndex*128/3
Next Colorlndex
hCurrentPalette=CreatePalette (Logicalpalette)
Form-Paint¼УȽ4ɫˢӣȻFormұ߻һľ
hSystemPalette= SelectPalette (WaterFlowForm.hDC,hCurrentPalette,False)
Dummy=RealizePalette (WaterFlowForm.hDC)
For Colorlndex=0 To 3 
hPaintBrush(ColorIndex)=CreateSolidBrush(& 
H1000000 or ColorIndex)
Next ColorIndex
BoxWidth=WaterFlowForm.ScaleWidth/20
BoxHeight=WaterFlowForm.ScaleHeight/20
WaterFlowForm.CurrentX=BoxWidth*1.5
TopPos=ScaleHeight/2
Do While CurrentX<(ScaleWidth-Boxwidth*2) 
Dummy=SelectObject(WaterFlowForm.hDC, hPaintBrush(Co-lorIndex)) 
Dummy=Rectangle(WaterFlowForm.hDC,CurrentX,
TopPosCurrentX+Boxwidth,TopPos+BoxHeight) 
ColorIndex=ColorIndex+1 
ColorIndex=ColorIndex Mod 4Loop
(5) 붨ʱ¼
ڶʱ¼УForѭ佫4ɫԪصɫеɫƶһλãԴģƶȻҲ޸佫ƶ
For ColorIdex=4 To 1 Step -1 
LogicalPalette.palPalEntry(ColorIndex)= 
LogicalPalette.palPalEntry(ColorIndex-1)
Next ColorIndex
LogicalPalette.palPalEntry(0)=LogicalPalette. pal
PalEntry(4)
AnimatePalette hCurrentPalette,0,4,LogicalPalette. 
palPalEntry(0)
  ɫ嶯ͨAnimatePalette APIģAnimatePaletteı߼ɫеɫֱ޸ϵͳɫ壬ʹЩı伸˲ͳĻϡTimerIntervalֵԸı䶯ٶȡ
ߵλʦѧϵ710062
ο
1 ()Jerke N. Visual Basic 4 API. еҵ 磬1997
2 ()Appleman D. Visual Basic 5.0 Win32API Աָ.  еҵ,1998
3 ()Ben Ezzell. Windows32λָ. 廪ѧ 磬1998
