This is some sample code in VB for displaying text and icons in a HUD, it also shows howto click and drag move the HUD
copy/paste this into a vb6 ActiveX DLL project
Reference the following:
Decal 1.0 Type Library
Decal Controls Type Library
Decal Plugins Type Library
|
Option Explicit Implements IPlugin Implements IRenderSink 'used to draw the HUD Implements IWindowsMessageSink 'used for mouse control Private ViewSchema As String Private MainView As View Private PluginSite As IPluginSite Private PluginID As Long Private WithEvents btn1 As DecalControls.PushButton Const LMBTNUP = &H202 'left mouse button up Const LMBTNDOWN = &H201 'left mouse button down Const MOUSEMOVE = &H200 'mouse move Type POINTAPI x As Long y As Long End Type Private myCanvas As DecalPlugins.ICanvas 'your canvas Private myRect As DecalPlugins.tagRECT 'the location of the sides of your canvas Private myPoint As DecalPlugins.tagPOINT 'where on your canvas you will put text/icons Dim pos As POINTAPI 'i like to reference all points to this, so to change the location of the HUD you just change pos.x and pos.y 'these are pretty self explaining Dim isMouseOnCanvas As Boolean Dim mouseDownPos As POINTAPI Dim moveToPos As POINTAPI Dim checkPos As POINTAPI 'this funtion puts the x/y points of the mouse into lpPoint Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long 'this function converts your mouse pos to the pos on the client (makes it work in windowed mode) Private Declare Function ScreenToClient Lib "user32" (ByVal HWND As Long, lpPoint As POINTAPI) As Long Private Sub btn1_Accepted(ByVal nID As Long) Call floatexample End Sub Private Sub Class_Initialize() ViewSchema = "<?xml version=""1.0""?>" & _ "<view icon=""4207"" title=""Float"">" & _ "<control progid=""DecalControls.FixedLayout"">" & _ "<control name=""btn1"" progid=""DecalControls.PushButton"" left=""5"" top=""5"" width=""100"" height=""20"" text=""Push Me""/>" & _ "</control>" & _ "</view>" End Sub Private Property Get IPlugin_FriendlyName() As String IPlugin_FriendlyName = "float v" & App.Major & "." & App.Minor & "." & App.Revision End Property Private Sub IPlugin_Initialize(ByVal pSite As IPluginSite, ByVal nID As Long) PluginID = nID Set PluginSite = pSite Set MainView = PluginSite.LoadView(ViewSchema) Set btn1 = MainView.Control("btn1") 'these points are easily seeable places, although you can make them whatever you want pos.x = 100 pos.y = 150 End Sub Private Sub IPlugin_Terminate() Set MainView = Nothing Set PluginSite = Nothing End Sub Private Function wtcw(message As String) PluginSite.RawWriteToChatWindow "Float: ", 7 PluginSite.WriteToChatWindow message, 5 End Function Private Sub IRenderSink_CustomDraw(ByVal pCanvas As DecalPlugins.ICanvas) 'this is called like 1000000000000000000000000000000000 times a sec so don't put much here If pCanvas.WasLost = True Then floatexample 'if you have more than one canvas, you need another one of these with the corresponding info Call pCanvas.Blt(myRect, myCanvas, myPoint) End Sub Private Sub floatexample() Dim font As DecalPlugins.IFontCache Dim szcanvas As DecalControls.tagSIZE Dim szicon As DecalControls.tagSIZE Dim icons As DecalPlugins.IIconCache szcanvas.cx = 150 + pos.x 'make canvas 150 wide szcanvas.cy = 200 + pos.y 'make canvas 200 tall 'most icons are 16x16 szicon.cx = 16 szicon.cy = 16 myRect.Top = pos.y myRect.Left = pos.x myRect.bottom = szcanvas.cy myRect.Right = szcanvas.cx myPoint.x = pos.x + 2 '+2 gives a little gap for looks :) myPoint.y = pos.y Set myCanvas = PluginSite.CreateCanvas(szcanvas) 'creates canvas Set icons = PluginSite.GetIconCache(szicon) 'creates memory for icons Set font = PluginSite.CreateFont("Times New Roman", 16, 1) 'sets the font type/size (1 should always be 1) myCanvas.Fill myRect, vbBlack 'make the canvas black, or any other color, clear is vbCyan Call font.DrawText(myPoint, "some text", vbWhite, myCanvas) 'point, the text, color, which canvas myPoint.y = myPoint.y + 20 'drop down roughly the size of 16pt font Call font.DrawText(myPoint, "this text is below", vbWhite, myCanvas) 'you get the idea myPoint.y = myPoint.y + 20 'same Call icons.DrawIcon(myPoint, &H6001383, 0, myCanvas) 'point, hex of icon, always 0, which canvas 'set stuff back to defaults myPoint.x = pos.x myPoint.y = pos.y 'clear font/icons Set font = Nothing Set icons = Nothing End Sub Private Function IWindowsMessageSink_WindowMessage(ByVal HWND As Long, ByVal uMsg As Integer, ByVal wParam As Long, ByVal lParam As Long) As Boolean Select Case uMsg Case LMBTNDOWN Call GetCursorPos(checkPos) 'gets the position the mouse went down at ScreenToClient PluginSite.HWND, checkPos 'converts it to client pos 'checks if its on the canvas, the -25 in pos.y is for the health/stam/mana bar If checkPos.x > pos.x And checkPos.x < pos.x + 150 And checkPos.y - 25 > pos.y And checkPos.y - 25 < pos.y + 200 Then isMouseOnCanvas = True Call GetCursorPos(mouseDownPos) End If Case MOUSEMOVE If isMouseOnCanvas = True Then 'checks if mouse is held down on canvas Call GetCursorPos(moveToPos) 'gets the new position pos.x = pos.x + (moveToPos.x - mouseDownPos.x) 'changes pos to relative change in mouse pos pos.y = pos.y + (moveToPos.y - mouseDownPos.y) 'same If pos.x < 0 Then pos.x = 0 'makes sure you don't go off the screen to the left/top If pos.y < 0 Then pos.y = 0 'depending on inventory open/chat up you can't tell right/bottom Call GetCursorPos(mouseDownPos) 'get new pos Call floatexample 'draw your HUD at new location End If Case LMBTNUP If isMouseOnCanvas = True Then 'if mouse is down on your canvas isMouseOnCanvas = False 'self explaining End If End Select End Function Private Sub IWindowsMessageSink_WindowMessageEnd() End Sub |