home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_2 / VB_PROJ / VBPROJ.BAS next >
Encoding:
BASIC Source File  |  1992-10-21  |  13.4 KB  |  410 lines

  1. DefInt A-Z
  2.  
  3. '----------------------
  4. 'for vbproj.ini file.
  5. '----------------------
  6. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lplFileName As String) As Integer
  7. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  8.  
  9. '-----------------------------------------------
  10. 'For finding if Visual Basic is already running.
  11. '-----------------------------------------------
  12. Declare Function GetModuleHandle Lib "Kernel" (ByVal Program$)
  13. Declare Function GetModuleUsage Lib "Kernel" (ByVal hModule)
  14.  
  15. '------------------------------------
  16. 'For finding Visual Basic title text
  17. 'and define proper contants.
  18. '------------------------------------
  19. Declare Function FindWindow Lib "User" (ByVal lpClass&, ByVal WinName&)
  20. Declare Function GetWindow Lib "User" (ByVal hWnd, ByVal wCmd)
  21. Declare Function GetNextWindow Lib "User" (ByVal hWnd, ByVal wCmd)
  22. Declare Function GetWindowText Lib "User" (ByVal hWnd, ByVal WinText$, ByVal BufSize)
  23. Const GW_HWNDFIRST = 0
  24. Const GW_HWNDNEXT = 2
  25.  
  26. '------------------------------------
  27. 'For restoring VB if it is minimized.
  28. '------------------------------------
  29. Declare Function ShowWindow Lib "User" (ByVal hWnd, ByVal nCmdShow)
  30. Const SW_RESTORE = 9
  31.  
  32. '---------------------------------
  33. 'Define Contants for messageboxes.
  34. '---------------------------------
  35. Const IDYES = 6
  36. Const YESNO = 4
  37.  
  38. '----------------------------------------------------
  39. 'Path where visual Basic is installed. See ReadButton
  40. 'procedure how to read it from vbproj.ini
  41. '----------------------------------------------------
  42. Dim VBPath As String
  43.  
  44. Sub DoCmdLine (Index As Integer)
  45. '----------------------------------------------------
  46. 'Check first if user have installed VB to a different
  47. 'directory after first taking this program to use.
  48. 'If directory has changed, let the user re-enter
  49. 'correct path where VB is installed.
  50. '----------------------------------------------------
  51.     
  52.     Section$ = "VB"
  53.     KeyName$ = "Path"
  54.     Fname$ = "vbproj.ini"
  55.     Match$ = Dir$(VBPath$)
  56.     If Match$ = "" Then VBNotFound Section$, KeyName$, Fname$
  57.  
  58. '---------------------------------------------
  59. 'If button's caption UnUsed, ask if user want
  60. 'to start new project.
  61. '---------------------------------------------
  62.  
  63. If Projects.Cmd_Project(Index).Caption = "&UnUsed" Then
  64.     
  65.     Msg$ = "Start New Project?"
  66.     Title$ = "????"
  67.     Answer% = MsgBox(Msg$, 32 + YESNO, Title$)
  68.     If Answer% = IDYES Then
  69.     Ret% = IsVBRunnig()
  70.     If Ret% > 0 Then
  71.         Ret% = BrowseWindows()
  72.         SendKeys "%F" + "{ENTER}"
  73.     Else
  74.         X% = Shell(VBPath$, 1)
  75.     End If
  76.    Else
  77.     Exit Sub
  78.    End If
  79. End
  80. End If
  81.  
  82.  
  83. '--------------------------------------------
  84. 'Check if desired project file is found.
  85. '--------------------------------------------
  86.  
  87. Match$ = Dir$(Projects.Cmd_Project(Index).Tag)
  88. If Match$ = "" Then
  89.     Msg$ = "Project file " + Projects.Cmd_Project(Index).Tag + " not found?" + Chr$(10) + Chr$(13)
  90.     Msg$ = Msg$ + "Check the correct path from [File|Add or Modify Buttons] menu."
  91.     MsgBox Msg$, 16, "ERROR!"
  92.     Exit Sub
  93. End If
  94.  
  95.  
  96. '-------------------------------------------------
  97. 'Check is VB already running. See IsVBRunning and
  98. 'BrowseWindows functions. If VB is running send
  99. 'keystrokes to open desired project, else start VB
  100. 'using Shell function with desired project.
  101. '-------------------------------------------------
  102.  
  103. Ret% = IsVBRunnig()
  104. If Ret% > 0 Then
  105.     
  106.     Ret% = BrowseWindows()
  107.     
  108.     '----------------------------------------------
  109.     'Change also to directory where project file is
  110.     'located. See Todir$ Function in this module.
  111.     '----------------------------------------------
  112.     
  113.     WhichDir$ = ToDir$((Projects.Cmd_Project(Index).Tag))
  114.     SendKeys "%FO" + Projects.Cmd_Project(Index).Tag + "{ENTER}", -1
  115.     ChDir WhichDir$
  116.     End
  117.  
  118. Else
  119.     WhichDir$ = ToDir$((Projects.Cmd_Project(Index).Tag))
  120.     ChDir WhichDir$
  121.     X% = Shell(VBPath$ + " " + Projects.Cmd_Project(Index).Tag, 1)
  122. End If
  123.  
  124. End
  125.  
  126. End Sub
  127.  
  128. Sub ReadButton (Frm As Form)
  129.  
  130. '-----------------------------------------------------------
  131. 'This procedure reads information from vbproj.ini, which
  132. 'is located in windows directory. We use API call function
  133. 'GetPrivateProfileString, which is declared in global module
  134. 'NOTE! When you use the function, you must Dim returned
  135. 'string as varible lenght string because of dll return.
  136. '
  137. 'Dim RetStr As String * 128
  138. '
  139. 'Unless you don't, it will hang your system.
  140. '-----------------------------------------------------------
  141.  
  142. Dim RetStr As String * 128
  143. Section$ = "ButtonCaption"
  144. Def$ = "&UnUsed,C:\VB\NO.MAK"
  145. Size% = 128
  146. Fname$ = "vbproj.ini"
  147.  
  148. '----------------------------------------------------
  149. 'Start loop for reading properties from vbproj.ini.
  150. '----------------------------------------------------
  151.  
  152. I = -1
  153. Do
  154.     I = I + 1
  155.     KeyName$ = "Button" + Str$(I)
  156.     Returned% = GetPrivateProfileString(Section$, KeyName$, Def$, RetStr$, Size%, Fname$)
  157.     
  158.     '----------------
  159.     'Get the caption.
  160.     '----------------
  161.     Frm.Cmd_Project(I).Caption = Left$(RetStr$, (InStr(RetStr$, ",")) - 1)
  162.     
  163.     '-----------------------------------------------------
  164.     'Get commandline assigning it to buttons Tag property.
  165.     '-----------------------------------------------------
  166.     Frm.Cmd_Project(I).Tag = Mid$(RetStr$, (InStr(RetStr$, ",")) + 1)
  167.     
  168.     '----------------------------
  169.     'we have reached last button.
  170.     '----------------------------
  171.     If I = 11 Then Exit Do
  172. Loop
  173.  
  174. '----------------------------------------
  175. 'next read path from where to execute VB.
  176. '----------------------------------------
  177.  
  178. Section$ = "VB"
  179. KeyName$ = "Path"
  180. Def$ = "NotDefined"
  181. Returned% = GetPrivateProfileString(Section$, KeyName$, Def$, RetStr$, Size%, Fname$)
  182. VBPath$ = Left$(RetStr$, Returned%)
  183.  
  184. '-----------------------------------------------------
  185. 'First time, get path where Visual Basic is installed.
  186. '-----------------------------------------------------
  187.  
  188. If VBPath$ = "NotDefined" Then VBNotFound Section$, KeyName$, Fname$
  189.  
  190.  
  191. End Sub
  192.  
  193. Function IsVBRunnig ()
  194.  
  195. '-------------------------------------
  196. 'Get value if Visual Basic is already
  197. 'runnig value 0 means VB is NOT runnig
  198. 'value >0 means VB is running.
  199. '-------------------------------------
  200.  
  201.     hModule = GetModuleHandle("VB.EXE")
  202.     IsVBRunnig = GetModuleUsage(hModule)
  203.  
  204. End Function
  205.  
  206. Function BrowseWindows ()
  207.     
  208. '---------------------------------------------------------
  209. 'This function searches all windows for finding if Visual
  210. 'Basic is already runnig. Finding method is browse all
  211. 'windows that are currently running and get those title
  212. 'text. If Visual Basic's title text is found, we use
  213. 'AppActivate statement to activate it for sending
  214. 'keystrokes. See DoCmdLine procedure found in this module.
  215. 'NOTE!
  216. 'Dim TitleText As String * 256 is needed for dll return or
  217. 'system will hang.
  218. '---------------------------------------------------------
  219.  
  220.     Dim TitleText As String * 256
  221.     Wnd = FindWindow(0, 0)
  222.     Wnd = GetWindow(Wnd, GW_HWNDFIRST)
  223.     
  224. '----------------------------------------------------------------
  225. 'Search Visual Basic's windows handle for getting it's
  226. 'title text. It is better using this method insted of
  227. 'AppActivate "Title", because if user has some sort
  228. 'of program running, which will add something else to
  229. 'active window's title text (eg. clock), straight AppActivate
  230. 'would not work. Now we only search the string containing program's
  231. 'title text to get firm result.
  232. 'Function InStr(TextToSearchFrom, TextToSearchfor) will do the job.
  233. 'If return value is not 0 (zero), then program is runnig.
  234. '------------------------------------------------------------------
  235.     
  236.     While Wnd <> 0
  237.     TChars = GetWindowText(Wnd, TitleText, 256)
  238.     X% = InStr(TitleText, "Microsoft Visual Basic [design]")
  239.     If X% <> 0 Then
  240.         
  241.         '--------------------------------------------------------
  242.         'If VB is minimized, API function ShowWindow will restore
  243.         'it, so there is no error message "Illegal function".
  244.         '--------------------------------------------------------
  245.  
  246.         SW = ShowWindow(Wnd, SW_RESTORE)
  247.         AppActivate (TitleText)
  248.         Exit Function
  249.     End If
  250.     Wnd = GetNextWindow(Wnd, GW_HWNDNEXT)
  251.     Wend
  252.     BrowseWindows = 0
  253. End Function
  254.  
  255. Sub WriteButton (Frm As Form)
  256.  
  257. '--------------------------------------------
  258. 'This procedure saves all button captions and
  259. 'command lines to vbproj.ini
  260. '--------------------------------------------
  261.  
  262. Section$ = "ButtonCaption"
  263. Fname$ = "vbproj.ini"
  264.  
  265. I = -1
  266. Do
  267.     I = I + 1
  268.     KeyName$ = "Button" + Str$(I)
  269.     'check named mark to end loop
  270.     WriteStr$ = Frm.Cmd_Project(I).Caption + "," + Frm.Cmd_Project(I).Tag
  271.     WriteThings% = WritePrivateProfileString(Section$, KeyName$, WriteStr$, Fname$)
  272.     If I = 11 Then Exit Do
  273. Loop
  274. End Sub
  275.  
  276. Sub VBNotFound (Section$, KeyName$, Fname$)
  277.  
  278. '-------------------------------------------------------
  279. 'This procedure is called whenever path for Visual Basic
  280. 'has changed or for the first time that user use this
  281. 'program.
  282. '-------------------------------------------------------
  283.  
  284.  
  285. WRONGPATH:
  286.     Prompt$ = "Path for Visual Basic is not defined or it has changed."
  287.     Prompt$ = Prompt$ + " Please enter full path where VB is installed."
  288.     GetPath$ = InputBox$(Prompt$, "Defining path for Visual Basic", "C:\VB")
  289.     
  290.     '-----------------------------------------------
  291.     'Check the path is correct. If it is wrong, give
  292.     'user a chance to re-enter it.
  293.     '-----------------------------------------------
  294.  
  295.     Match$ = Dir$(GetPath$ + "\" + "vb.exe")
  296.     If Match$ = "" Then
  297.     Answer% = MsgBox("Could not find VB.EXE. Check the path again?", 16 + YESNO, "ERROR!")
  298.     If Answer% = IDYES Then
  299.         GoTo WRONGPATH
  300.     Else
  301.         End
  302.     End If
  303.     End If
  304.     
  305.     '--------------------------------------------------------
  306.     'If entered path is correct assing it to VBPath$
  307.     'and write the path to vbproj.ini (to windows directory).
  308.     '--------------------------------------------------------
  309.     
  310.     VBPath$ = GetPath$ + "\" + Match$
  311.     WriteThings% = WritePrivateProfileString(Section$, KeyName$, UCase$(VBPath$), Fname$)
  312.     WriteButton Projects
  313. End Sub
  314.  
  315. Sub TreeD (Frm As Form, Ctrl As Control, Style As String)
  316.     
  317. '---------------------------------------------------
  318. 'This procedure draw 4 lines around a control
  319. 'to give 3 - dimensional look. You can give to
  320. 'control either raised or downed effect. Style
  321. 'variable determine if control is raised or downed.
  322. '
  323. 'Style$ = "up" for raised effect and
  324. 'Style$ = "down" fo downed effect.
  325. 'etc. TreeD FormName, ControlName, "up" would give
  326. 'to control a raised look. Call this sub from Form's
  327. 'paint procedure.
  328. '----------------------------------------------------
  329.     
  330.     '------------------------------------------------------
  331.     'Check style and give proper colors representing style.
  332.     '8 = Grey
  333.     '15 = Bright White
  334.     '------------------------------------------------------
  335.  
  336.     Style$ = LCase$(Style$)
  337.     If Style$ = "down" Then
  338.     Col1 = 8
  339.     Col2 = 15
  340.     ElseIf Style$ = "up" Then
  341.     Col1 = 15
  342.     Col2 = 8
  343.     Else
  344.     Msg$ = "TreeD Sub not properly defined." + Chr$(10) + Chr$(13)
  345.     Msg$ = Msg$ + "You should use:" + Chr$(10) + Chr$(13)
  346.     Msg$ = Msg$ + "TreeD FormName, ControlName, Style$" + Chr$(10) + Chr$(13)
  347.     Msg$ = Msg$ + "Where Style$ is up or down"
  348.     MsgBox Msg$, 64, "Designing time ERROR!"
  349.     End
  350.     End If
  351.     
  352.     '--------------------------
  353.     'Get control's coordinates.
  354.     '--------------------------
  355.  
  356.     CtrlLeft% = Ctrl.Left - 15
  357.     CtrlTop% = Ctrl.Top - 15
  358.     CtrlWide% = Ctrl.Width + 15
  359.     CtrlHigh% = Ctrl.Height + 15
  360.  
  361.     '---------------------------------------------
  362.     'Draw 4 lines around control, left & top
  363.     'with same color and right & bottom with same.
  364.     '---------------------------------------------
  365.  
  366.     Frm.Line (CtrlLeft%, CtrlTop%)-Step(CtrlWide%, 0), QBColor(Col1)
  367.     Frm.Line -Step(0, CtrlHigh%), QBColor(Col2)
  368.     Frm.Line -Step(-CtrlWide%, 0), QBColor(Col2)
  369.     Frm.Line -Step(0, -CtrlHigh%), QBColor(Col1)
  370. End Sub
  371.  
  372. Function ToDir (Directory As String) As String
  373.                    
  374. '----------------------------------------------
  375. 'This function retrieves Button's Tag property
  376. '(command line). First it converts it reverse
  377. 'to get project's directory which to change to.
  378. '----------------------------------------------
  379.  
  380. StrLen% = Len(Directory$)           'Tag's lenght
  381. For J% = StrLen% To 1 Step -1       ' Loop to start from right
  382.     Temp$ = Mid$(Directory$, J%, 1)  'side 1 charcacter at a time
  383.     RevStr$ = RevStr$ + Temp$        'store charcacter to temp$ variable.
  384. Next
  385.  
  386. '--------------------------------------
  387. 'Now we have path without project file.
  388. '--------------------------------------
  389.  
  390. RevStr$ = Mid$(RevStr$, InStr(RevStr$, "\") + 1)
  391.  
  392. '----------------------------------
  393. 'convert it back to original state.
  394. '----------------------------------
  395.  
  396. StrLen% = Len(RevStr$)
  397. For J% = StrLen% To 1 Step -1
  398.     Temp$ = Mid$(RevStr$, J%, 1)
  399.     RevStr1$ = RevStr1$ + Temp$
  400. Next
  401.  
  402. '-----------------------------------------------
  403. 'give value to function to change the directory.
  404. '-----------------------------------------------
  405.  
  406. ToDir = RevStr1$
  407.  
  408. End Function
  409.  
  410.