Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
ver=StrUpper(Version()) verdll=StrUpper(VersionDLL()) If (ver<"2003b") Message("Error","Need WinBatch 2003B or newer%@CRLF%You have WinBatch %ver% %@CRLF%and DLL %verdll%") Exit EndIf If WinVersion(5) < "2-4-0" Message("Error","Must be running NT 4.0, Win2000 or XP for this script") Exit EndIf GoSub InitUDF #DefineSubRoutine UpdateButtons(DlgHandle) DeskList=IntControl(84,"",0,0,0) ; Intcontrol returns list of available desktops a=ItemLocate("Winlogon",desklist,@TAB) If a!=0 Then desklist=ItemRemove(a,desklist,@TAB) a=ItemLocate("Disconnect",desklist,@TAB) If a!=0 Then desklist=ItemRemove(a,desklist,@TAB) DeskCount=ItemCount(Desklist,@TAB) If DeskCount==0 Then Return(99) ; eeeek no desktops nextdesk=1 For xx=1 To deskcount thisdesk=ItemExtract(xx,desklist,@TAB) DialogControlState(DlgHandle,deskcount-xx+1,DCSTATE_REMOVESTYLE,DCSTYLE_INVISIBLE) DialogControlSet(DlgHandle,deskcount-xx+1,DC_TITLE,thisdesk) nextdesk=nextdesk+1 Next For xx=nextdesk To 9 DialogControlState(DlgHandle,xx,DCSTATE_ADDSTYLE,DCSTYLE_INVISIBLE) DialogControlSet(DlgHandle,xx,DC_TITLE,"xxx") Next If deskcount>=9 DialogControlState(DlgHandle,011,DCSTATE_ADDSTYLE,DCSTYLE_DISABLED) DialogControlState(DlgHandle,010,DCSTATE_ADDSTYLE,DCSTYLE_DISABLED) Else DialogControlState(DlgHandle,010,DCSTATE_REMOVESTYLE,DCSTYLE_DISABLED) DialogControlState(DlgHandle,011,DCSTATE_REMOVESTYLE,DCSTYLE_DISABLED) EndIf Return(0) #EndSubRoutine #DefineFunction MyDialogProc(DlgHandle,DlgMessage,DlgControlID,param4,param5) Init_DD_Constants() DESKTOP_SWITCHDESKTOP=256 ; aka hex 100 GENERIC_ALL=268435456 ; aka Hex 10000000 Switch DlgMessage Case MSG_INIT title=GetDesiredTitle() SetTitle(DlgHandle,title) DialogProcOptions(DlgHandle,MSG_BUTTONPUSHED,1) DialogProcOptions(DlgHandle,MSG_TIMER,5000) UpdateButtons(DlgHandle) Return(-1) Case MSG_TIMER UpdateButtons(DlgHandle) Return(-1) Case MSG_BUTTONPUSHED ;if any push buttons pushed Switch DlgControlID ;figure out which one Case 001 Case 002 Case 003 Case 004 Case 005 Case 006 Case 007 Case 008 Case 009 desk=DialogControlGet(DlgHandle,DlgControlID,DC_TITLE) hdeskNewDesktop=CreateDesktop(desk,0,GENERIC_ALL) SwitchDesktop(hdeskNewDesktop) Break Case 011 ;Create New Desktop (or goto it if it exists) desk=DialogControlGet(DlgHandle,010,DC_EDITBOX) hdeskNewDesktop=CreateDesktop(desk,0,GENERIC_ALL) SwitchDesktop(hdeskNewDesktop) a=CreateProcess("explorer.exe","",desk) If a==0 b=DllLastError() Message("retval",b) EndIf moi=IntControl(1004,0,0,0,0) If StrUpper(FileExtension(moi))=="EXE" a=CreateProcess(moi,"",desk) If a==0 b=DllLastError() Message("retval",b) EndIf EndIf If StrUpper(FileExtension(moi))=="WBT" moi=StrCat('"',moi,'"') a=CreateProcess("winbatch.exe",moi,desk) If a==0 b=DllLastError() Message("retval",b) EndIf ;Message("debug",moi) EndIf Break EndSwitch Return (-2) EndSwitch ; ConfigDlgMessage Return(-1) ; Do default processing#EndFunction #EndFunction ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; title=GetDesiredTitle() If WinExist(title) WinActivate(title) Exit Else WinTitle("",title) EndIf IntControl(49,1,0,0,0) WinIconize("") MyDialogFormat=`WWWDLGED,6.1` MyDialogCaption=`WIL Dialog 1` MyDialogX=002 MyDialogY=030 MyDialogWidth=139 MyDialogHeight=102 MyDialogNumControls=011 MyDialogProcedure=`MyDialogProc` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`006,012,033,011,PUSHBUTTON,DEFAULT,"Push 1",2,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`041,012,033,011,PUSHBUTTON,DEFAULT,"Push 2",3,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`082,012,034,011,PUSHBUTTON,DEFAULT,"Push 3",4,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog004=`006,028,033,011,PUSHBUTTON,DEFAULT,"Push 4",5,6,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog005=`041,028,033,011,PUSHBUTTON,DEFAULT,"Push 5",6,7,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog006=`082,028,034,011,PUSHBUTTON,DEFAULT,"Push 6",7,8,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog007=`006,044,033,011,PUSHBUTTON,DEFAULT,"Push 7",8,9,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog008=`041,044,033,011,PUSHBUTTON,DEFAULT,"Push 8",9,10,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog009=`082,044,034,011,PUSHBUTTON,DEFAULT,"Push 9",10,11,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog010=`007,071,069,011,EDITBOX,MyVariable1,"",DEFAULT,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog011=`082,070,044,010,PUSHBUTTON,DEFAULT,"New Desktop",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("MyDialog",1) Exit :InitUDF ;typedef struct _STARTUPINFO { // si ;00 DWORD cb; ;04 LPTSTR lpReserved; ;08 LPTSTR lpDesktop; ;12 LPTSTR lpTitle; ;16 DWORD dwX; ;20 DWORD dwY; ;24 DWORD dwXSize; ;28 DWORD dwYSize; ;32 DWORD dwXCountChars; ;36 DWORD dwYCountChars; ;40 DWORD dwFillAttribute; ;44 DWORD dwFlags; ;48 WORD wShowWindow; ;52 WORD cbReserved2; ;56 LPBYTE lpReserved2; ;60 HANDLE hStdInput; ;64 HANDLE hStdOutput; ;68 HANDLE hStdError; ; TOTALSIZE=72 ;} STARTUPINFO, *LPSTARTUPINFO; ;typedef struct _PROCESS_INFORMATION { // pi ; ;00 HANDLE hProcess; ;04 HANDLE hThread; ;08 DWORD dwProcessId; ;12 DWORD dwThreadId; ;16 total size ;} PROCESS_INFORMATION; ;BOOL CreateProcess( ; LPCTSTR lpApplicationName, // pointer to name of executable module ; LPTSTR lpCommandLine, // pointer to command line string ; LPSECURITY_ATTRIBUTES lpProcessAttributes, // pointer to process security attributes ; LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to thread security attributes ; BOOL bInheritHandles, // handle inheritance flag ; DWORD dwCreationFlags, // creation flags ; LPVOID lpEnvironment, // pointer to new environment block ; LPCTSTR lpCurrentDirectory, // pointer to current directory name ; LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO ; LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION ); #DefineFunction CreateProcess(app,cmdline,desktop) dll=StrCat(DirWindows(1),"kernel32.dll") sbbsize=72 sbb=BinaryAlloc(sbbsize) BinaryPoke4(sbb,0,sbbsize) pbbsize=16 pbb=BinaryAlloc(pbbsize) BinaryEodSet(pbb,pbbsize) deskbb=BinaryAlloc(255) BinaryPokeStr(deskbb,0,desktop) deskaddr=IntControl(42,deskbb,0,0,0) BinaryPoke4(sbb,8,deskaddr) appx=FileLocate(app) If appx=="" Message("Error: Not found",app) Return (0) EndIf app=appx ; Message("App",app) ;Message("CmdLine",cmdline) cmdlinex=StrCat('"',app,'" ',cmdline) ;Message("CmdLineX",cmdlinex) ; bool return val appname cmdline lpPA lpTA inhrt dwCF lpEnv LPDir Startinfo procinf retval=DllCall(dll,long:"CreateProcessA",lpnull,lpstr:cmdlinex,lpnull,lpnull,long:0,long:0,lpnull,lpnull,lpbinary:sbb,lpbinary:pbb) hProcess=BinaryPeek4(pbb,0) hThread=BinaryPeek4(pbb,4) CloseHandle(hProcess) CloseHandle(hThread) BinaryFree(deskbb) BinaryFree(sbb) BinaryFree(pbb) Return(retval) #EndFunction ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #DefineFunction CloseHandle(handle) dll=StrCat(DirWindows(1),"kernel32.dll") retval=DllCall(dll,long:"CloseHandle",long:handle) Return(retval) #EndFunction ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #DefineFunction CreateDesktop(lpszDesktop,dwFlags,dwDesiredAccess) dll=StrCat(DirWindows(1),"user32.dll") retval=DllCall(dll,long:"CreateDesktopA",lpstr:lpszDesktop,lpnull,lpnull,long:dwFlags,long:dwDesiredAccess,lpnull) Return(retval) #EndFunction #DefineFunction SwitchDesktop(hDesk) dll=StrCat(DirWindows(1),"user32.dll") retval=DllCall(dll,long:"SwitchDesktop",long:hDesk) Return(retval) #EndFunction ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #DefineSubRoutine Init_DD_Constants() ;DialogprocOptions Constants MSG_INIT=0 ; The one-time initilization MSG_TIMER=1 ; Timer event MSG_BUTTONPUSHED=2 ; Pushbutton or Picturebutton MSG_RADIOPUSHED=3 ; Radiobutton clicked MSG_CHECKBOX=4 ; Checkbox clicked MSG_EDITBOX=5 ; Editbox or Multilinebox MSG_FILESELECT=6 ; Filelistbox MSG_ITEMSELECT=7 ; Itembox MSG_COMBOCHANGE=8 ; Combobox/Droplistbox MSG_Calendar=9 ; Calendar date change MSG_SPINNER=10 ; Spinner number change MSG_CLOSEVIA49=11 ; Close clicked (Enabled via Intcontrol 49) MSG_FILEBOXDOUBLECLICK=12 ; Get douvle-click message on a FileListBox MSG_ITEMOXDOUBLECLICK=13 ; Get douvle-click message on an ItemBox DPO_DISABLESTATE=1000 ; codes -1=GetSetting 0=EnableDialog 1=DisableDialog DPO_CHANGEBACKGROUND=1001 ; -1=GetSetting otherise bitmap or color string ;DialogControlState Constants DCSTATE_SETFOCUS=1 ; Give Control Focus DCSTATE_QUERYSTYLE=2 ; Query control's style DCSTATE_ADDSTYLE=3 ; Add control style DCSTATE_REMOVESTYLE=4 ; Remove control style DCSTATE_GETFOCUS=5 ; Get control that has focus DCSTYLE_INVISIBLE=1 ; Set Control Invisible ; ALL controls DCSTYLE_DISABLED=2 ; Set Control Disabled ; PUSHBUTTON RADIOBUTTON CHECKBOX PICTUREBUTTON EDITBOX ; MULTILINEBOX ITEMBOX FILELISTBOX CALENDAR DROPLISTBOX ; SPINNER GROUPBOX VARYTEXT STATICTEXT DCSTYLE_NOUSERDATA=4 ; Note: Setable via DialogControlState function ONLY ; SPINNER control only DCSTYLE_READONLY=8 ; Sets control to read-only (user cannot type in data) ; EDITBOX MULTILINEBOX SPINNER DCSTYLE_PASSWORD=16 ; Sets "password mode" where only *'s are displayed ; EDITBOX DCSTYLE_DEFAULTBUTTON=32 ; Sets a button as a the default button ; PUSHBUTTON PICTUREBUTTON DCSTYLE_DIGITSONLY=64 ; Set edit box to accept digits only ; EDITMOX MULTILINEBOX ;DialogControlSet / DialogControlGet Constants DC_CHECKBOX=1 ; CHECKBOX DC_RADIOBUTTON=2 ; RADIOBUTTON DC_EDITBOX=3 ; EDITBOX MULTILINEBOX DC_TITLE=4 ; PICTURE RADIOBUTTON CHECKBOX PICTUREBUTTON VARYTEXT ; STATICTEXT GROUPBOX PUSHBUTTON DC_ITEMBOXCONTENTS=5 ; ITEMBOX FILELISTBOX DROPLISTBOX DC_ITEMBOXSELECT=6 ; ITEMBOX FILELISTBOX DROPLISTBOX DC_CALENDAR=7 ; CALENDAR DC_SPINNER=8 ; SPINNER DC_MULTITABSTOPS=9 ; MULTILINEBOX DC_ITEMSCROLLPOS=10 ; ITEMBOX FILELISTBOX DC_BACKGROUNDCOLOR=11 ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON ; ITEMBOX FILELISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX DC_PICTUREBITMAP=12 ; PICTURE PICTUREBUTTON DC_TEXTCOLOR=13 ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON ; ITEMBOX FIELLISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX DC_ITEMBOXADD=14 ; ITEMBOX FILELISTBOX DROPLISTBOX DC_ITEMBOXREMOVE=15 ; ITEMBOX FILELISTBOX DROPLISTBOX Return 0 #EndSubRoutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #DefineFunction GetDesiredTitle() UOI_NAME= 2 DESKTOP_SWITCHDESKTOP=256 ; aka hex 100 hDesk=OpenInputDesktop(0,@FALSE,DESKTOP_SWITCHDESKTOP) dll=StrCat(DirWindows(1),"user32.dll") bbsize=200 bb=BinaryAlloc(bbsize) BinaryEodSet(bb,bbsize) bb2=BinaryAlloc(4) DllCall(dll,long:"GetUserObjectInformationA",long:hDesk,long:UOI_NAME,lpbinary:bb,long:bbsize,lpbinary:bb2) dtop=BinaryPeekStr(bb,0,bbsize) ;debugging... If StrUpper(Dtop)=="DEFAULT" IntControl(12,0,0,0,0) Else IntControl(12,1,0,0,0) EndIf DeskTitle=StrCat("DesktopHopper - ",dtop) BinaryFree(bb) BinaryFree(bb2) Return(DeskTitle) #EndFunction #DefineFunction SetTitle(DlgHandle,title) dll=StrCat(DirWindows(1),"user32.dll") DllCall(dll,long:"SetWindowTextA",long:DlgHandle,lpstr:title) Return(0) #EndFunction ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #DefineFunction OpenInputDesktop(dwFlags,fInherit,dwDesiredAccess) dll=StrCat(DirWindows(1),"user32.dll") retval=DllCall(dll,long:"OpenInputDesktop",long:dwFlags,long:fInherit,long:dwDesiredAccess) Return(retval) #EndFunction Return
Article ID: W16185
File Created: 2004:03:30:15:43:12
Last Updated: 2004:03:30:15:43:12