Advertisement
Najeebsk

SEARCH-TEXT3.ahk

Apr 17th, 2023
1,290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*   INFO
  2.    NAJEEB SEARCH TEXT UTILITY 2023
  3.    Written by: Najeeb Shah Khan (najeebshahkhan@gmail.com)
  4.    Last Modified: 3-25-2023
  5. */
  6. ;#warn
  7. #NoEnv
  8. #LTrim
  9. #SingleInstance, Force
  10. Process, Priority, , A
  11. SendMode, Input
  12. SetBatchLines, -1
  13. ;#NoTrayIcon
  14. SetKeyDelay 0    ; In case SendInput is not available
  15. SetTitleMatchMode RegEx
  16. SetWorkingDir %A_WorkingDir% ;%A_ScriptDir%
  17. FileSelectFile, SelectedFile, 3, , Open a file
  18. FileRead, FileContents, %SelectedFile%
  19. ;Sort, FileContents
  20. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  21. FileCreateDir, %A_ScriptDir%\DATA
  22. FileInstall , SEARCH-TEXT3.ahk, %A_ScriptDir%\DATA\SEARCH-TEXT3.ahk, 1
  23. FileInstall , S12.she, %A_ScriptDir%\DATA\S12.she, 1
  24. FileInstall , SkinH_EL.dll, %A_ScriptDir%\DATA\SkinH_EL.dll, 1
  25. FileSetAttrib +HS, %A_ScriptDir%\DATA\S12.she, 2
  26. FileSetAttrib +HS, %A_ScriptDir%\DATA\SkinH_EL.dll, 2
  27. FileSetAttrib +HS, %A_ScriptDir%\DATA\SEARCH-TEXT3.ahk, 2
  28. FileSetAttrib +HS, %A_ScriptDir%\DATA, 2
  29. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  30. SkinForm(Apply, A_ScriptDir . "\DATA\SkinH_EL.dll", A_ScriptDir . "\DATA\S12.she")
  31. OnExit, GetOut
  32. Gui 1:Color, 091D33, 091D33
  33. Gui 1:Font, s16 cDDDDDD, Calibri
  34. Gui 1:Add,Text,X50 Y7, ~~~************ NAJEEB SEARCH TEXT UTILITY 2023************~~~
  35. Gui 1:Font, s12 cDDDDDD, Calibri
  36. Gui 1:Add, Button, x10 y45 gFindString, SEARCH TEXT
  37. Gui 1:Add, Edit, x130 y47 w565 vfind
  38. Gui 1:Add, Edit, x10 y85 w700 r28 vcontent HSCROLL, %FileContents%
  39. Gui 1:Add, StatusBar,, Type the search string to look for and click the Search-button
  40. ;SB_SetParts(300)
  41. Gui 1:Show, w720 h672, FindSample
  42. WinGet ControlID, ID, FindSample
  43.  
  44. FindString:
  45. Gui, Submit, Nohide
  46.  
  47. if (find != lastFind) {
  48. offset = 0
  49. hits = 0
  50. }
  51.  
  52. GuiControl 1:Focus, Content ; focus on main help window to show selection
  53. SendMessage 0xB6, 0, -999, Edit2, ahk_id %ControlID% ; Scroll to top
  54. StringGetPos pos, Content, %find% ,,offset ; find the position of the search string
  55. if (pos = -1) {
  56. if (offset = 0) {
  57. SB_SetText("'" . find . "' not found", 1)
  58. SB_SetText("", 2)
  59. }
  60. else {
  61. SB_SetText("No more occurrences of '" . find . "'")
  62. SB_SetText("", 2)
  63. offset = 0
  64. hits = 0
  65. }
  66. return
  67. }
  68. StringLeft __s, Content, %pos% ; cut off end to count lines
  69. StringReplace __s,__s,`n,`n,UseErrorLevel ; Errorlevel <- line number
  70. addToPos=%Errorlevel%
  71. SendMessage 0xB6, 0, ErrorLevel, Edit2, ahk_id %ControlID% ; Scroll to visible
  72. SendMessage 0xB1, pos + addToPos, pos + addToPos + Strlen(find), Edit2, ahk_id %ControlID% ; Select search text
  73. ; http://msdn.microsoft.com/en-us/library/bb761637(VS.85).aspx
  74. ; Scroll the caret into view in an edit control:
  75. SendMessage, EM_SCROLLCARET := 0xB7, 0, 0, Edit2, ahk_id %ControlID%
  76. offset := pos + addToPos + Strlen(find)
  77. lastFind = %find%
  78. hits++
  79. SB_SetText("'" . find . "' found in line " . addToPos + 1, 1)
  80. SB_SetText(hits . (hits = 1 ? " hit" : " hits"), 2)
  81. Return
  82. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  83. GetOut:
  84. ;GuiClose:
  85. Gui, Hide
  86. SkinForm(0)
  87. ExitApp
  88. return
  89.  
  90. SkinForm(Param1 = "Apply", DLL = "", SkinName = ""){
  91.     if(Param1 = Apply){
  92.         DllCall("LoadLibrary", str, DLL)
  93.         DllCall(DLL . "\SkinH_AttachEx", AStr,SkinName, Str,"mhgd")
  94.     }else if(Param1 = 0){
  95.         DllCall(DLL . "\USkinExit")
  96.         }
  97. }
  98. Clip:
  99.  Gui, Submit, NoHide
  100.   Clipboard := results
  101. Return
  102. ;=-=-=-=-=-=-=-=-=-=- END SCRIPT -=-=-=-=-=-=-=-=-=-=-=-
  103. #R::Reload
  104. #S::Suspend
  105. #P::Pause
  106. ESC::ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement