AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

AHK Functions :: Control_GetFont() / GuiDefaultFont()
Goto page Previous  1, 2, 3 ... 8, 9, 10, 11  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
cherno
Guest





PostPosted: Tue Apr 06, 2010 8:57 am    Post subject: Reply with quote

Is there any errorlevel that can be used with ShellFileOperation() ? (ex. If 'Cancel' was pressed)
Back to top
OceanMachine



Joined: 15 Oct 2007
Posts: 780
Location: England

PostPosted: Tue Apr 06, 2010 8:34 pm    Post subject: Reply with quote

SKAN's function returns the address of the fAnyOperationsAborted member of the SHFILEOPTSTRUCT Structure. You can use this to check if any operations were aborted, and if so use the error code to determine what the problem was.

I have modified the function slightly so you can see what I mean (changes in red)

Code:
SetBatchLines -1
SetWorkingDir, %A_ScriptDir%

imgPath := A_Temp . "orary Internet Files"
Loop, %imgPath%\*.gif, 0 ,1
     Source .= A_LoopFileLongPath "|"

Target := A_ScriptDir "\Gif_Files"

flags := ( FOF_RENAMEONCOLLISION := 0x8 ) | ( FOF_NOCONFIRMMKDIR := 0x200 )

If ( ErrorCode := ShellFileOperation( 0x2, Source, Target, flags ) ) ; the variable "ErrorCode" will hold the error value if there was one
   MsgBox, Error Code "%ErrorCode%".  Check http://msdn.microsoft.com/en-us/library/ms681381`%28v=VS.85`%29.aspx for explanation of the error code.

Return


ShellFileOperation( fileO=0x0, fSource="", fTarget="", flags=0x0, ghwnd=0x0 )     {

 If ( SubStr(fSource,0) != "|" )
      fSource := fSource . "|"

 If ( SubStr(fTarget,0) != "|" )
      fTarget := fTarget . "|"

 fsPtr := &fSource
 Loop, % StrLen(fSource)
  If ( *(fsPtr+(A_Index-1)) = 124 )
      DllCall( "RtlFillMemory", UInt, fsPtr+(A_Index-1), Int,1, UChar,0 )

 ftPtr := &fTarget
 Loop, % StrLen(fTarget)
  If ( *(ftPtr+(A_Index-1)) = 124 )
      DllCall( "RtlFillMemory", UInt, ftPtr+(A_Index-1), Int,1, UChar,0 )

 VarSetCapacity( SHFILEOPSTRUCT, 30, 0 )                 ; Encoding SHFILEOPSTRUCT
 NextOffset := NumPut( ghwnd, &SHFILEOPSTRUCT )          ; hWnd of calling GUI
 NextOffset := NumPut( fileO, NextOffset+0    )          ; File operation
 NextOffset := NumPut( fsPtr, NextOffset+0    )          ; Source file / pattern
 NextOffset := NumPut( ftPtr, NextOffset+0    )          ; Target file / folder
 NextOffset := NumPut( flags, NextOffset+0, 0, "Short" ) ; options

 ret := DllCall( "Shell32\SHFileOperationA", UInt,&SHFILEOPSTRUCT )  ; store the return value of the function (error code)
 
 Return NumGet( NextOffset+0 ) ? ret : 0 ; if the fAnyOperationsAborted member was true, return the error code, otherwise return 0.
}
Back to top
View user's profile Send private message
cherno
Guest





PostPosted: Wed Apr 07, 2010 3:47 pm    Post subject: Reply with quote

OceanMachine wrote:
SKAN's function returns the address of the fAnyOperationsAborted member of the SHFILEOPTSTRUCT Structure. You can use this to check if any operations were aborted, and if so use the error code to determine what the problem was.

I have modified the function slightly so you can see what I mean (changes in red)



Many thanks! Very Happy
Back to top
derRaphael



Joined: 23 Nov 2007
Posts: 841
Location: ~/.

PostPosted: Wed Aug 18, 2010 11:02 am    Post subject: Re: AHK Functions Reply with quote

SKAN wrote:
Dear Friends, Smile

Space()
Code:
Space(Width)
{
Loop,%Width%
Space=% Space Chr(32)
Return Space
}



this is a function with similar capabilities, yet more flexible, since it allows to specify any ansi char and its faster, since it uses less operations (eg no loop)

Code:
dup( length, char = " " )
{
   return ( length > 0 && VarSetCapacity( dup, length, asc(char) ) ) ? dup : false
}


per default it uses a space as the fillchar

greets
dR
_________________

    All scripts, unless otherwise noted, are hereby released under CC-BY
Back to top
View user's profile Send private message
Enter_User_Name_Here



Joined: 18 Apr 2010
Posts: 35
Location: Cincinnati, OH USA

PostPosted: Wed Aug 18, 2010 2:04 pm    Post subject: Reply with quote

SKAN wrote:
Laszlo wrote:
Goyyah wrote:
I will be glad if this code is optimised..

Code:
LDOM(TimeStr="") {
  If TimeStr=
     TimeStr = %A_Now%
  StringLeft Date,TimeStr,6 ; YearMonth
  Date1 = %Date%
  Date1+= 31,D              ; A day in next month
  StringLeft Date1,Date1,6  ; YearNextmonth
  Date1-= %Date%,D          ; Difference in days
  Return Date1
}


Dear Laszlo, :D

Brilliant! You always amaze me .. I would have never thought this way.
I wrote LDOM() 10 years before (in Foxpro) for a Payroll Software.
What I have presented here is a optimised version. ( I thought so! )

In the original function, I start with day 1 (for the given date) and
loop till the month changes and then break.. :shock:

I have to change the way I envision, I guess! :D

Thank you .. Regards, :)



Code:
  Date1+= 31,D              ; A day in next month

Won't this break if you are at the end of Jan (29, 30, 31)? Won't you push on in to March?
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Wed Aug 18, 2010 4:20 pm    Post subject: Reply with quote

Enter_User_Name_Here wrote:
Code:
  Date1+= 31,D              ; A day in next month

Won't this break if you are at the end of Jan (29, 30, 31)? Won't you push on in to March?


It will not.. It is Laszlo's code, I remind you.
The following part takes care of it:
Code:
StringLeft Date,TimeStr,6 ; YearMonth
Back to top
View user's profile Send private message Send e-mail
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Wed Aug 18, 2010 5:13 pm    Post subject: Re: AHK Functions Reply with quote

DerRaphael wrote:
Code:
dup( length, char = " " )
{
   return ( length > 0 && VarSetCapacity( dup, length, asc(char) ) ) ? dup : false
}


I tried that a long time ago, and it worked incorrectly for length < 3
.. and then Lexikos clarified me about VarSetCapacity()

You need to add a pair of additional VarSetCapacity()

Code:
dup( length, char = " " )
{
   VarSetCapacity( dup,64 ), VarSetCapacity( dup,0 )
   return ( length > 0 && VarSetCapacity( dup, length, asc(char) ) ) ? dup : false
}


I updated my Replicate() function as follows:

Code:
Replicate( Chr=" ", X=1 ) {
 Return VarSetCapacity( V, VarSetCapacity(V,VarSetCapacity(V,64)>>32)+X, Asc(Chr) ) ? V :
}

MsgBox, % Replicate( "/", 90 ) ; Example
Back to top
View user's profile Send private message Send e-mail
derRaphael



Joined: 23 Nov 2007
Posts: 841
Location: ~/.

PostPosted: Wed Aug 18, 2010 7:41 pm    Post subject: Re: AHK Functions Reply with quote

SKAN wrote:
I tried that a long time ago, and it worked incorrectly for length < 3
.. and then Lexikos clarified me about VarSetCapacity()

You need to add a pair of additional VarSetCapacity()

Code:
dup( length, char = " " )
{
   VarSetCapacity( dup,64 ), VarSetCapacity( dup,0 )
   return ( length > 0 && VarSetCapacity( dup, length, asc(char) ) ) ? dup : false
}


Yeah well, i tested only with 5 chars and u were perfectly right with lengths less than 3, however there is a different solution, which works without the need for two additional varsetcapacitys, so if you're for short codes this one's for you:

Code:
dup(l,c=" ")
{
return l>0&&(VarSetCapacity(_,l,asc(c))|Numput(0,_,l,"UChar"))? _:
}


edit

this one even repeats strings when passed as c
Code:
dup(l,c=" ") {
   return StrLen(c)=1 ? l>0&&(VarSetCapacity(_,l,asc(c))|Numput(0,_,l,"UChar"))? _::RegExReplace(dup(l)," ",c)
}


edit II

this function should be named String instead of dup
greets
dR
_________________

    All scripts, unless otherwise noted, are hereby released under CC-BY
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Wed Aug 18, 2010 8:17 pm    Post subject: Re: AHK Functions Reply with quote

DerRaphael wrote:


Code:
dup(l,c=" ")
{
return l>0&&(VarSetCapacity(_,l,asc(c))|Numput(0,_,l,"UChar"))? _:
}




Nice! Very Happy
Back to top
View user's profile Send private message Send e-mail
Lexikos



Joined: 17 Oct 2006
Posts: 7290
Location: Australia

PostPosted: Wed Aug 18, 2010 9:45 pm    Post subject: Reply with quote

Since VarSetCapacity fills bytes, not characters, that method won't work in Unicode builds. See infogulch's post and my responses.
Back to top
View user's profile Send private message Visit poster's website
derRaphael



Joined: 23 Nov 2007
Posts: 841
Location: ~/.

PostPosted: Wed Aug 18, 2010 10:00 pm    Post subject: Re: AHK Functions Reply with quote

Lexikos wrote:
Since VarSetCapacity fills bytes, not characters, that method won't work in Unicode builds. See infogulch's post and my responses.


even not this one?

DerRaphael wrote:
Code:
dup(l,c=" ") {
   return StrLen(c)=1 ? l>0&&(VarSetCapacity(_,l,asc(c))|Numput(0,_,l,"UChar"))? _::RegExReplace(dup(l)," ",c)
}


or does it fail due to the strlen() ?
_________________

    All scripts, unless otherwise noted, are hereby released under CC-BY
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7290
Location: Australia

PostPosted: Wed Aug 18, 2010 10:03 pm    Post subject: Reply with quote

It relies on VarSetCapacity either way and will therefore fail on Unicode builds regardless of how long 'c' is.
Back to top
View user's profile Send private message Visit poster's website
djmorgan911



Joined: 26 Aug 2010
Posts: 1

PostPosted: Thu Aug 26, 2010 2:00 pm    Post subject: Reply with quote

In regards to LDOM, is there a way to figure out what the year of the last month is? Example: I run a set of reports each month. They are run using last months dates. So if I automate this report to run in Feb, then last months year is the same as the current year but if I run it in Jan, I need it to figure out that last month was last year not the current year.

Hope I have made sense!
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Thu Aug 26, 2010 2:39 pm    Post subject: Reply with quote

Quote:
I need it to figure out that last month was last year not the current year


Code:
somedate=20100826

MsgBox, % YearOfPreviousMonth( somedate )

YearOfPreviousMonth( date ) {
 date += 0,D
 date := SubStr(date,1,6 )
 date += -1,D
 Return substr( date,1,4 )
}
Back to top
View user's profile Send private message Send e-mail
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Thu Aug 26, 2010 4:37 pm    Post subject: PE_FunctionExports() Reply with quote

Quote:
PE_FunctionExports()

Returns a linefeed-delimited-list of 'Exported Function Names' found in a Portable Executable file.

Usage Example:
Code:
MsgBox, % PE_FunctionExports( "shell32.dll" )


Output of above call:
Code:
Activate_RunDLL
AppCompat_RunDLLW
CDefFolderMenu_Create
CDefFolderMenu_Create2
CallCPLEntry16
CheckEscapesA
CheckEscapesW
CommandLineToArgvW
Control_FillCache_RunDLL
Control_FillCache_RunDLLA
Control_FillCache_RunDLLW
Control_RunDLL
Control_RunDLLA
Control_RunDLLAsUserW
Control_RunDLLW
DAD_AutoScroll
DAD_DragEnterEx
DAD_DragEnterEx2
DAD_DragLeave
DAD_DragMove
DAD_SetDragImage
DAD_ShowDragImage
DllCanUnloadNow
DllGetClassObject
DllGetVersion
DllInstall
DllRegisterServer
DllUnregisterServer
DoEnvironmentSubstA
DoEnvironmentSubstW
DragAcceptFiles
DragFinish
DragQueryFile
DragQueryFileA
DragQueryFileAorW
DragQueryFileW
DragQueryPoint
DriveType
DuplicateIcon
ExtractAssociatedIconA
ExtractAssociatedIconExA
ExtractAssociatedIconExW
ExtractAssociatedIconW
ExtractIconA
ExtractIconEx
ExtractIconExA
ExtractIconExW
ExtractIconResInfoA
ExtractIconResInfoW
ExtractIconW
ExtractVersionResource16W
FindExeDlgProc
FindExecutableA
FindExecutableW
FreeIconList
GetFileNameFromBrowse
ILAppendID
ILClone
ILCloneFirst
ILCombine
ILCreateFromPath
ILCreateFromPathA
ILCreateFromPathW
ILFindChild
ILFindLastID
ILFree
ILGetNext
ILGetSize
ILIsEqual
ILIsParent
ILLoadFromStream
ILRemoveLastID
ILSaveToStream
InternalExtractIconListA
InternalExtractIconListW
IsLFNDrive
IsLFNDriveA
IsLFNDriveW
IsNetDrive
IsUserAnAdmin
OpenAs_RunDLL
OpenAs_RunDLLA
OpenAs_RunDLLW
OpenRegStream
Options_RunDLL
Options_RunDLLA
Options_RunDLLW
PathCleanupSpec
PathGetShortPath
PathIsExe
PathIsSlowA
PathIsSlowW
PathMakeUniqueName
PathProcessCommand
PathQualify
PathResolve
PathYetAnotherMakeUniqueName
PickIconDlg
PifMgr_CloseProperties
PifMgr_GetProperties
PifMgr_OpenProperties
PifMgr_SetProperties
PrintersGetCommand_RunDLL
PrintersGetCommand_RunDLLA
PrintersGetCommand_RunDLLW
ReadCabinetState
RealDriveType
RealShellExecuteA
RealShellExecuteExA
RealShellExecuteExW
RealShellExecuteW
RegenerateUserEnvironment
RestartDialog
RestartDialogEx
SHAddFromPropSheetExtArray
SHAddToRecentDocs
SHAlloc
SHAllocShared
SHAppBarMessage
SHBindToParent
SHBrowseForFolder
SHBrowseForFolderA
SHBrowseForFolderW
SHCLSIDFromString
SHChangeNotification_Lock
SHChangeNotification_Unlock
SHChangeNotify
SHChangeNotifyDeregister
SHChangeNotifyRegister
SHChangeNotifySuspendResume
SHCloneSpecialIDList
SHCoCreateInstance
SHCreateDirectory
SHCreateDirectoryExA
SHCreateDirectoryExW
SHCreateFileExtractIconW
SHCreateLocalServerRunDll
SHCreateProcessAsUserW
SHCreatePropSheetExtArray
SHCreateQueryCancelAutoPlayMoniker
SHCreateShellFolderView
SHCreateShellFolderViewEx
SHCreateShellItem
SHCreateStdEnumFmtEtc
SHDefExtractIconA
SHDefExtractIconW
SHDestroyPropSheetExtArray
SHDoDragDrop
SHEmptyRecycleBinA
SHEmptyRecycleBinW
SHEnableServiceObject
SHEnumerateUnreadMailAccountsW
SHExtractIconsW
SHFileOperation
SHFileOperationA
SHFileOperationW
SHFindFiles
SHFind_InitMenuPopup
SHFlushClipboard
SHFlushSFCache
SHFormatDrive
SHFree
SHFreeNameMappings
SHFreeShared
SHGetAttributesFromDataObject
SHGetDataFromIDListA
SHGetDataFromIDListW
SHGetDesktopFolder
SHGetDiskFreeSpaceA
SHGetDiskFreeSpaceExA
SHGetDiskFreeSpaceExW
SHGetFileInfo
SHGetFileInfoA
SHGetFileInfoW
SHGetFolderLocation
SHGetFolderPathA
SHGetFolderPathAndSubDirA
SHGetFolderPathAndSubDirW
SHGetFolderPathW
SHGetIconOverlayIndexA
SHGetIconOverlayIndexW
SHGetImageList
SHGetInstanceExplorer
SHGetMalloc
SHGetNewLinkInfo
SHGetNewLinkInfoA
SHGetNewLinkInfoW
SHGetPathFromIDList
SHGetPathFromIDListA
SHGetPathFromIDListW
SHGetRealIDL
SHGetSetFolderCustomSettingsW
SHGetSetSettings
SHGetSettings
SHGetShellStyleHInstance
SHGetSpecialFolderLocation
SHGetSpecialFolderPathA
SHGetSpecialFolderPathW
SHGetUnreadMailCountW
SHHandleUpdateImage
SHHelpShortcuts_RunDLL
SHHelpShortcuts_RunDLLA
SHHelpShortcuts_RunDLLW
SHILCreateFromPath
SHInvokePrinterCommandA
SHInvokePrinterCommandW
SHIsFileAvailableOffline
SHLimitInputEdit
SHLoadInProc
SHLoadNonloadedIconOverlayIdentifiers
SHLoadOLE
SHLockShared
SHMapIDListToImageListIndexAsync
SHMapPIDLToSystemImageListIndex
SHMultiFileProperties
SHObjectProperties
SHOpenFolderAndSelectItems
SHOpenPropSheetW
SHParseDisplayName
SHPathPrepareForWriteA
SHPathPrepareForWriteW
SHPropStgCreate
SHPropStgReadMultiple
SHPropStgWriteMultiple
SHQueryRecycleBinA
SHQueryRecycleBinW
SHReplaceFromPropSheetExtArray
SHRestricted
SHRunControlPanel
SHSetInstanceExplorer
SHSetLocalizedName
SHSetUnreadMailCountW
SHShellFolderView_Message
SHSimpleIDListFromPath
SHStartNetConnectionDialogW
SHTestTokenMembership
SHUnlockShared
SHUpdateImageA
SHUpdateImageW
SHUpdateRecycleBinIcon
SHValidateUNC
SheChangeDirA
SheChangeDirExA
SheChangeDirExW
SheChangeDirW
SheConvertPathW
SheFullPathA
SheFullPathW
SheGetCurDrive
SheGetDirA
SheGetDirExW
SheGetDirW
SheGetPathOffsetW
SheRemoveQuotesA
SheRemoveQuotesW
SheSetCurDrive
SheShortenPathA
SheShortenPathW
ShellAboutA
ShellAboutW
ShellExec_RunDLL
ShellExec_RunDLLA
ShellExec_RunDLLW
ShellExecuteA
ShellExecuteEx
ShellExecuteExA
ShellExecuteExW
ShellExecuteW
ShellHookProc
ShellMessageBoxA
ShellMessageBoxW
Shell_GetCachedImageIndex
Shell_GetImageLists
Shell_MergeMenus
Shell_NotifyIcon
Shell_NotifyIconA
Shell_NotifyIconW
SignalFileOpen
StrChrA
StrChrIA
StrChrIW
StrChrW
StrCmpNA
StrCmpNIA
StrCmpNIW
StrCmpNW
StrCpyNA
StrCpyNW
StrNCmpA
StrNCmpIA
StrNCmpIW
StrNCmpW
StrNCpyA
StrNCpyW
StrRChrA
StrRChrIA
StrRChrIW
StrRChrW
StrRStrA
StrRStrIA
StrRStrIW
StrRStrW
StrStrA
StrStrIA
StrStrIW
StrStrW
WOWShellExecute
Win32DeleteFile
WriteCabinetState


The Function:
Code:
PE_FunctionExports( PEFile ) { ; Lists Exported Functions/ Comp@t: WIN32_NT +AHK +LA +LW
;By SKAN www.autohotkey.com/forum/viewtopic.php?p=379086#379086 CD:20100824/LM:20100825
 VarSetCapacity( $LI,48,0 ), DllCall( "ImageHlp\MapAndLoad", A_IsUnicode ? "AStr"
                                      : "Str",PEFile, Int,0, UInt,&$LI, Int,1, Int,1 )
 nPtr := DllCall( "ImageHlp\ImageRvaToVa", UInt,Numget( $LI,12 ), UInt,Numget( $LI,08 )
       , UInt, NumGet( ( P := DllCall( "ImageHlp\ImageDirectoryEntryToData", UInt
       , NumGet( $LI,8 ), Int,0, UShort,0, UIntP,nSz )) + 12 ), UInt,0 )
 VarSetCapacity( Var,1024,0 ), VarSetCapacity( List,10240,0 )
 IfEqual,nPtr,0, Return SubStr( DllCall( "ImageHlp\UnMapAndLoad", UInt,&$LI ), 0,0 )
 Loop % NumGet( P+24 ) + 1
  A_IsUnicode ? Var := DllCall( "MulDiv", Int,nPtr, Int,1, Int,1, AStr )
                : DllCall( "lstrcpy", Str,Var, UInt,nPtr )
, nPtr := nPtr+StrLen( Var )+1,  List .= "`n" Var, A_Index=1 ? Omit := StrLen( Var )+2 :
 StringTrimLeft, List, List, %Omit%
 DllCall( "ImageHlp\UnMapAndLoad", UInt,&$LI )
 Return List
}


Demo : Crazy Scripting : WinAPI Listing [New Version]
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 8, 9, 10, 11  Next
Page 9 of 11

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group