Im new to asm. Most of this code is from one of Iczelion's tutorials.






.data
ClassName db "SimpleWinClass",0
AppName db "Galahad Search",0
MenuName db "FirstMenu",0
ButtonClassName db "button",0
ButtonText db "SEARCH",0
EditClassName db "edit",0
hIconImage dd 0
hIcon dd 0
szOpen db "open",0
szUrl db "http://www.google.com/search?num=100&hl=en&as_q=",0


.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hwndButton HWND ?
hwndEdit HWND ?
buffer db 512,0 dup(?)




.const
ButtonID equ 1
EditID equ 2
IDM_EXIT equ 1

.code


start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
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 CreateWindowEx,WS_EX_APPWINDOW,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
CW_USEDEFAULT,300,200,NULL,NULL,\
hInst,NULL
mov hwnd,eax
INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
INVOKE UpdateWindow, hwnd
.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg




.ENDW


ret
WinMain endp



WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM





.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke CreateWindowEx,WS_EX_PALETTEWINDOW, ADDR EditClassName,NULL,\
WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or\
ES_AUTOHSCROLL,\
50,35,200,25,hWnd,EditID,hInstance,NULL
mov hwndEdit,eax
invoke SetFocus, hwndEdit
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonText,\
WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\
75,70,140,25,hWnd,ButtonID,hInstance,NULL
mov hwndButton,eax


.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF lParam==0
.IF ax==IDM_EXIT


invoke DestroyWindow,hWnd
.ENDIF
.ELSE
.IF ax==ButtonID
shr eax,16
.IF ax==BN_CLICKED
invoke GetWindowText,hwndEdit,ADDR buffer,512
invoke szCatStr, addr szUrl, addr buffer
invoke ShellExecute, NULL, addr szOpen,addr szUrl,0, NULL, SW_SHOWMAXIMIZED




.ENDIF
.ENDIF
.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret

WndProc endp







My problem is after a search i dont know how to reset szUrl to its original value.
Any help is appreciated.
Posted on 2003-02-10 19:00:37 by sample
invoke szCatStr, addr szUrl, addr buffer

That line is appending whatever string is in 'buffer' to 'szUrl' and it is impossible to "reset" the string to its original state, unless you record the length of the string before hand... but thats a little unorthodox, it is better to just create another string...
szNewUrl db 512 dup(?)

add that to your data section
invoke szCpyStr, addr szNewUrl, addr szUrl                                       [color=green]; Make a duplicate of szUrl[/color]

invoke szCatStr, addr szNewUrl, addr buffer [color=green]; append 'buffer' to the duplicate[/color]
invoke ShellExecute, NULL, addr szOpen,addr szNewUrl,0, NULL, SW_SHOWMAXIMIZED [color=green]; use szNewUrl instead of szUrl[/color]
Posted on 2003-02-10 20:14:01 by BubbaFate
If you want to reset szUrl to it's original value then you must store the value before changing it.

or you can do somehing like this:


.data
szUrl db "http://www.google.com/search?num=100&hl=en&as_q=" ;_NOTe No NULL terminator!
buffer db 512 dup (0)

.code

;fill in code here
invoke GetWindowText,hwndEdit,ADDR buffer,512
invoke ShellExecute, NULL, addr szOpen,addr szUrl,0, NULL, SW_SHOWMAXIMIZED
;fill in more code here


your exe will be 512 bytes larger because buffer is now in the initialised section.

With the above code you won't have to make a call to szCatStr. szUrl does not have NULL terminator so by declaring buffer directly after it, GetWindowText effectively appends the window text to the end of szUrl.

so if the edit control had in pr0rn then after the call to GetWindowText
szUrl would be http://www.google.com/search?num=100&hl=en&as_q=pr0rn
the original szUrl is always preserved.
Posted on 2003-02-10 20:18:24 by MArtial_Code
thanks guys, that got it
Posted on 2003-02-10 21:34:06 by sample