Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: WinBatch Studio Buddy
It allows you to keep track of files when you are working on a project that needs a number of files, without having to have them loaded in WB Studio all the time. Hidding away when not needed.
You can have any number of projects, each with any number of subfolders and files.
It makes use of both Guido's TreeView code and my SetWindowPos.
;################################################################## ;# Winbatch Studio Buddy - buddy.wbt # ;# By: Iain Dickason 2002 (iain@caverock.net) # ;# A application to provide project lists to WinBatch developers # ;# and hides when not in use. # ;################################################################## ; Todo: ; - Hide automaticly when mouse leaves the window ; - Fix the WinBatch Studio detection ; - Add hiding in title bar? ; - Make it semi transperent when hidden? ; - Able to add SCS projects ; - better icons ; Lets have some window controls for now (need to add an exit button) IntControl(49,1,1,0,0) IntControl(72,1, 0, 0, 0) IntControl (1002, 0, 0, 0, 0) ;Window API Constants SWP_NOSIZE = 1 SWP_NOMOVE = 2 SWP_NOZORDER = 4 SWP_NOACTIVATE = 16 SWP_SHOWWINDOW = 64 SWP_HIDEWINDOW = 128 ;TREE VIEW API CONSTANTS ;Styles TVS_HASBUTTONS=1 TVS_HASLINES=2 TVS_LINESATROOT=4 TVS_SHOWSELALWAYS=32 TVS_EDITLABELS=8 TVI_FIRST=-65535 TVI_LAST=-65534 TVI_ROOT=-65536 TVI_SORT=-65533 TVE_EXPAND = 2 dlg_timer = 1 dlg_button = 2 dlg_listchange = 8 ; Make sure there is a key to store all under (if you change this there are a couple of other places to change as well) RegKey = RegCreateKey(@REGCURRENT, "SOFTWARE\Iain\Studio Buddy") #definesubroutine dlgproc(handle,msg,id,p4,p5) select msg case 0 ;Init ; Add button, timer and listchange events DialogProcOptions(handle,dlg_button,1) ;BUTTONS DialogProcOptions(handle,dlg_timer,100) ;timer DialogProcOptions(handle,dlg_listchange,1) ;listchange ; Work out where WinBatch Studio is studiohandle = DllHwnd("WinBatch Studio") studiopos = GetWindowPos(studiohandle) ; move to just down on the left edge xpos = ItemExtract(1,studiopos,",") + 0 ypos = ItemExtract(2,studiopos,",") + 80 SetWindowPos(handle,xpos,ypos,0,0,0,SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER) ; get the list of projects and add list to the dropdown ProjList = GetProjectList() DialogControlSet(handle, 3, 5, ProjList) DialogControlSet(handle, 3, 6, ItemExtract(1,ProjList,@Tab)) ;create and fill the treeview htree=TreeCreate(4,30,170,300,TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS|TVS_EDITLABELS,handle) root = DrawProject(ItemExtract(1,ProjList,@Tab),htree,0) break case dlg_timer activewindow = WinGetActive ( ) ; See if WinBatch Studio is the active window ; ** bug here ** a number of WBS's child dialogs get detected If StrTrim(ItemExtract(1,activewindow,"-")) == "WinBatch Studio" then ; move us to the top. (need to work out the z-order stuff for SetWindowPos) IntControl (54, "", 1, 0, 0) studiohandle = DllHwnd("WinBatch Studio") ; Work out where WBS is and move us there studiopos = GetWindowPos(studiohandle) xpos = ItemExtract(1,studiopos,",") + 0 ypos = ItemExtract(2,studiopos,",") + 80 SetWindowPos(handle,xpos,ypos,0,0,0,SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER) else ; Get us off the top IntControl (54, "", 0, 0, 0) EndIf break case dlg_button select id case 1 ;hide ; Shrink window and show the show button SetWindowPos(handle,0,0,7+10,44+23,0,SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER) SetWindowPos(htree,0,0,0,0,0,SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE|SWP_HIDEWINDOW) DialogControlState(handle, 2, 4, 1) return -2 case 2 ;show ; Set the window size back and hide the show button SetWindowPos(handle,0,0,202,359,0,SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER) SetWindowPos(htree,0,0,0,0,0,SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE|SWP_SHOWWINDOW) DialogControlState(handle, 2, 3, 1) return -2 case 4; Add project project = DialogControlGet(handle, 3, 6) If project == "" then Message("Error!","Type in a project name to create.") Return -2 EndIf If !ItemLocate(project,GetProjectList(),@tab) then RegCreateKey(RegKey,project) TreeDeleteItem(htree,TVI_ROOT) DrawProject(project,htree,0) ProjList = GetProjectList() DialogControlSet(handle, 3, 5, ProjList) DialogControlSet(handle, 3, 6, Project) EndIf return -2 case 5; Remove project project = DialogControlGet(handle, 3, 6) If ItemLocate(project,GetProjectList(),@tab) then RegDeleteKey(RegKey, project) TreeDeleteItem(htree,TVI_ROOT) ProjList = GetProjectList() DrawProject(ItemExtract(1,ProjList,@Tab),htree,0) DialogControlSet(handle, 3, 5, ProjList) DialogControlSet(handle, 3, 6, ItemExtract(1,ProjList,@Tab)) EndIf return -2 case 6 ; Edit File item = TreeGetSelectedItem(htree) project = DialogControlGet(handle, 3, 6) Item = StrCat(project,"\",item) If item!="" then last = ItemCount(item,"\") item = ItemReplace(StrCat("[",ItemExtract(last,item,"\"),"]"),last,item,"\") If RegExistValue(RegKey,item) then file = RegQueryValue(RegKey,item) Run("Winbatch Studio.exe",StrCat('"',file,'"')) EndIf EndIf Return -2 break case 7 ; Add File item = TreeGetSelectedItem(htree) project = DialogControlGet(handle, 3, 6) Item = StrCat(project,"\",item) If RegExistKey(RegKey, item) then types="WIL Files|*.wbt;*.wil;*.web|Text Files|*.txt|HTML Files|*.htm;*.html;*.css|All Files|*.*" filelist = AskFileName("Add File","",types,"",2) For f = 1 to ItemCount(filelist,@tab) file = ItemExtract(f,filelist,@tab) subkey = ItemExtract(-1,file,"\") RegSetValue(RegKey,StrCat(item,"\","[",subkey,"]"),file) Next f Project = DialogControlGet(handle, 3, 6) TreeDeleteItem(htree,TVI_ROOT) DrawProject(project,htree,0) EndIf Return -2 break case 8 ; Remove File itemhandle = TreeGetSelectedItemHandle(htree) If itemhandle then item = TreeGetSelectedItem(htree) project = DialogControlGet(handle, 3, 6) Item = StrCat(project,"\",item) last = ItemCount(item,"\") item = ItemReplace(StrCat("[",ItemExtract(last,item,"\"),"]"),last,item,"\") If RegExistValue(RegKey, item) then RegDelValue(RegKey, item) TreeDeleteItem(htree,TVI_ROOT) DrawProject(project,htree,0) EndIf EndIf Return -2 break case 9 ; Add Folder item = TreeGetSelectedItem(htree) project = DialogControlGet(handle, 3, 6) Item = StrCat(project,"\",item) If RegExistKey(RegKey, item) then folder = AskLine("Studio Buddy","New Folder name:","") RegCreateKey(RegKey, StrCat(item,"\",folder)) TreeDeleteItem(htree,TVI_ROOT) DrawProject(project,htree,0) EndIf Return -2 break case 10 ; Remove Folder itemhandle = TreeGetSelectedItemHandle(htree) If itemhandle then item = TreeGetSelectedItem(htree) If RegExistKey(RegKey, item) then RegDeleteKey(RegKey, item) TreeDeleteItem(htree,TVI_ROOT) DrawProject(project,htree,0) EndIf EndIf Return -2 break case 11 ; Help Message("Winbatch Budy Help",HelpString) Return -2 break endselect break case dlg_listchange project = DialogControlGet(handle, 3, 6) If ItemLocate(project,GetProjectList(),@tab) then TreeDeleteItem(htree,TVI_ROOT) root = DrawProject(project,htree,0) TreeExpand(htree,TVE_EXPAND,root) EndIf break endselect return -1 :Cancel ; To deal with people clicking cancel on file open dialog and askline return -2 #endsubroutine #DefineFunction GetProjectList() key = RegOpenKey(@REGCURRENT, "SOFTWARE\Iain\Studio Buddy") return RegQueryKeys(key) #EndFunction #DefineFunction DrawProject(item,htree,parent_handle) TVE_EXPAND = 2 TVI_LAST=-65534 text = ItemExtract(ItemCount(item,"\"),item,"\") key = RegOpenKey(@REGCURRENT, StrCat("SOFTWARE\Iain\Studio Buddy\",item)) subfolders = RegQueryKeys(key) If ItemCount(Subfolders,@tab) > 0 then For f = 1 to ItemCount(Subfolders,@tab) folder = ItemExtract(f,subfolders,@tab) treehandle = TreeInsertItem(htree,TVI_LAST,folder,parent_handle) DrawProject(StrCat(item,"\",folder),htree,treehandle) TreeExpand(htree,TVE_EXPAND,treehandle) Next f EndIf files = RegQueryItem(key,"") If ItemCount(files,@tab) > 0 then For f = 1 to ItemCount(files,@tab) TreeInsertItem(htree,TVI_LAST,ItemExtract(f,files,@tab),parent_handle) Next f EndIf RegCloseKey(key) return 0 #EndFunction ;--------------------------------------------------------------------------------; ;GetWindowPos : Gets window position in real screen x,y ; ;--------------------------------------------------------------------------------; ;handle : dialog handle of window ; ;--------------------------------------------------------------------------------; ;Returns: string = "xpos,ypos,widht,height" ; ;--------------------------------------------------------------------------------; #DefineFunction GetWindowPos(handle) user32=strcat(dirwindows(1),"user32.dll") lpRect = BinaryAlloc(16) ret = -1 if dllcall(user32,long:"GetWindowRect",long:handle,lpbinary:lpRect) then ret = StrCat(BinaryPeek4(lpRect,0),",",BinaryPeek4(lpRect,4),",",BinaryPeek4(lpRect,8),",",BinaryPeek4(lpRect,12)) endif BinaryFree(lpRect) Return ret #EndFunction ;--------------------------------------------------------------------------------; ;SetWindowPos : Moves or resizes a window (or control) ; ;--------------------------------------------------------------------------------; ;xpos : pixels from left ; ;ypos : pixels from top ; ;width : width in pixels ; ;height : height in pixels ; ;after : handle for window or control to put it before (order to be drawn) ; ;style : See API Constants for styles ; ;handle : dialog handle returned by the dialog procedure ; ;--------------------------------------------------------------------------------; ;Returns: <>0 if succesful , 0 otherwise ; ;--------------------------------------------------------------------------------; #DefineFunction SetWindowPos(handle,xpos,ypos,width,height,after,style) user32=strcat(dirwindows(1),"user32.dll") val = dllcall(user32,long:"SetWindowPos",long:handle,long:after,long:xpos,long:ypos,long:width,long:height,long:style) Return val #EndFunction ;--------------------------------------------------------------------------------; ;TreeCreate : Creates a treeview control. ; ;--------------------------------------------------------------------------------; ;x : pixels from left ; ;y : pixels from top ; ;w : width in pixels ; ;h : height in pixels ; ;style : style flags , see API constants ; ;handle : dialog handle returned by the dialog procedure ; ;--------------------------------------------------------------------------------; ;Returns: treeview handle if succesful , 0 otherwise ; ;--------------------------------------------------------------------------------; ;API EXStyle : WS_EX_CLIENTEDGE ; ; Style : WS_CHILD|WS_VISIBLE ; ;--------------------------------------------------------------------------------; #definefunction TreeCreate(x,y,w,h,style,handle) user32=strcat(dirwindows(1),"user32.dll") hinst=dllhinst("") return dllcall(user32,long:"CreateWindowExA",long:512,lpstr:"SysTreeView32",lpstr:"",long:1073741824|268435456|style,long:x,long:y,long:w,long:h,long:handle,long:0,long:hinst,long:0) #endfunction ;--------------------------------------------------------------------------------; ;TreeExpand : Expands part of a treeview ; ;--------------------------------------------------------------------------------; ;htree : treeview handle returned by TreeCreate() ; ;flag : flags , see API constants ; ;item : handle to the TreeView item (as returned by TreeInsertItem) ; ;--------------------------------------------------------------------------------; ;Returns: 0 ; ;--------------------------------------------------------------------------------; #definefunction TreeExpand(htree,flag,item) TVM_EXPAND = 4352+2 user32=strcat(dirwindows(1),"user32.dll") dllcall(user32,long:"SendMessageA",long:htree,long:TVM_EXPAND,long:flag,long:item) #endfunction ;--------------------------------------------------------------------------------; ;TreeInsertItem : Inserts an item in a treeview control. ; ;--------------------------------------------------------------------------------; ;htree : treeview handle returned by TreeCreate() ; ;insertafter : item handle after wich the new item will be inserted , or: ; ; TVI_FIRST : Inserts the item at the beginning of the list ; ; TVI_LAST : Inserts the item at the end of the list ; ; TVI_ROOT : Add the item as a root item ; ; TVI_SORT : Inserts the item into the list in alphabetical order ; ;text : item text ; ;hparent : handle of parent item , if this member is the TVI_ROOT value or 0 ; ; the item is inserted at the root of the tree-view control. ; ;--------------------------------------------------------------------------------; ;Returns : handle to the new item if successful, or 0 otherwise. ; ;--------------------------------------------------------------------------------; #definefunction treeinsertitem(htree,insertafter,text,hparent) user32=strcat(dirwindows(1),"user32.dll") TV_FIRST=4352 TVIF_TEXT=1 TVIF_CHILDREN=64 TVIF_HANDLE=16 TVM_INSERTITEM=TV_FIRST+0 TVM_GETNEXTITEM=TV_FIRST+10 TVM_SETITEM=TV_FIRST+13 if hparent TVITEM=binaryalloc(40) mask=TVIF_CHILDREN|TVIF_HANDLE binarypoke4(TVITEM,0,mask) ;mask binarypoke4(TVITEM,4,hparent) ;hItem binarypoke4(TVITEM,32,1) ;cChildren dllcall(user32,long:"SendMessageA",long:htree,long:TVM_SETITEM,long:0,lpbinary:TVITEM) binaryfree(TVITEM) endif TVINSERTSTRUCT=binaryalloc(48) binarypoke4(TVINSERTSTRUCT,0,hparent) ;hParent binarypoke4(TVINSERTSTRUCT,4,insertafter);hInsertAfter binarypoke4(TVINSERTSTRUCT,8,TVIF_TEXT) ;mask textlen=strlen(text) textbuf=binaryalloc(textlen+1) binarypokestr(textbuf,0,text) binarypoke4(TVINSERTSTRUCT,24,intcontrol(42,textbuf,0,0,0)) ;pszText binarypoke4(TVINSERTSTRUCT,28,textlen) ;cchTextMax ret=dllcall(user32,long:"SendMessageA",long:htree,long:TVM_INSERTITEM,long:0,lpbinary:TVINSERTSTRUCT) binaryfree(textbuf) binaryfree(TVINSERTSTRUCT) return ret #endfunction ;------------------------------------------------------------------------------; ;TreeDeleteItem : Removes an item(or all) from the tree view. ; ;------------------------------------------------------------------------------; ;htree : treeview handle ; ;hitem : handle to the item to delete. If hitem is set to TVI_ROOT all items ; ; are deleted ; ;------------------------------------------------------------------------------; ;Returns: TRUE if successful, or FALSE otherwise. ; ;------------------------------------------------------------------------------; #definefunction TreeDeleteItem(htree,hitem) user32=strcat(dirwindows(1),"user32.dll") TVM_DELETEITEM=4352+1 return dllcall(user32,long:"SendMessageA",long:htree,long:TVM_DELETEITEM,long:0,long:hitem) #endfunction ;------------------------------------------------------------------------------; ;TreeGetSelectedItem : Retrieves the selected item text. ; ;------------------------------------------------------------------------------; ;htree : treeview handle ; ;------------------------------------------------------------------------------; ;Returns : Selected item. If the item is a child item returns a tab delimited ; ; list representing the item hierarchy. ; ;Note : The max item text is set to 500 , change it for bigger item text. ; ;------------------------------------------------------------------------------; #definefunction TreeGetSelectedItem(htree) user32=strcat(dirwindows(1),"user32.dll") TVM_GETNEXTITEM=4352+10 TVM_GETITEM=4352+12 TVGN_CARET=9 TVGN_PARENT=3 TVIF_HANDLE=16 TVIF_TEXT=1 MAXTEXT=500 ;change this for bigger text hitem=dllcall(user32,long:"SendMessageA",long:htree,long:TVM_GETNEXTITEM,long:TVGN_CARET,long:0) if hitem TVITEM=binaryalloc(40) mask=TVIF_TEXT|TVIF_HANDLE binarypoke4(TVITEM,0,mask) ;mask binarypoke4(TVITEM,4,hitem);hItem bufsize=MAXTEXT+1 textbuf=binaryalloc(bufsize) binarypoke4(TVITEM,16,intcontrol(42,textbuf,0,0,0)) ;pszText binarypoke4(TVITEM,20,MAXTEXT) ;cchTextMax dllcall(user32,long:"SendMessageA",long:htree,long:TVM_GETITEM,long:0,lpbinary:TVITEM) binaryeodset(textbuf,bufsize) item=binarypeekstr(textbuf,0,bufsize) ;selected item ;search for parent items while hitem !=0 hitem=dllcall(user32,long:"SendMessageA",long:htree,long:TVM_GETNEXTITEM,long:TVGN_PARENT,long:hitem) if hitem binarypoke4(TVITEM,4,hitem) ;hItem dllcall(user32,long:"SendMessageA",long:htree,long:TVM_GETITEM,long:0,lpbinary:TVITEM) item=iteminsert(binarypeekstr(textbuf,0,bufsize),0,item,"\") endif endwhile binaryfree(TVITEM) binaryfree(textbuf) return item else return "" endif #endfunction ;------------------------------------------------------------------------------; ;TreeGetSelectedItem : Retrieves the selected item text. ; ;------------------------------------------------------------------------------; ;htree : treeview handle ; ;------------------------------------------------------------------------------; ;Returns : Selected item handle. ; ;------------------------------------------------------------------------------; #definefunction TreeGetSelectedItemHandle(htree) user32=strcat(dirwindows(1),"user32.dll") TVM_GETNEXTITEM=4352+10 TVM_GETITEM=4352+12 TVGN_CARET=9 TVGN_PARENT=3 TVIF_HANDLE=16 TVIF_TEXT=1 hitem=dllcall(user32,long:"SendMessageA",long:htree,long:TVM_GETNEXTITEM,long:TVGN_CARET,long:0) return hitem endif #endfunction ;########################## ;Help String HelpString = StrCat("Winbatch Studio Buddy - Project Manager",@crlf,@crlf) HelpString = StrCat(HelpString,"Buttons: (from top)",@crlf) HelpString = StrCat(HelpString,"Create project - Type the project name in then click",@crlf) HelpString = StrCat(HelpString,"Delete Project - Deletes currently displayed project",@crlf) HelpString = StrCat(HelpString,"Edit File - Loads file in Winbatch Studio for editing",@crlf) HelpString = StrCat(HelpString,"Add File(s) - Adds a file to the project (select location for files first)",@crlf) HelpString = StrCat(HelpString,"Remove file - Removes file from project",@crlf) HelpString = StrCat(HelpString,"Create Folder - Creates a folder in the project from selected folder",@crlf) HelpString = StrCat(HelpString,"Remove Folder - Removes the folder from project",@crlf) ;########################## MyDialogFormat=`WWWDLGED,6.1` MyDialogCaption=`Studio Buddy` MyDialogX=115 MyDialogY=131 MyDialogWidth=101 MyDialogHeight=170 MyDialogNumControls=011 MyDialogProcedure=`dlgproc` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=4513660 MyDialog001=`089,083,008,022,PICTUREBUTTON,DEFAULT,"hide",2,7,128,DEFAULT,DEFAULT,"F:\Winbatch Work\studio buddy\hide.bmp"` MyDialog002=`000,000,006,022,PICTUREBUTTON,DEFAULT,"show",3,8,129,DEFAULT,DEFAULT,"F:\Winbatch Work\studio buddy\show.bmp"` MyDialog003=`009,001,078,076,DROPLISTBOX,projects,DEFAULT,DEFAULT,1,DEFAULT,"Microsoft Sans Serif|6656|40|34","0|0|0",DEFAULT` MyDialog004=`089,001,008,008,PICTUREBUTTON,DEFAULT,"Create Project",4,1,128,DEFAULT,DEFAULT,"F:\Winbatch Work\studio buddy\ProjectAdd.bmp"` MyDialog005=`089,011,008,008,PICTUREBUTTON,DEFAULT,"Remove Project",5,2,128,DEFAULT,DEFAULT,"F:\Winbatch Work\studio buddy\ProjectRemove.bmp"` MyDialog006=`089,021,008,008,PICTUREBUTTON,DEFAULT,"Edit File",6,3,160,DEFAULT,DEFAULT,"F:\Winbatch Work\studio buddy\WinBatch.bmp"` MyDialog007=`089,031,008,008,PICTUREBUTTON,DEFAULT,"Add File",7,4,128,DEFAULT,DEFAULT,"F:\Winbatch Work\studio buddy\FileAdd.bmp"` MyDialog008=`089,041,008,008,PICTUREBUTTON,DEFAULT,"Remove File",8,5,128,DEFAULT,DEFAULT,"F:\Winbatch Work\studio buddy\FileRemove.bmp"` MyDialog009=`089,051,008,008,PICTUREBUTTON,DEFAULT,"Add Folder",9,4,128,DEFAULT,DEFAULT,"F:\Winbatch Work\studio buddy\FolderAdd.bmp"` MyDialog010=`089,061,008,008,PICTUREBUTTON,DEFAULT,"Remove Dolfer",10,5,128,DEFAULT,DEFAULT,"F:\Winbatch Work\studio buddy\FolderRemove.bmp"` MyDialog011=`089,157,008,008,PICTUREBUTTON,DEFAULT,"Remove Dolfer",11,5,128,DEFAULT,DEFAULT,"F:\Winbatch Work\studio buddy\Help.bmp"` ButtonPushed=Dialog("MyDialog",1)
Article ID: W15781
File Created: 2003:05:13:11:30:02
Last Updated: 2003:05:13:11:30:02