I got it to work, but then when I exit , it doesn't really exit, the program is still there. I removed the GetOpenFileName code, and it worked fine. I think it has something to do with memory but I'm not sure........
Posted on 2002-09-27 14:16:10 by CyberGuy
Probably your messing with the stack. It's probably an unbalanced stack. Or your application is not calling PostQuitMessage or something. If you can post some code, that would be nice than just guessing here.

Here's a sample program to do just that. Though I have stripped this program from its features because this is a personal project.

Note: To move the window around, just drag any part of the window excluding on the edit and button controls part.

Warning: The code style may not be to your liking but don't worry, the important parts are the ones you should look at.








and the call to GetOpenFileName.

Tested on Win2k SP3.
Posted on 2002-09-28 01:34:27 by stryker
Thanks for the example, but i still can't figure out whats wrong
Sorry for not posting the code, here it is:
format PE GUI 4.0

entry start

include 'include\kernel.inc'
include 'include\user.inc'
include 'include\comdlg.inc'
include 'include\gdi.inc'

include 'include\macro\stdcall.inc'
include 'include\macro\import.inc'
include 'include\macro\resource.inc'

section '.data' data readable writeable

var1 dw 0
mainhwnd dd 0 ; handle of window
hinstance dd 0 ; handle of module
edit dd 0
msg MSG
wc WNDCLASS
size RECT
deffont LOGFONT
font_face db 'MS Sans Serif',0
dopen OPENFILENAME

_title db 'My Notepad',0
_class db 'FASMWIN32',0

_edit db 'EDIT',0
_filter db "Text Files (*.txt)",0,"*.txt",0
default_extension db 'TXT',0

OPEN = 932
SAVE = 933
SAVEAS = 934
EXIT = 935
COPY = 936
PASTE = 937
CUT = 938
ALL = 939
UNDO = 940

section '.code' code readable executable

start:

invoke GetModuleHandle,0
mov [hinstance],eax
invoke LoadIcon,0,IDI_APPLICATION
mov [wc.hIcon],eax
invoke LoadCursor,0,IDC_ARROW
mov [wc.hCursor],eax
mov [wc.style],0
mov [wc.lpfnWndProc],WindowProc
mov [wc.cbClsExtra],0
mov [wc.cbWndExtra],0
mov eax,[hinstance]
mov [wc.hInstance],eax
mov [wc.hbrBackground],COLOR_BTNFACE+1
mov [wc.lpszMenuName],0
mov [wc.lpszClassName],_class
invoke RegisterClass,wc

invoke LoadMenu,[hinstance],29
invoke CreateWindowEx,0,_class,_title,WS_MINIMIZEBOX+WS_THICKFRAME+WS_MAXIMIZEBOX+WS_SYSMENU,78,78,640,480,NULL,eax,[hinstance],NULL
mov [mainhwnd],eax
invoke ShowWindow,[mainhwnd],SW_SHOWDEFAULT
msg_loop:
invoke GetMessage,msg,NULL,0,0
or eax,eax
jz end_loop
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msg_loop

end_loop:
invoke ExitProcess,[msg.wParam]

proc WindowProc, hwnd,wmsg,wparam,lparam
enter
push ebx esi edi
cmp [wmsg],WM_DESTROY
je wmdestroy
cmp [wmsg],WM_CREATE
je wmcreate
cmp [wmsg],WM_SIZE
je wmsize
cmp [wmsg],WM_COMMAND
je wmcommand
defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp finish
wmcreate:
invoke GetClientRect,[hwnd],size
invoke CreateWindowEx,WS_EX_CLIENTEDGE,_edit,0,WS_CHILD+ES_MULTILINE+WS_VSCROLL+WS_HSCROLL,[size.left],[size.top],[size.right],[size.bottom],[hwnd],NULL,[hinstance],NULL
mov [edit],eax
invoke ShowWindow,eax,SW_SHOWDEFAULT
mov [dopen.lStructSize],dopen.size
mov eax,[edit]
mov [dopen.hwndOwner],eax
mov eax,[hinstance]
mov [dopen.hInstance],eax
mov [dopen.lpstrFilter],_filter
mov [dopen.lpstrCustomFilter],NULL
mov [dopen.nFilterIndex],1
mov [dopen.lpstrFileTitle],_title
mov [dopen.nMaxFileTitle],100h
mov [dopen.lpstrInitialDir],NULL
mov [dopen.lpstrDefExt],default_extension

mov [deffont.lfHeight],10h
mov [deffont.lfWidth],0
mov [deffont.lfEscapement],0
mov [deffont.lfOrientation],0
mov [deffont.lfWeight],400
mov [deffont.lfItalic],FALSE
mov [deffont.lfUnderline],FALSE
mov [deffont.lfStrikeOut],FALSE
mov [deffont.lfCharSet],ANSI_CHARSET
mov [deffont.lfOutPrecision],OUT_RASTER_PRECIS
mov [deffont.lfClipPrecision],CLIP_DEFAULT_PRECIS
mov [deffont.lfQuality],DEFAULT_QUALITY
mov [deffont.lfPitchAndFamily],FF_SWISS
mov edi,deffont.lfFaceName
mov esi,font_face
invoke CreateFontIndirect,deffont
mov edx,eax
invoke SendMessage,[edit],WM_SETFONT,edx,0
jmp finish
wmsize:
invoke GetClientRect,[hwnd],size
invoke MoveWindow,[edit],[size.left],[size.top],[size.right],[size.bottom],TRUE
xor eax,eax
jmp finish
wmcommand:
mov eax,[wparam]
and eax,0FFFh
cmp eax,EXIT
je wmdestroy
cmp eax,OPEN
je open
cmp eax,CUT
je cut
cmp eax,COPY
je copy
cmp eax,PASTE
je paste
cmp eax,UNDO
je undo
cmp eax,ALL
je all
jmp defwndproc
wmdestroy:
invoke PostQuitMessage,0
xor eax,eax
open:
invoke GetOpenFileName,dopen
jmp finish
cut:
invoke SendMessage,[edit],WM_CUT,0,0
jmp finish
copy:
invoke SendMessage,[edit],WM_COPY,0,0
jmp finish
paste:
;Not done yet
jmp finish
undo:
invoke SendMessage,[edit],EM_UNDO,0,0
jmp finish
all:
invoke SendMessage,[edit],WM_KEYDOWN,VK_SHIFT+VK_DOWN,15
jmp finish
finish:
pop edi esi ebx
return



section '.idata' import data readable writeable

library kernel,'KERNEL32.DLL',\
user,'USER32.DLL',\
comdlg,'COMDLG32.DLL',\
gdi,'GDI32.DLL'

kernel:
import GetModuleHandle,'GetModuleHandleA',\
strcpy,'lstrcpy',\
strcpyn,'lstrcpyn',\
strlen,'lstrlen',\
strcat,'lstrcat',\
VirtualAlloc,'VirtualAlloc',\
VirtualFree,'VirtualFree',\
ExitProcess,'ExitProcess'

user:
import RegisterClass,'RegisterClassA',\
CreateWindowEx,'CreateWindowExA',\
DefWindowProc,'DefWindowProcA',\
GetClientRect,'GetClientRect',\
SendMessage,'SendMessageA',\
GetMessage,'GetMessageA',\
MoveWindow,'MoveWindow',\
ShowWindow,'ShowWindow',\
TranslateMessage,'TranslateMessage',\
DispatchMessage,'DispatchMessageA',\
LoadCursor,'LoadCursorA',\
MessageBox,'MessageBoxA',\
LoadIcon,'LoadIconA',\
LoadMenu,'LoadMenuA',\
PostQuitMessage,'PostQuitMessage' \

comdlg:
import GetOpenFileName,'GetOpenFileNameA'

gdi:
import CreateFontIndirect,'CreateFontIndirectA'

section '.rsrc' resource data readable

directory RT_MENU,menus

menus:
resource 29,LANG_ENGLISH+SUBLANG_DEFAULT,main

menu main
menuitem '&File',0,MFR_POPUP
menuitem '&Open',OPEN,0
menuitem '&Save',SAVE,0
menuitem 'S&ave as...',SAVEAS,0
menuseparator
menuitem 'E&xit',EXIT,MFR_END
menuitem '&Edit',0,MFR_POPUP+MFR_END
menuitem '&Undo',UNDO,0
menuitem '&Copy Ctrl+C',COPY,0
menuitem 'C&ut Ctrl+X',CUT,0
menuitem '&Paste Ctrl+V',PASTE,0
menuseparator
menuitem '&Select All Ctrl+A',ALL,MFR_END
Posted on 2002-09-28 11:07:43 by CyberGuy
The problem is how you setup the WindowProc procedure, there were some messages that are not returning 0, another thing was, you're jumping to DefWindowProc during a WM_COMMAND. I've edited parts of it, so it looks a liitle more readable.
[size=9]proc WindowProc, hwnd,wmsg,wparam,lparam


enter

push ebx
push esi
push edi

cmp [wmsg], WM_DESTROY
je wmdestroy
cmp [wmsg], WM_CREATE
je wmcreate
cmp [wmsg], WM_SIZE
je wmsize
cmp [wmsg], WM_COMMAND
je wmcommand

invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
pop edi
pop esi
pop ebx
return

wmcreate:

invoke GetClientRect,[hwnd],size
invoke CreateWindowEx, WS_EX_CLIENTEDGE, _edit, 0, WS_CHILD+ES_MULTILINE+WS_VSCROLL+WS_HSCROLL, \
[size.left], [size.top], [size.right], [size.bottom], [hwnd], NULL, \
[hinstance], NULL
mov [edit],eax
invoke ShowWindow,eax,SW_SHOWDEFAULT
mov [dopen.lStructSize],dopen.size
mov eax,[edit]
mov [dopen.hwndOwner],eax
mov eax,[hinstance]
mov [dopen.hInstance],eax
mov [dopen.lpstrFilter],_filter
mov [dopen.lpstrCustomFilter],NULL
mov [dopen.nFilterIndex],1
mov [dopen.lpstrFileTitle],_title
mov [dopen.nMaxFileTitle],100h
mov [dopen.lpstrInitialDir],NULL
mov [dopen.lpstrDefExt],default_extension
mov [deffont.lfHeight],10h
mov [deffont.lfWidth],0
mov [deffont.lfEscapement],0
mov [deffont.lfOrientation],0
mov [deffont.lfWeight],400
mov [deffont.lfItalic],FALSE
mov [deffont.lfUnderline],FALSE
mov [deffont.lfStrikeOut],FALSE
mov [deffont.lfCharSet],ANSI_CHARSET
mov [deffont.lfOutPrecision],OUT_RASTER_PRECIS
mov [deffont.lfClipPrecision],CLIP_DEFAULT_PRECIS
mov [deffont.lfQuality],DEFAULT_QUALITY
mov [deffont.lfPitchAndFamily],FF_SWISS
mov edi,deffont.lfFaceName
mov esi,font_face
invoke CreateFontIndirect,deffont
mov edx,eax
invoke SendMessage,[edit],WM_SETFONT,edx,0
jmp finish

wmsize:

invoke GetClientRect,[hwnd],size
invoke MoveWindow,[edit],[size.left],[size.top],[size.right],[size.bottom],TRUE
jmp finish

wmcommand:

cmp [lparam], 0
jne finish

mov eax,[wparam]
and eax,0FFFh
cmp eax,EXIT
je wmdestroy
cmp eax,OPEN
je open
cmp eax,CUT
je cut
cmp eax,COPY
je copy
cmp eax,PASTE
je paste
cmp ax,UNDO
je undo
cmp eax,ALL
je all

open:

invoke GetOpenFileName,dopen
jmp finish

cut:

invoke SendMessage,[edit],WM_CUT,0,0
jmp finish

copy:

invoke SendMessage,[edit],WM_COPY,0,0
jmp finish

paste:

;Not done yet
jmp finish

undo:

invoke SendMessage,[edit],EM_UNDO,0,0
jmp finish

all:

invoke SendMessage,[edit],WM_KEYDOWN,VK_SHIFT+VK_DOWN,15
jmp finish

wmdestroy:

invoke PostQuitMessage,0

finish:

xor eax,eax
pop edi esi ebx
return[/size]
Posted on 2002-09-28 13:09:47 by stryker