hi ,all. how can i add a new line or new message in the editbox,not replace the messages that the editbox had.

can SetWindowText works?

Posted on 2005-08-13 14:55:36 by Abuseyourdna
Assuming my edit box had the message as follow:

      2.I like linkin park

i want to add :"3.I am from china",
i had tried this:
    invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr szText          ;szText db "3.I am from china",13,10,0

but the result just as follow:
              3.I am from china
              2.I like linkin park

how can i add the message after "2.I like linkin park" ?
Posted on 2005-08-13 15:15:59 by Abuseyourdna
Use WM_GETTEXT to get the Text into a Buffer, then use lstrcat to append strings to it and use WM_SETTEXT to set the text back.

NewLine db 13,10,0
AddedData db "Hello World",0
invoke SendMessage, hEdit, WM_GETTEXT, addr Buffer, Sizeof Buffer
invoke lstrcat, addr Buffer, addr Newline
invoke lstrcat, addr Buffer, addr Added Data
invoke SendMessage, hEdit, WM_SETTEXT, addr Buffer,0

Code Not Verified.
Posted on 2005-08-13 15:16:40 by JimmyClif
The idea is to use the EM_SETSEL message to deselect everything and then set caret position to the end of text.
Try something like this:

invoke SendMessage,hwndEdit,EM_SETSEL, -1, -1
invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr szText



PS: read some documentation if it doesn't work (MSDN).
Posted on 2005-08-13 15:32:50 by Kecol
oh,it doesnt work.

but i have another question,how can i undo the editbox operations?
i have defined a submenu named "UNDO"

IDM_UNDO equ 1

invoke CreateMenu
mov hwndMenu,eax
invoke CreatePopupMenu
mov esi,eax
invoke AppendMenu,hwndMenu,MF_POPUP,esi,addr MenuName
invoke AppendMenu,esi,MF_STRING,IDM_UNDO,addr submenu

if ax==IDM_UNDO
  invoke SendMessage,hwndEdit,EM_UNDO,0,0    ;but it doesnt work,tell me why?

Posted on 2005-08-13 16:41:56 by Abuseyourdna
Hey, you didn't check the API documentation. The idea was good but I made a mistake in the code.
This will work:

invoke SendMessage,hwndEdit,EM_SETSEL, -1, 0
invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr szText

Search the forum before asking. I will do the same before answering.

Posted on 2005-08-13 17:59:06 by Kecol
              invoke EnableMenuItem,hwndMenu,IDM_ADDRESS,MF_GRAYED
              invoke EnableMenuItem,hwndMenu,IDM_CLEAR,MF_ENABLED
              invoke SetWindowText,hwndEdit,addr buffer
              invoke SendMessage,hwndEdit,EM_SETSEL,-1,0             
              invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr try 

it doesnt work yet,why?

i have search the forum before asking question.but now, what i want to know is how to use  the EM_UNDO

Posted on 2005-08-14 00:00:14 by Abuseyourdna
i have tested the edit`control undo queue,it return false?why?

my program as follow:

.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

ClassName db "SimpleWinClass",0
AppName  db "Kernel Tools",0
MenuName db "&Function",0
MenuName1 db "&Edit",0
submenu1 db "&Kernel/PE Addr",0
submenu2 db "&Clear",0
submenu3 db "E&xit",0
submenu4 db "&Undo",0
outformat db "Base address of kernel:0x%XH",13,10
          db "Address of PE header  :0x%XH",0
try db "Haha,you make it!",13,10,0
EditClassName db "edit",0
szWarning db "Failure.:(",0

hInstance HINSTANCE ?
CommandLine LPSTR ?
hwndMenu DWORD ?
hwndEdit HWND ?
buffer db 1024 dup(?)               


IDM_EXIT equ 3
IDM_UNDO equ 4

    mov eax,
    .while word ptr !="ZM"
    dec eax
    mov edx,
    add edx,eax
    invoke wsprintf,addr buffer,addr outformat,eax,edx
    invoke GetModuleHandle, NULL
    mov    hInstance,eax
    invoke GetCommandLine
    mov CommandLine,eax
    invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
    invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
    LOCAL msg:MSG
    LOCAL hwnd:HWND
    mov  wc.cbSize,SIZEOF WNDCLASSEX
    mov  wc.style, CS_HREDRAW or CS_VREDRAW
    mov  wc.lpfnWndProc, OFFSET WndProc
    mov  wc.cbClsExtra,NULL
    mov  wc.cbWndExtra,NULL
    push  hInst
    pop  wc.hInstance
    mov  wc.hbrBackground,COLOR_BTNFACE+1
    mov  wc.lpszMenuName,OFFSET MenuName
    mov  wc.lpszClassName,OFFSET ClassName
    invoke LoadIcon,NULL,IDI_APPLICATION
    mov  wc.hIcon,eax
    mov  wc.hIconSm,eax
    invoke LoadCursor,NULL,IDC_ARROW
    mov  wc.hCursor,eax
    invoke RegisterClassEx, addr wc
    invoke CreateMenu
    mov hwndMenu,eax
    invoke CreatePopupMenu
    mov esi,eax
    invoke AppendMenu,hwndMenu,MF_POPUP,esi,addr MenuName
    invoke AppendMenu,esi,MF_STRING,IDM_ADDRESS,addr submenu1
    invoke AppendMenu,esi,MF_STRING,IDM_CLEAR,addr submenu2
    invoke AppendMenu,esi,MF_STRING,IDM_UNDO,addr submenu4
    invoke AppendMenu,esi,MF_SEPARATOR,NULL,NULL
    invoke AppendMenu,esi,MF_STRING,IDM_EXIT,addr submenu3
    invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR ClassName, \
                        ADDR AppName, WS_OVERLAPPED,\
                      360, 280,\
                      400,300,NULL,hwndMenu, hInst,NULL
    mov  hwnd,eax
    invoke ShowWindow, hwnd,SW_SHOWNORMAL
    invoke UpdateWindow, hwnd
        invoke GetMessage, ADDR msg,NULL,0,0
        .BREAK .IF (!eax)
        invoke TranslateMessage, ADDR msg
        invoke DispatchMessage, ADDR msg
    mov    eax,msg.wParam
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    .IF uMsg==WM_DESTROY
        invoke PostQuitMessage,NULL
        invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,NULL,\
                        WS_CHILD or WS_VISIBLE or WS_BORDER or WS_VSCROLL or ES_LEFT or\
                        ES_READONLY or ES_MULTILINE or ES_AUTOVSCROLL,\
        mov  hwndEdit,eax
            invoke EnableMenuItem,hwndMenu,IDM_CLEAR,MF_GRAYED
            .ELSEIF uMsg==WM_COMMAND
        mov eax,wParam
        .IF lParam==0
            .IF ax==IDM_ADDRESS
              invoke EnableMenuItem,hwndMenu,IDM_ADDRESS,MF_GRAYED
              invoke EnableMenuItem,hwndMenu,IDM_CLEAR,MF_ENABLED
              invoke SetWindowText,hwndEdit,addr buffer
              ;invoke SendMessage,hwndEdit,EM_SETSEL,0,-1             
              invoke SendMessage,hwndEdit,EM_REPLACESEL,0,addr try           
            .ELSEIF ax==IDM_CLEAR
                invoke SetWindowText,hwndEdit,NULL
                invoke EnableMenuItem,hwndMenu,IDM_ADDRESS,MF_ENABLED
                invoke EnableMenuItem,hwndMenu,IDM_CLEAR,MF_GRAYED
            .ELSEIF ax==IDM_UNDO
                invoke SendMessage,hwndEdit,EM_CANUNDO,0,0
                .if eax!=0
                invoke SendMessage,hwndEdit,EM_UNDO,0,0
                invoke MessageBox,NULL,addr szWarning,addr AppName,MB_ICONERROR
                invoke DestroyWindow,hWnd
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam
    xor    eax,eax
WndProc endp
end start

who can help me to solve the problem?
Posted on 2005-08-14 00:15:18 by Abuseyourdna
mov eax,
    .while word ptr !="ZM"
    dec eax
    mov edx,
    add edx,eax
    invoke wsprintf,addr buffer,addr outformat,eax,edx
    invoke GetModuleHandle, NULL

what the hell is the point in doing your little scan to find the kernel32 base address when you're using apis from it right after (GetModuleHandle)
is it to look leet or something?, if so you failed, a simple invoke GetModuleHandleA, offset kernel32text (where kernel32text = db 'kernel32.dll',00h) would do the same, and if you are going to do such a scan then it would be wise to do an exception handler to handle the possibility that the dword @ esp might not be inside kernel32 (forwarded/redirected import could cause this).. and try and use msdn as a reference too as previously advised
Posted on 2005-08-14 01:46:47 by evlncrn8