home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 3_2004-2005.ISO / Data / Zips / VB_API_cod1852392132005.psc / DefaultProgSubsFunctionsMenu.cpd < prev   
Encoding:
Text File  |  2004-04-27  |  12.3 KB  |  378 lines

  1.  
  2. menucaption: Simple Text to Screen
  3.  
  4. Const DT_WORDBREAK = &H10
  5.  
  6. Enum TextAlign
  7.     DT_LEFT = &H0
  8.     DT_RIGHT = &H2
  9.     DT_CENTER = &H1
  10. End Enum
  11.  
  12. Private Type RECT
  13.     Left As Long
  14.     Top As Long
  15.     Right As Long
  16.     Bottom As Long
  17. End Type
  18. Private dec_deskMsgRect As RECT
  19. Private TXT_COLOR As Long
  20.  
  21. Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
  22. Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
  23. Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
  24. Private Declare Function InvalidateRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT, ByVal bErase As Long) As Long
  25. Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  26.  
  27. '----------------------------------------------------------------------
  28. '   INPUTS: |
  29. '  RETURNS: |
  30. ' COMMENTS: |draw simple text message to the screen/desktop
  31. '----------------------------------------------------------------------
  32. Sub DrawTextToScreen(sDeskMsg$, iTextLeft%, iTextRight%, iTextTop%, iTextBottom%, _
  33.                                   Optional TXT_ALIGN As TextAlign = DT_CENTER, _
  34.                                   Optional TxtColor& = vbBlack)
  35.  
  36. 'VARIABLES:
  37.       Dim DeskDc&
  38. 'CODE:
  39.       'erase text before drawing new
  40.       Call EraseTextDrawnToScreen
  41.       DoEvents
  42.       'desktop pallette
  43.       DeskDc = GetWindowDC(0)
  44.       'set the textcolor
  45.       SetTextColor DeskDc, TxtColor
  46.       'rectangle where we draw the text
  47.       SetRect dec_deskMsgRect, (iTextLeft% / Screen.TwipsPerPixelX), _
  48.                               (iTextTop% / Screen.TwipsPerPixelY), _
  49.                               (iTextRight% / Screen.TwipsPerPixelX), _
  50.                               (iTextBottom% / Screen.TwipsPerPixelY)
  51.        'print info text to screen
  52.       DrawText DeskDc, sDeskMsg, Len(sDeskMsg), _
  53.                               dec_deskMsgRect, _
  54.                               DT_WORDBREAK Or TXT_ALIGN
  55. 'END CODE:
  56.  
  57. End Sub
  58. '----------------------------------------------------------------------
  59. '   INPUTS: |
  60. '  RETURNS: |
  61. ' COMMENTS: |erase that message by invalidating whats inside rect
  62. '----------------------------------------------------------------------
  63. Sub EraseTextDrawnToScreen()
  64. '
  65.        InvalidateRect 0, dec_deskMsgRect, True
  66. End Sub
  67.  
  68.  
  69.  
  70.  
  71. menucaption: Menu Handling Shell
  72.  
  73.  
  74. Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
  75. Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
  76.  
  77.  
  78. '----------------------------------------------------------------------
  79. '   INPUTS: |
  80. '  RETURNS: |
  81. ' COMMENTS: |
  82. '----------------------------------------------------------------------
  83. Sub Menu(YourFormsHwnd&, mnuIndex&)
  84. '
  85. 'VARIABLES:
  86.   Dim mnuTopHwnd&, mnuSubHwnd&
  87.         
  88. 'CODE:
  89.         'forms handle
  90.         mnuTopHwnd = GetMenu(YourFormsHwnd&)
  91.         
  92.         'submenu
  93.         mnuSubHwnd = GetSubMenu(mnuTopHwnd, mnuIndex&)
  94. 'END CODE:
  95.  
  96. End Sub
  97.  
  98.  
  99. menucaption: Check/Uncheck Menu Items
  100.  
  101. Sub ToggleMenuOn(MenuNameCheck As Menu, ParamArray MenuNamesUncheck())
  102. 'VARIABLES:
  103.    Dim i%
  104.  'CODE:  
  105.        ' untoggle items in menuNameUnchecked
  106.        For i = 0 To UBound(MenuNamesUncheck)
  107.              MenuNamesUncheck(i).Checked = False
  108.        Next i
  109.        
  110.        ' toggle menu item on
  111.        MenuNameCheck.Checked = True
  112. 'END CODE:
  113. End Sub
  114.  
  115.  
  116.  
  117. menucaption: Enable/Disable Show/Hide Control Group
  118.  
  119.  
  120.  
  121. Public Enum enCtlAction
  122.         Enable_Disable = 0
  123.         Show_Hide = 1
  124. End Enum
  125.  
  126.  
  127.  
  128. '----------------------------------------------------------------------
  129. '   INPUTS: | NONE
  130. '  RETURNS: | NONE
  131. ' COMMENTS: | to enable/disable or show/hide a group of
  132. '             controls at once with a single line code
  133. '----------------------------------------------------------------------
  134. Public Sub Show_EnableControls(What As enCtlAction, bTrue As Boolean, ParamArray CtlNames())
  135.  
  136. 'VARIABLES:
  137.    Dim i%
  138. 'CODE:
  139.        For i = LBound(CtlNames) To UBound(CtlNames)
  140.           If What = Enable_Disable Then
  141.                CtlNames(i).Enabled = bTrue
  142.           Else
  143.                CtlNames(i).Visible = bTrue
  144.           End If
  145.        Next i
  146. 'END CODE:
  147. End Sub
  148.  
  149.  
  150.  
  151. menucaption: File Load Data
  152.  
  153. '----------------------------------------------------------------------
  154. '   INPUTS: |sPath:path to the file that holds variabled for our program
  155. '  RETURNS: |
  156. ' COMMENTS: |
  157. '----------------------------------------------------------------------
  158. Function func_FileLoadData(sPath As String) As Variant()
  159. 'VARIABLES:
  160.    Dim s$
  161.    Dim fFile%, i%
  162.    Dim arr()   As Variant
  163. 'CODE:
  164.    
  165.       fFile = FreeFile
  166.   '!!!#### IMPORTANT !!! : The first time the person runs the prog,
  167.  '                         the file to load has not yet been created.
  168.  '      YOU MUST:
  169.  '                   1)hand create the file, which gives
  170.  '                      you the flexibility of presetting prog
  171.  '                      defaults to whatever you wish
  172.  '         OR:
  173.  '                   2)user error handling in this sub, using
  174.  '                     API call "CreateFile"
  175.  '                     (in the "API miscellaneous" menu)
  176.  '                     followed by  "exit sub"
  177.       Open sPath For Input As #fFile
  178.              Do Until EOF(fFile)
  179.                 Input #fFile, s
  180.                 ReDim Preserve arr(i)
  181.                 arr(i) = s
  182.                 i = (i + 1)
  183.             Loop
  184.       Close fFile
  185.       
  186.       func_FileLoadData = arr
  187. 'END CODE:
  188.       
  189.       'SAMPLE USEAGE___________________________
  190.       'say your program has two variable values
  191.       'you want filled from file(bTimerEnabled, intTimerCount)
  192.                ':
  193.       'Private Sub Form_Load_____________________
  194.        ' Dim arr()   As Variant
  195.        ' Dim i       as integer
  196.        '
  197.        '  arr = func_FileLoadData("strWhateverPathYouWant")
  198.        '
  199.        '  For i = LBound(arr) To UBound(arr)
  200.        '      Select Case i
  201.        '          Case Is = 0
  202.        '                bTimerEnabled = Cbool(arr(i))
  203.        '          Case =1
  204.        '                intTimerCount = Cint(arr(i))
  205.        '      End Select
  206.        '  Next i
  207.        'End Sub____________________________________
  208. End Function
  209.  
  210.  
  211. menucaption: File Save Data
  212.  
  213.  
  214. '----------------------------------------------------------------------
  215. '   INPUTS: |sPath: path saving program data to
  216. '            varVals: the array of program variables your saving to file
  217. '  RETURNS: |
  218. ' COMMENTS: |
  219. '----------------------------------------------------------------------
  220. Sub sub_FileSaveData(sPath As String, ParamArray varVals())
  221. 'VARIABLES:
  222.   Dim fFile%, i%
  223. 'CODE:
  224.       fFile = FreeFile
  225.       
  226.       Open sPath For Output As #fFile
  227.            'each variable value to be saved
  228.            '(varVals) saved on its own line
  229.            For i = 0 To UBound(varVals)
  230.                Write #fFile, varVals(i)
  231.            Next i
  232.       Close fFile
  233. 'END CODE:
  234.       'SAMPLE USAGE__________________________
  235.            'say you have two variables from
  236.            'your program you want to filesave
  237.               'bTimerEnabled
  238.               'intTimerCount
  239.               ':
  240.       'Private Sub Form_Unload ____________________
  241.       '
  242.       '   call sub_FileSaveData("strWhateverPathYouWant", _
  243.       '                        bTimerEnabled, intTimerCount)
  244.       'End Sub_____________________________________
  245. End Sub
  246.  
  247.  
  248.  
  249. menucaption: Flatten Control
  250.  
  251. Const GWL_EXSTYLE = -20
  252. Const WS_EX_STATICEDGE = &H20000
  253. Const WS_EX_CLIENTEDGE = &H200&
  254.  
  255. Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  256. Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  257. Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  258.  
  259.  
  260. '----------------------------------------------------------------------
  261. '   INPUTS: | handle to the window to flatten
  262. '  RETURNS: | NONE
  263. ' COMMENTS: | flatten control or form
  264. '----------------------------------------------------------------------
  265. Sub Flatten(lhWnd&)
  266. 'VARIABLES:
  267.   Dim lngStyle&
  268. 'CODE:
  269.          lngStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
  270.          lngStyle = (lngStyle And Not WS_EX_CLIENTEDGE Or WS_EX_STATICEDGE)
  271.          SetWindowLong hwnd, GWL_EXSTYLE, lngStyle
  272.          SetWindowPos hwnd, 0, 0, 0, 0, 0, _
  273.                    &H1 Or &H2 Or &H4 Or &H20
  274. 'END CODE:
  275. End Sub
  276.  
  277.  
  278. menucaption: Keypress/Mousestate Detect
  279.  
  280.  
  281. Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
  282.  
  283.  
  284. '----------------------------------------------------------------------
  285. '   INPUTS: |
  286. '  RETURNS: | boolean..true if the key specified is toggled on)
  287. ' COMMENTS: | determine if a keys state is down(includes mouse downs)
  288. '----------------------------------------------------------------------
  289. Private Function funcKeyTrue(VirtualKey As Integer) As Boolean
  290.   On Error GoTo ERR:
  291. 'CODE:
  292.          If GetKeyState(VirtualKey) = -127 Or _
  293.             GetKeyState(VirtualKey) = -128 Then
  294.             
  295.                   funcKeyTrue = True
  296.          End If
  297. 'END CODE:
  298. Exit Function
  299. ERR:
  300.    If ERR.Number <> 0 Then
  301.        MsgBox ERR.Number & vbCrLf & ERR.Description
  302.    End If
  303. End Function
  304.  
  305.  
  306. menucaption: Move Controls/Form
  307.  
  308.  
  309. Const WM_SYSCOMMAND As Long = &H112
  310.  
  311. Declare Function ReleaseCapture Lib "user32.dll" () As Long
  312. Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  313.  
  314.  
  315.  
  316. '----------------------------------------------------------------------
  317. '   INPUTS: | NONE
  318. '  RETURNS: | STRING
  319. ' COMMENTS: | holds the code related to moving controls
  320. '----------------------------------------------------------------------
  321. Sub mod_Move(lhWnd&)
  322. 'CODE:
  323.         ReleaseCapture
  324.         SendMessage lhWnd, WM_SYSCOMMAND, &HF012&, 0&
  325. 'END CODE:
  326. End Sub
  327.  
  328.  
  329. menucaption: Set Thread Priority
  330.  
  331. Const HIGH_PRIORITY_CLASS = &H80
  332. Const NORMAL_PRIORITY_CLASS = &H20
  333. Const IDLE_PRIORITY_CLASS = &H40
  334.  
  335. Enum enumPriorityLevel
  336.        priority_High = 2
  337.        priority_normal = 0
  338.        priority_low = -2
  339. End Enum
  340.  
  341. Declare Function GetCurrentProcess Lib "kernel32" () As Long
  342. Declare Function GetCurrentThread Lib "kernel32" () As Long
  343. Declare Function GetThreadPriority Lib "kernel32" (ByVal hThread As Long) As Long
  344. Declare Function SetThreadPriority Lib "kernel32" (ByVal hThrad As Long, ByVal nPriority As Long) As Long
  345. Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
  346.  
  347. '----------------------------------------------------------------------
  348. '   INPUTS: | NONE
  349. '  RETURNS: | STRING
  350. ' COMMENTS: | set the priority of current thread..good for do loop control
  351. '----------------------------------------------------------------------
  352. -------eread..goor'ead.dad..goiDaption: Set ThS If GetKeyState(VirtualKey) = -127 O____0""""veW'(Liboop control
  353. TevelL0
  354. C-ereatafsC'(Liboop,ad.dad..iorityClasslF------------------
  355. -------ereol
  356. '------------h,Dim arr()   As Vari---(lhWncr()   AsLority_low = -2
  357. EndubHw
  358. e ERR.Descr -2
  359. iity_low = -2
  360. minuereol
  361. r()   AsLority_low = -2
  362.   ' PVWorityClass As LerityClCw(VWorityClass As LerityClCw(VWoris)reatafsC'(LiboEi
  363. '----M ERR.Descr -2koMMAND As LouAl32" (Byvariables frosltcinst NORMA'END CODE:i2c:
  364.   
  365.      nuereolo CODE:i2c:
  366.   
  367. ,Dim ntrol
  368. '-----------srMclaDo      olGetCurDIORITY_CLASS = &H20
  369. Const IDLE_PRIORITY_CLASS = %(Virtualith a single lyPRIORITY_CLASS = &HfB
  370. Endci---(lhWncr()  Ton
  371. ClCw(VWoris)reion
  372. ClCw(VWoris)reip' COMMENTS: | rEt(PCRi)MENTS: |F
  373.   S = %(Virtualith a single lyPRIORITY_CLASSLongd..iorityA,Ipmiingle l=ENTS: | rslCw(VWoris)reion
  374. ClCw(  lyPRICODipAs Long, lParam As A dboEi
  375. '----M ER---lyPEIBs"D((uraw the text
  376.     ,L,
  377. '----nt--------
  378. '   IN-20
  379. Cone(Byvarincr()Cone(Byvarinid Sub
  380.  
  381.  
  382. menucaptioityA,Ipmiingle l=ENTS: | rslCwNRFCone(B-2
  383. s Long, Bur -2ktoggled on)
  384. ' COMMENTS: | determine if a niODE: nrincr(single lyPRmRwMsg A---M 
  385.   yhyVadwNewLong As LEEEEEEEEEEE