Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Forms Code Examples

Set the mouse cursor for a form

Set the mouse cursor for a form To change the cursor for a form use the following routine: Private Declare Function LoadCursorFromFile Lib "user32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long Private Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long Public Enum eCursorType ecAppStarting = 32650 'The application starting (arrow and hourglass) cursor. ecCross = 32515 'The cross-shaped cursor. ecIBeam = 32513 'The text selection (I-beam) cursor. ecIcon = 32641 'The empty icon cursor (Win NT only). ecNo = 32648 'The circle with slash through it cursor. ecNormal = 32512 'The normal arrow cursor. ecSize = 32640 'The four-arrow resize/move cursor (Win NT only). ecSizeAll = 32646 'The four-arrow resize/move cursor. ecSizeNESW = 32643 'The double-arrow resize/move cursor pointing to the upper-right and lower-left. ecSizeNS = 32645 'The double-arrow resize/move cursor pointing up and down. ecSizeNWSE = 32642 'The double-arrow resize/move cursor pointing to the upper-left and lower-right. ecSizeWE = 32644 'The double-arrow resize/move cursor pointing left and right. ecUp = 32516 'The up arrow cursor. ecWait = 32514 'The waiting (hourglass) cursor. End Enum 'Purpose : Sets the curson for a specified from, from a file or resource. 'Inputs : lhwndForm The handle to the form. ' [sCursorPath] The path to a cursor. ' [lCursorHwnd] The handle to a cursor. ' [CursorType] A enumerated cursor type. 'Outputs : Returns the handle of the original cursor (to allow the cursor to be reset). 'Notes : Specify one of either the sCursorPath,lCursorHwnd or CursorType parameters. Function FormCursorSet(lhwndForm As Long, Optional sCursorPath As String, Optional lCursorHwnd As Long, Optional lCursorType As eCursorType) As Long Const GCL_HCURSOR As Long = (-12) If Len(Dir$(sCursorPath)) > 0 And Len(sCursorPath) > 0 Then 'Load the cursor from file lCursorHwnd = LoadCursorFromFile(sCursorPath) FormCursorSet = SetClassLong(lhwndForm, GCL_HCURSOR, lCursorHwnd) ElseIf lCursorHwnd Then 'Use the specified cursor handle FormCursorSet = SetClassLong(lhwndForm, GCL_HCURSOR, lCursorHwnd) ElseIf lCursorType Then 'Use the specified cursor types lCursorHwnd = LoadCursor(ByVal 0&, CLng(lCursorType)) FormCursorSet = SetClassLong(lhwndForm, GCL_HCURSOR, lCursorHwnd) End If End Function