Jump to content

Logman

Active Members
  • Posts

    41
  • Joined

  • Last visited

Everything posted by Logman

  1. I would like to thank the author of this add-on for VSC for his excellent work! After a long time I needed to write some AutoIt script and I was able to do it in my favorite editor. The ability to run help directly from a keyword is very useful. Great job!
  2. Thanks guinness for respond. I finally used the function _Resource_GetAsBytes() instead of _Resource_GetAsRaw(), but I had another problem on my side... an older version of SciTE editor, so it wasn't possible to add any resource file. After upgrade everything works great. Thanks again
  3. I try get file size of a txt resource using _Resource_GetAsRaw() but without success. With the old UDF by Zedna, I get filesize with _ResourceGet() function. Using _Resource_GetAsBytes function() I get error 6. What is wrong? Oops... I'm sorry. I had last AutoIt but an older version of SciTE editor. After the upgrade is everything okay.
  4. I was too lazy to frequent backups my database on localhost via phpMyAdmin so I wrote a very simple script to backup databases via command com. Maybe it will be useful to someone... It backs up all or selected databases into one or separate sql files, e.g: single file output: 20130406.022354_drupal,test.sql separate files output: 20130406.022354_drupal.sql 20130406.022354_test.sql Recommended php utility to import .sql files into MySql: BigDump: Staggered MySQL Dump Importer #include <Array.au3> #include <Constants.au3> ; ------------------------------------------------------------------------ ; BACKUP MYSQL DATABASES ON LOCALHOST ; ------------------------------------------------------------------------ ; Definition and meaning: ; $export_defs ..... combine two constants: $cEXPORT_DB + ($cEXPORT_TO_... or $cEXPORT_AS_...) ; e.g. [ $cEXPORT_DB_ALL_DATABASES + $cEXPORT_TO_SINGLE_FILE ] => export all dbs to one file ; $custom_dbs ...... user-created databases. Use comma as separator, e.g. "drupal, joomla" ; $export_path ..... an export destination folder ; $dbUsr ........... user login credentials, usually 'root' ; $dbPwd ........... passwords for MySQL accounts ; $dbSrv ........... MySQL server, 127.0.0.1 for localhost ; $sMySqlPath ...... full path to MySQL bin directory ; $sSytemDbs ....... list of databases created during installation MySql app ; use this constants in variable $export_defs: Const $cEXPORT_DB_SYSTEMS_ONLY = 1 ; export default databases (e.g. XAMPP default databases) Const $cEXPORT_DB_NON_SYSTEMS = 2 ; export user-created databases (e.g. all non XAMPP default dbs) Const $cEXPORT_DB_ALL_DATABASES = 4 ; export all databases Const $cEXPORT_DB_CUSTOM_DATABASES = 8 ; export selected databases (e.g. 'Drupal' database only) Const $cEXPORT_TO_SINGLE_FILE = 128 ; export databases as one .sql file Const $cEXPORT_AS_SEPARATE_FILES = 256 ; export each stored database as separate .sql file ;=== user definition ===================================================>> Local $export_defs = $cEXPORT_DB_CUSTOM_DATABASES + $cEXPORT_AS_SEPARATE_FILES ;Local $export_defs = $cEXPORT_DB_NON_SYSTEMS + $cEXPORT_TO_SINGLE_FILE Local $custom_dbs = "drupal" ; as separator use comma, e.g. "drupal, joomla" Local $export_path = "E:\Backup\FullBackup\Aplikace\MySQL" Local $dbUsr = "root" Local $dbPwd = "123456" Local $dbSrv = "127.0.0.1" Local $sMySqlPath = "C:\xampp\mysql\bin\" Local $sSytemDbs = "cdcol, information_schema, mysql, performance_schema , phpmyadmin, test, webauth" ;=== user definition ==== (Do not change anything below this line) ====<< $export_path = StringRegExpReplace($export_path, "[\\/]+\z", "") & "\" $sMySqlPath = StringRegExpReplace($sMySqlPath, "[\\/]+\z", "") & "\" Local $sMySqlExe = FileGetShortName($sMySqlPath & "mysql.exe") Local $sMySqlDmpExe = FileGetShortName($sMySqlPath & "mysqldump.exe") Local $sFormat = "%s -u %s -p%s -h%s %s -e ""show databases"" -s -N" Local $sExtCmd = StringFormat($sFormat, $sMySqlExe, $dbUsr, $dbPwd, $dbSrv) Local $aSytemDbs = StringSplit(StringStripWS($sSytemDbs, 8), ",", 2) Const $2L = @LF & @LF If FileExists($sMySqlExe) <> 1 Then MsgBox(8240, "MySql.exe not found", "The mysql.exe not found!" & $2L & _ "The path '$export_path' is probably not being set properly.") Exit EndIf ; run in cmd Local $CMD = Run(@ComSpec & " /c " & $sExtCmd, "", @SW_HIDE, $STDERR_CHILD+$STDOUT_CHILD) ProcessWaitClose($CMD) Local $sMsg = StdoutRead($CMD) Local $sErr = StderrRead($CMD) ; if an error in mysql.exe (eg. server is not running) If StringInStr($sErr, "ERROR") <> 0 Then MsgBox(8208, "Error", $sErr) Exit EndIf If StringLen($sMsg) = 0 Then MsgBox(8208, "Error", "Failed to get databases names") Exit EndIf ; read all installed databases to $aAllDbs array Local $aAllDbs = StringSplit($sMsg, Chr(13), 2) For $i = UBound($aAllDbs) - 1 To 0 Step -1 $aAllDbs[$i] = StringStripWS($aAllDbs[$i],3) If StringLen($aAllDbs[$i]) = 0 Then _ArrayDelete($aAllDbs, $i) EndIf Next ; move requested names of databases to $aDbs array Select Case BitAND($export_defs, $cEXPORT_DB_SYSTEMS_ONLY) <> 0 $aDbs = $aSytemDbs Local $sResult = fncItemsInArray($aDbs, $aAllDbs) If @error Then MsgBox(8240, "Error", "Defined system database name '" & $sResult & "' not found!") Exit EndIf Case BitAND($export_defs, $cEXPORT_DB_NON_SYSTEMS) <> 0 $aDbs = fncArrayExclude($aAllDbs, $aSytemDbs) Case BitAND($export_defs, $cEXPORT_DB_ALL_DATABASES) <> 0 $aDbs = $aAllDbs Case BitAND($export_defs, $cEXPORT_DB_CUSTOM_DATABASES) <> 0 $aDbs = StringSplit(StringStripWS($custom_dbs, 8), ",", 2) Local $sResult = fncItemsInArray($aDbs, $aAllDbs) If @error Then MsgBox(8240, "Error", "Defined custom database name '" & $sResult & "' not found!") Exit EndIf EndSelect ; export Local $sOutFile Local $sFileFirstPart = $export_path & @YEAR & @MON & @MDAY & "." & @HOUR & @MIN & @SEC $sFormat = "%s --lock-all-tables -u %s -p%s -h%s %s > " & """" & "%s" & """" Select Case BitAND($export_defs, $cEXPORT_TO_SINGLE_FILE) <> 0 $sOutFile = FileGetShortName($sFileFirstPart & "_" & _ArrayToString($aDbs, ",") & ".sql") $sExtCmd = StringFormat($sFormat, $sMySqlDmpExe, $dbUsr, $dbPwd, $dbSrv, "-B " & _ _ArrayToString($aDbs, " "), $sOutFile) $CMD = RunWait(@ComSpec & " /c " & $sExtCmd, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) If FileExists($sOutFile) = 0 Then MsgBox(8208, "Error", "An error occurring during the export..." & $2L & "databases: " & _ _ArrayToString($aDbs, ", ") & @LF & "destination: " & $sOutFile) Exit EndIf Case BitAND($export_defs, $cEXPORT_AS_SEPARATE_FILES) <> 0 For $x = 0 To UBound($aDbs) - 1 $sOutFile = FileGetShortName($sFileFirstPart & "_" & $aDbs[$x] & ".sql") $sExtCmd = StringFormat($sFormat, $sMySqlDmpExe, $dbUsr, $dbPwd, $dbSrv, $aDbs[$x], $sOutFile) $CMD = RunWait(@ComSpec & " /c " & $sExtCmd, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) If FileExists($sOutFile) = 0 Then MsgBox(8208, "Error", "An error occurring during the export..." & $2L & "database: " & _ $aDbs[$x] & @LF & "destination: " & $sOutFile) Exit EndIf Next EndSelect ; final msg $sFormat = "%s database%s was exported:%s%s%sTo destination:%s%s" $sMsg = StringFormat($sFormat, UBound($aDbs), _iIf(UBound($aDbs) > 1, "s", ""), $2L, "- " & _ _ArrayToString($aDbs, @LF & "- "), $2L, $2L, $export_path) MsgBox(8256, "Done", $sMsg) Exit ; ------------------------------------------------------------------- ; Check if all items from $aSrc are included in $aCmp ; ------------------------------------------------------------------- Func fncItemsInArray($aSrc, $aCmp) Local $bFound, $i, $j For $i = 0 To UBound($aSrc) - 1 $bFound = False For $j = 0 To UBound($aCmp) - 1 If $aSrc[$i] = $aCmp[$j] Then $bFound = True ExitLoop EndIf Next If $bFound = False Then SetError(1) Return $aSrc[$i] EndIf Next Return 1 EndFunc ;==>> fncItemsInArray ; ------------------------------------------------------------------- ; Exclude items from array based on another array ; $iFirstIdx1: ... first index of $aAll ; $iFirstIdx2: ... first index of $aExclude ; ------------------------------------------------------------------- Func fncArrayExclude($aAll, $aExclude, $iFirstIdx1=0, $iFirstIdx2=0) Local $bFound, $i, $j, $aResult[1] For $i = $iFirstIdx1 To UBound($aAll) - 1 $bFound = False For $j = $iFirstIdx2 To UBound($aExclude) - 1 If $aAll[$i] = $aExclude[$j] Then $bFound = True ExitLoop EndIf Next If $bFound = False Then If StringLen($aResult[0]) <> 0 Then ReDim $aResult[UBound($aResult) + 1] EndIf $aResult[UBound($aResult)-1] = $aAll[$i] EndIf Next Return $aResult EndFunc ; ==>> fncArrayExclude ; ------------------------------------------------------------------- ; _Iif from MISC ; ------------------------------------------------------------------- Func _Iif($fTest, $vTrueVal, $vFalseVal) If $fTest Then Return $vTrueVal Else Return $vFalseVal EndIf EndFunc ;==>_Iif Export_MySql_Databases_v1.au3
  5. Yes, that's it! In the recovery console: explorer.exe ... is not running setup.exe ... is running winpeshl.exe ... is running It will be sufficient to verify that recovery console is running. Thanks
  6. I planned to check is process explorer.exe exists, but for moving the system folders like ProgramData and Users I want to use at least one other method for check is script is running only in recovery console. For example, after boot to a safe mode with command prompt the process explorer.exe is not running too, but in this mode, you cannot move the system folders. This is the main reason why I asked for a different method. I use robocopy to move both folders and if the OS is loaded the robocopy.exe reports an error, but some files and folder are already moved. I forgot to write that my OS is a Windows 7 64-bit
  7. I tried to run a compiled exe including a GUI in the recovery console and it works.
  8. I wrote a batch script (bat) designed for Windows Recovery Console (SHITF + F10 after boot from DVD), which automatically moves the Users and ProgramData folder to another drive and then create a junction link (mklink) to target destinations. But if I want to use system restore via restore point I have to boot from DVD again, start the Windows Recovery Console, and both linked folder move back to system drive... Batch script is very uncomfortable and I plan to rewrite it to AutoIt (it will not be a problem), but I need advice... How to check that AutoIt script (EXE) is executed from the Windows Recovery Console? Is there a way how to check that Windows is(not) loaded? (I do not know if it is appropriate to check if process explorer.exe exists...)
  9. LarsJ, thanks a lot. The modified code really works! Perfect! Only a small change in the UDF on line 373 (changed the first parameter from $hLV to $hWndFrom): _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem")) Functional sort: #include <GuiListView.au3> #include <EditConstants.au3> #include 'LV_Format_include.au3' Global $GUI Global $hLV Global $hListView Local $col = '' For $i = 1 To 5 $col &= $i & '|' Next ; Main GUI $GUI = GUICreate('') $hListView = GUICtrlCreateListView(StringTrimRight($col,1), 10, 10, 380, 150, -1, $LVS_EX_CHECKBOXES) ; << ListBox with checkboxes $hLV = GUICtrlGetHandle($hListView) For $i = 0 To 5 _GUICtrlListView_SetColumnWidth($hLV, $i, 75) Next ; initialize Global vars Local $aHWnd[1] = [$hLV] _GUICtrlListView_Formatting_Startup($GUI, $hLV) ; add new Items _GUICtrlListView_AddOrIns_Item($hLV, 'Test0|Test1|Test2|Test3|Test4|Test5') _GUICtrlListView_AddOrIns_Item($hLV, 'Blub0|Blub1|Blub2|Blub3|Blub4|Blub5') _GUICtrlListView_AddOrIns_Item($hLV, 'Club0|Club1|Club2|Club3|Club4|Club5') _GUICtrlListView_AddOrIns_Item($hLV, 'Blab0|Blab1|Blab2|Blab3|Blab4|Blab5') _GUICtrlListView_AddOrIns_Item($hLV, 'Bumm0|Bumm1|Bumm2|Bumm3|Bumm4|Bumm5') GUISetState(@SW_SHOW, $GUI) _GUICtrlListView_RegisterSortCallBack($hLV) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case Else EndSwitch Sleep (10) WEnd _GUICtrlListView_UnRegisterSortCallBack($hLV) ;... Thanks again so much!
  10. I can not sort checkboxes included in listview created by this UDF. Does anyone have any idea how to solve it? #include <GuiListView.au3> #include <EditConstants.au3> #include 'LV_Format_include.au3' $Debug_LV = False Global $GUI Global $hLV Global $hListView, $B_DESCENDING Local $col = '' For $i = 1 To 5 $col &= $i & '|' Next ; Main GUI $GUI = GUICreate('') ; LV_Format $hListView = GUICtrlCreateListView(StringTrimRight($col,1), 10, 10, 380, 150, -1, $LVS_EX_CHECKBOXES) ; << ListBox with checkboxes $hLV = GUICtrlGetHandle($hListView) For $i = 0 To 5 _GUICtrlListView_SetColumnWidth($hLV, $i, 75) Next ; initialize Global vars Local $aHWnd[1] = [$hLV] _GUICtrlListView_Formatting_Startup($GUI, $hLV) ; add new Items _GUICtrlListView_AddOrIns_Item($hLV, 'Test0|Test1|Test2|Test3|Test4|Test5') _GUICtrlListView_AddOrIns_Item($hLV, 'Blub0|Blub1|Blub2|Blub3|Blub4|Blub5') _GUICtrlListView_AddOrIns_Item($hLV, 'Club0|Club1|Club2|Club3|Club4|Club5') _GUICtrlListView_AddOrIns_Item($hLV, 'Blab0|Blab1|Blab2|Blab3|Blab4|Blab5') _GUICtrlListView_AddOrIns_Item($hLV, 'Bumm0|Bumm1|Bumm2|Bumm3|Bumm4|Bumm5') ;~ ; standard way ;~ $hListView = GUICtrlCreateListView(StringTrimRight($col,1), 10, 10, 380, 150, -1, $LVS_EX_CHECKBOXES) ; << ListBox with checkboxes ;~ $hLV = GUICtrlGetHandle($hListView) ;~ GUICtrlCreateListViewItem('Test0|Test1|Test2|Test3|Test4|Test5', $hListView) ;~ GUICtrlCreateListViewItem('Blub0|Blub1|Blub2|Blub3|Blub4|Blub5', $hListView) ;~ GUICtrlCreateListViewItem('Club0|Club1|Club2|Club3|Club4|Club5', $hListView) ;~ GUICtrlCreateListViewItem('Blab0|Blab1|Blab2|Blab3|Blab4|Blab5', $hListView) ;~ GUICtrlCreateListViewItem('Bumm0|Bumm1|Bumm2|Bumm3|Bumm4|Bumm5', $hListView) ;~ For $i = 0 To 5 ;~ _GUICtrlListView_SetColumnWidth($hLV, $i, 75) ;~ Next GUISetState(@SW_SHOW, $GUI) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case Else EndSwitch Sleep (10) WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iCode, $tNMHDR $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) ; a LV_Format sort function ; __GUICtrlListView_SimpleSort($hLV, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; modified to sort also IParam __GUICtrlListView_SimpleSort($hLV, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; modified to sort also IParam ; standard way ;_GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY
  11. Yes, you're right. The problem is in the FileOpen() function, which returns no error. #include <File.au3> Local $sTmpFile = _TempFile(@SystemDir) $hFile = FileOpen($sTmpFile, 2 + 8 + 16) If @error Then MsgBox(0, "Error handle", "An error while opening file.") ; <<-- this message does not show Exit EndIf If $hFile = -1 Then MsgBox(0, "Error", "Unable to open file.") ; <<-- this message always appears Exit EndIf FileClose($sTmpFile) What about change the causing line in _ResourceSaveToFile(): ; ... $FileHandle = FileOpen($FileName, 2+16+$CreatePath) If @error Then Return SetError(2, 0, 0) ; ... to ; ... $FileHandle = FileOpen($FileName, 2+16+$CreatePath) If $FileHandle = -1 Then Return SetError(2, 0, 0) ; ... And maybe the line with FileWrite() function...
  12. The problem is that _ResourceSaveToFile() return no error when installing to a system folder without authorization. ... _ResourceSaveToFile($sDestFile,$sResName,$sResType,$ResLang,$CreatePath,$DLL) If @error Then Return -1 EndIF ... So before installation I have to check with an external function if destination folder is writable.
  13. Zedna, I'm sorry, but I have another question about _ResourceSaveToFile function. I'm trying to install a file to a folder with administrator privileges only. Compiled file running as administrator will install fine, but without an administrator nothing happens. The function below returns always the same result. Func installResourceFile($sDestFile, $sResName, $sResType=10, $ResLang=0, $CreatePath=1, $DLL = -1) ; get filesize first _ResourceGet($sResName, $sResType, $ResLang, $DLL) If @error Then Return -1 Local $filesize = @extended If $filesize = 0 Then Return -2 Local $result = _ResourceSaveToFile($sDestFile,$sResName,$sResType,$ResLang,$CreatePath,$DLL) MsgBox(0, '$result', $result) ; <<-- ?? If @error Then MsgBox(0, 'Error', 'Some error') ; <<-- ?? Return -1 EndIf While 1 If FileExists($sDestFile) And FileGetSize($sDestFile) = $filesize Then ExitLoop Sleep(100) WEnd Return 1 EndFunc ; ==>> installResourceFile I do not want to run the application as admin and I'll have to check the user right of each folder before installing each file. Is there the possibility to return different values ​​for successful and unsuccessful _ResourceSaveToFile? Yashied, I meant to get a file version of DLL that is included as resource only: Yashied, I meant to get a file version of DLL that is included as resource only: #... #AutoIt3Wrapper_Res_File_Add=resources\SQLite3.dll, rt_rcdata, SQL_FILE_1 #AutoIt3Wrapper_Res_File_Add=resources\SQLite3_x64.dll, rt_rcdata, SQL_FILE_2 #...
  14. It is a pity, but I understand. I wanted to avoid the manual definition of a constant in the script. I prefer the way 'Copy & Play' - all fully automated.
  15. Zedna, your UDF is really useful. One question... How to get the file version of the included file? I would like to compare the version of SQLite3.dll files (compare the file distributed with application and a dll installed on the client PC).
  16. That's it! I overlooked it. Thanks
  17. Yashied, I have a small problem with the function _GUICtrlHKI_GetHotKey, that returns the wrong value. I used an example from the first post in the following code where I try to change the shortcut key twice, but the second set returns wrong result. In the following example I am trying to change the hotkey shortcut from F12 to F11 and then back to F12. No change from F11 to F12. Where is the problem? Thanks #Include <APIConstants.au3> #Include <GUIConstantsEx.au3> #Include <HotKeyInput.au3> Local $iMyHotKey = 123 ; F12 ; F11 (122) ; F12 (123) $iMyHotKey = _changeHotKey($iMyHotKey) ; <<--- manually change from F12 to F11 then click to OK ConsoleWrite ('1: ' & $iMyHotKey & @LF) ; <<--- Correct (122) $iMyHotKey = _changeHotKey($iMyHotKey) ; <<--- manually change from F11 to F12 then click to OK ConsoleWrite ('2: ' & $iMyHotKey & @LF) ; <<--- WRONG! Still 122 instead of 123 $iMyHotKey = _changeHotKey($iMyHotKey) ; you can see wrong value... Exit Func _changeHotKey($iOldHK) Local $Form, $HKI1, $HKI2, $Button, $Text, $NewHK $Form = GUICreate('Test', 300, 160) GUISetFont(8.5, 400, 0, 'Tahoma', $Form) $HKI1 = _GUICtrlHKI_Create($iOldHK, 56, 55, 230, 20) ; <<---- OLD HotKey as default ; Lock CTRL-ALT-DEL for Hotkey Input control, but not for Windows _KeyLock(0x062E) GUICtrlCreateLabel('Hotkey1:', 10, 58, 44, 14) GUICtrlCreateLabel('Click on Input box and hold a combination of keys.' & @CR & 'Press OK to view the code.', 10, 10, 280, 28) $Button = GUICtrlCreateButton('OK', 110, 124, 80, 23) GUICtrlSetState(-1, BitOR($GUI_DEFBUTTON, $GUI_FOCUS)) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE $NewHK = -1 ExitLoop Case $Button $NewHK = _GUICtrlHKI_GetHotKey($HKI1) ; <<--- second call returns the wrong result ? ExitLoop EndSwitch WEnd GUIDelete ($Form) Return $NewHK EndFunc ; ==>> _changeHotKey
  18. Yashied, I tried it and it works well! That's what I needed! You are King! Thanks a lot.
  19. No response? I try to rephrase the question... How do I get KeyNameText of virtual-key code for a specific (and installed) keyboard layout? I tried to search this forum, the MSDN library, but unfortunately I could not find a solution. The code below will return same result. Function __WinAPI_MapVirtualKeyEx does not accept the parameter $sKbLayout. The function alway returns only KeyNameText for default keyboard layout specified in Regional and language settings. ; # Question: How do I get the correct name of the key for each keyboard layout? ; # Note: I know two parameters: Virtual codes & KB Layout ; # Note: Both types of keyboards have been installed (Win7 x64, Au3: 3.3.8.1) ; local $sCurrentKbLayout = hex(_WinAPI_GetKeyboardLayout(_WinAPI_GetForegroundWindow()),4) ; $VK_3 >> 0x33: (US keyboard = '3', CS keyboard = 'š') Const $VK_3 = 0x33 ; two types of keyboard layout Const $US_KbLayout = '0409' Const $CS_KbLayout = '0405' ConsoleWrite('KeyNameText(US KB): ' & __WinAPI_GetKeyNameText(BitShift(__WinAPI_MapVirtualKeyEx(hex($VK_3), $US_KbLayout), -16)) & @CR) ConsoleWrite('KeyNameText(CS KB): ' & __WinAPI_GetKeyNameText(BitShift(__WinAPI_MapVirtualKeyEx(hex($VK_3), $CS_KbLayout), -16)) & @CR) ; << same result Func __WinAPI_MapVirtualKeyEx($sHexKey, $sKbLayout) Local Const $MAPVK_VK_TO_VSC = 0 Local Const $MAPVK_VSC_TO_VK = 1 Local Const $MAPVK_VK_TO_CHAR = 2 Local Const $MAPVK_VSC_TO_VK_EX = 3 Local Const $MAPVK_VK_TO_VSC_EX = 4 Local $Ret = DllCall('user32.dll', 'long', 'MapVirtualKeyEx', 'int', '0x' & $sHexKey, 'int', $MAPVK_VK_TO_VSC, 'int', '0x' & $sKbLayout) Return $Ret[0] EndFunc ;==>_WinAPI_MapVirtualKeyEx Func __WinAPI_GetKeyNameText($lParam) Local $Ret = DllCall('user32.dll', 'int', 'GetKeyNameTextW', 'long', $lParam, 'wstr', '', 'int', 256) If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, '') EndIf Return $Ret[2] EndFunc ;==>__WinAPI_GetKeyNameText I'm really confused. Thanks for any guidance.
  20. Yashied, your UDF is perfect as always, just very hard to read. I'm trying to change the output to controls for current keyboard layout. For example, if the user switches the keyboard to another language, then will not be able to identify defined shortcuts in the future: US KB (0x0409): Ctrl + 3 CS KB (0x0405): Ctrl + 3 (but Ctrl + š is correctly) For this case I tried to modify your UDF function with _WinAPI_GetKeyNameText($lParam) called via GUIRegisterMsg($WM_KEYDOWN, 'WM_KEYDOWN'), but I was unable to incorporate into your script and obtain the correct parameter ($lParam) for the translation of a key. So, Is there any way to get the correct keyname for any keyboard? This solution is useful, but only for the default KBLayout: Moreover, ability to translate keycode->name for current keyboard layout may be useful for parsing a reading stored shorcuts. Thanks for UDF and any tip
  21. Wraithdu, this UDF is very useful for me! The ability to save and restore the entire clipboard contents I really missed! Thanks a lot
  22. From time to time I need to convert 24bit RGB color depth to 16bit depth, exactly to RGB555 (15bit: rrrrrggggg0bbbbb) and vice versa. I wrote a two simple conversion functions. Maybe there is a faster way for converting color depth, will anyone know (GDI, WinAPI)? Func _ConvertRGB_24b_to_16b555($R, $G, $B) $R = BitShift($R, 3) $G = BitShift($G, 3) $B = BitShift($B, 3) $R = BitShift($R, -11) $G = BitShift($G, -6) Return Hex(BitOR($R, $G, $B), 4) EndFunc Func _ConvertRGB_16b555_to_24b($16b, ByRef $R, ByRef $G, ByRef $B) $R = BitShift($16b, 11) $R = Hex (BitShift($R, -3), 2) $G = BitAND ($16b, "0x7C0") ;mask $G = Hex (BitShift($G, 3), 2) $B = BitAND ($16b, "0x1F") ;mask $B = Hex (BitShift($B, -3), 2) EndFunc
  23. Hi, I have simple question. How to remain Index (Row) of a ControlID after sorting in ListView? #include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> Dim $nCurCol = -1 Dim $nSortDir = 1 Dim $bSet = 0 Dim $nCol = -1 Dim $MyArr[10] Dim $CtlrID[10] _dumpArr_for_test_only() ; GUI GUICreate("Retrieve Row after sorting",220, 270) $hListView = GUICtrlCreateListView ("colA|colB|colC|colD",10, 10, 200, 200) $Btn_Ret = GUICtrlCreateButton("Retrieve Row from $CtlrID[5]", 25, 230, 170, 25, 0) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) ; create rows For $i = 0 To UBound($MyArr) - 1 $CtlrID[$i] = GUICtrlCreateListViewItem($MyArr[$i], $hListView) ; Next GUICtrlSetBkColor ($CtlrID[5], 0xff0000) GUICtrlRegisterListViewSort($hListView, "LVSort") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Btn_Ret msgbox (0,"Row No.", "RowIndex (Index) of $CtlrID[5] is: " & "??") ;?? <= I need get Row (Index) from ControlID Case $hListView $bSet = 0 $nCurCol = $nCol DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($hListView), "int", 0, "int", 1) EndSwitch WEnd ; for example only Func _dumpArr_for_test_only() Local $bTmp = true, $sTmp For $i = 0 To UBound($MyArr) - 1 Switch $i Case 2, 5, 7 $sTmp = "Err" Case Else $sTmp = "OK" EndSwitch $bTmp = Not $bTmp $MyArr[$i] = $i & "|" & UBound($MyArr)-$i-1 & "|" & $bTmp & "|" & $sTmp Next EndFunc ; Our sorting callback funtion Func LVSort($hWnd, $nItem1, $nItem2, $nColumn) Local $nSort Local $tInfo = DllStructCreate($tagLVFINDINFO) DllStructSetData($tInfo, "Flags", $LVFI_PARAM) ; Switch the sorting direction If $nColumn = $nCurCol Then If Not $bSet Then $nSortDir = $nSortDir * - 1 $bSet = 1 EndIf Else $nSortDir = 1 EndIf $nCol = $nColumn DllStructSetData($tInfo, "Param", $nItem1) $val1 = _GUICtrlListView_FindItem($hWnd, -1, $tInfo) DllStructSetData($tInfo, "Param", $nItem2) $val2 = _GUICtrlListView_FindItem($hWnd, -1, $tInfo) $val1 = _GUICtrlListView_GetItemText($hWnd, $val1, $nColumn) $val2 = _GUICtrlListView_GetItemText($hWnd, $val2, $nColumn) $nResult = 0 ; No change of item1 and item2 positions If $val1 < $val2 Then $nResult = -1 ; Put item2 before item1 ElseIf $val1 > $val2 Then $nResult = 1 ; Put item2 behind item1 EndIf $nResult = $nResult * $nSortDir Return $nResult EndFunc ;==>LVSort
×
×
  • Create New...