Hi, I want to implement a search function in my notepad but I don't know how to.... I wonder if anyone can tell me wich way does notepad uses in it search dialog... I was reading a code that uses repnz scasb, repz cmpsb but it's too complicated and since notepad was coded in C there might be an easyer way to do it.
Posted on 2005-10-12 22:47:16 by Lenin
For a quick and cheesy search, you can try strstr() ... the str* functions from libc are generally unsafe, though, buffer overflows and all.
Posted on 2005-10-13 03:06:05 by f0dder
You can use the strstr function from msvcrt.dll
Posted on 2005-10-13 03:12:01 by Vortex
The same function is also available from Pelle's C run-time static library crt.lib

Posted on 2005-10-13 03:17:23 by Vortex

If you are using a rich text editor, it has the capacity to find text using the EM_FINDTEXTEX message.
Posted on 2005-10-13 10:05:07 by hutch--
I have decided for the hardest way, but I'm having problems with it...

            .if ax==IDB_FNDNXT
            invoke GetDlgItem, hWnd, IDE_TEXT
            invoke GetWindowTextLength, eax
            inc eax
            mov dwStrLen, eax
            inc eax
            invoke HeapAlloc, ProcessHeap, HEAP_ZERO_MEMORY, eax
            .if eax != NULL
                mov pszStrText, eax
                invoke GetDlgItemText, hWnd, IDE_TEXT, pszStrText, dwStrLen
                invoke GetWindowTextLength, hwndEdit
                inc eax
                mov dwEditLen, eax
                invoke HeapAlloc, ProcessHeap, HEAP_ZERO_MEMORY, eax
                .if eax != NULL
                    mov pszEditText, eax
                    invoke GetWindowText, hwndEdit, pszEditText, dwEditLen

                    mov edi, pszEditText
                    mov ecx, dwEditLen
                    mov esi, pszStrText
                    mov al, byte ptr
                    repnz scasb
                    test ecx, ecx
                    jz not_found

                    push ecx
                    push edi
                    push esi

                    dec edi
                    mov ecx, dwStrLen
                    repz cmpsb
                    test ecx, ecx
                    jz found_the_string
                        pop esi
                        pop edi
                        pop ecx
                        jmp search
                        pop esi
                        pop edi
                        pop ecx

                        dec edi
                        inc ecx
                        mov eax, dwEditLen
                        sub eax, ecx ; eax = start of selection
                        mov ebx, dwStrLen
                        add ebx, eax ; ebx = end of selection
                    invoke SendMessage, hwndEdit, EM_SETSEL, eax, ebx

            jmp quit
            invoke MessageBox, hWnd, 0, 0, MB_OK

                invoke HeapFree, ProcessHeap, 0, pszEditText
            invoke HeapFree, ProcessHeap, 0, pszStrText

I don't selects the right text, but when there's no match it alerts me.

I'm also having some problems with my hotkeys... I've been using RegisterHotkey to do so but it sets system-wide hotkeys, wich are giving me several problems (like traping other programs hotkeys...), how would I set a hotkey that only affects my program? Without having to use hooks...
Posted on 2005-10-15 12:02:58 by Lenin
:sad: Awnser my questions.... :P

I have one more question by the way... How do I add a menu to a dialog? I searched in google and found a lot of MFC stuff and a function (SHCreateMenuBar) that masm seems to never have heard of before.
Posted on 2005-10-17 20:04:06 by Lenin
Get the actual window handle of the dialog and use the normal method used in CreateWindowEx() windows.
Posted on 2005-10-18 04:34:03 by hutch--

One of my most used bookmarks.

Posted on 2005-10-18 08:23:53 by number2pencil