@sover-david said in [C#] Find Text In File:
I know you can use the Find in Files dialog with NPPM_LAUNCHFINDINFILESDLG but can you use the regular find?
NPPM_MENUCOMMAND will run any builtin menu with lParam providing the command ID: in this case, IDM_SEARCH_FIND to run Search > Find to launch the FIND dialog.
// open the FIND dialog
SendMessage( npp_hWnd, NPPM_MENUCOMMAND, 0, IDM_SEARCH_FIND);
Once inside the dialog, you should be able to search controls. If I understand things correctly, FindReplaceDlg_rc.h defines the control ID’s for each of the entries and buttons: in this case, I think you want IDFINDWHAT for the “Find What” text box.
I am starting to get out of my element, because for Win32 stuff, I am usually using a wrapper libary in Perl rather than truly programming in Win32 API code, so it sometimes provides wrapper functions that don’t map directly to Win32 API calls. But I think you would want to get the hWnd for the FIND dialog and maybe the edit control, then use WM_SETTEXT to the IDFINDWHAT entry:
find_dlg_hWnd = GetActiveWindow(); // or GetForegroundWindow(); // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getactivewindow
find_box_hWnd = GetDlgItem( find_dlg_hWnd , IDFINDWHAT ); // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdlgitem
SendMessage( find_box_hWnd, WM_SETTEXT, 0, "search text");
or maybe instead of getting the extra hwnd, just
SetDlgItemText( find_dlg_hWnd, IDFINDWHAT, "search text"); // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setdlgitemtexta
Then somehow, you would have to press the “FIND NEXT” button (but I wasn’t able to find the raw API equivalent of Perl’s Win32::GuiTest::PushChildButton or PushChildById, so I cannot link you to the right API command for pusing the button, sorry).
But if the SendText/SendWait is working for you, that’s probably sufficient.
For other reference, the NPP User Manual’s Searching Actions When Recorded As Macros seem to be using the control IDs as the parameters of the macro commands, so that might give you insight into the control IDs needed for other actions in the FIND family of dialogs … though I’m not sure they always line up with teh FindReplaceDlg_rc.h constants, so I’m not sure.