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

http://www.masmforum.com/simple/index.php?topic=2670.msg21076#msg21076
Posted on 2005-10-13 03:17:23 by Vortex
Lenin,

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
                   
                    search:
                    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
                       
                        found_the_string:
                        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
            not_found:
            invoke MessageBox, hWnd, 0, 0, MB_OK
            quit:

                invoke HeapFree, ProcessHeap, 0, pszEditText
                .endif
            invoke HeapFree, ProcessHeap, 0, pszStrText
            .endif


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--
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/a_functions.asp

One of my most used bookmarks.

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