flat assembler
Message board for the users of flat assembler.
Index
> Windows > text editor |
Author |
|
DimonSoft 18 Oct 2018, 16:24
Ali.A wrote: im trying to make a simple text editor, but the problem is there is no edit box. Something wrong went here, at least: Code: invoke CreateWindowEx,0,_edit_class,0,WS_CHILD,WS_VISIBLE,ES_MULTILINE,WS_VSCROLL,WS_HSCROLL,ES_AUTOVSCROLL,ES_AUTOHSCROLL,[rct.left],[rct.top],[rct.right],[rct.bottom],[hwnd],NULL,[wc.hInstance],NULL |
|||
18 Oct 2018, 16:24 |
|
Walter 18 Oct 2018, 16:58
In order to see your input, you are going to need:
In CreateWindowEx: WS_CHILD+WS_VISIBLE+ES_MULTILINE+WS_VSCROLL+WS_HSCROLL+ES_AUTOVSCROLL+ES_AUTOHSCROLL Class: _edit_class db 'EDIT',0 and in msg_loop: ; cmp [msg.message],WM_KEYDOWN ; jz msg_dispatch |
|||
18 Oct 2018, 16:58 |
|
revolution 18 Oct 2018, 17:22
If you check the return values from each API call then you can narrow down each problem more easily. Print some sort of simple message (or better, use a debugger) when any of the API calls fails. Fix up each call one-by-one until they all execute successfully.
|
|||
18 Oct 2018, 17:22 |
|
Ali.Z 18 Oct 2018, 20:23
ok found my issue after debugging:
Code: WS_CHILD,WS_VISIBLE,ES_MULTILINE,WS_VSCROLL,WS_HSCROLL,ES_AUTOVSCROLL,ES_AUTOHSCROLL used comma instead of '+' plus sign. and why i cant get a custom name for _edit_class? why it have to be 'edit'? and why im limited in the editbox? i cant write many characters! also ; cmp [msg.message],WM_KEYDOWN ; jz msg_dispatch didnt work, i had to change it to: Code: msg_loop: invoke GetMessage,msg,NULL,0,0 or eax,eax jz end_loop cmp [msg.message],WM_KEYDOWN jz msg_translate invoke TranslateAccelerator,[hwnd_main],[hkeys],msg or eax,eax jnz msg_loop cmp [msg.message],WM_KEYDOWN jz msg_dispatch msg_translate: invoke TranslateMessage,msg msg_dispatch: invoke DispatchMessage,msg jmp msg_loop but the issue now is i cant receive hotkeys with shift or ctrl, only alt key. Code: menu main_menu menuitem '&File',0,MFR_POPUP menuitem '&New' _ 'Alt+N',IDM_NEW,0,MFS_GRAYED,0 menuseparator menuitem '&Exit' _ 'Alt+X',IDM_EXIT,MFR_END menuitem '&Help',0,MFR_POPUP+MFR_END menuitem '&About' _ 'Alt+H',IDM_ABOUT,MFR_END accelerator hot_keys,\ ; cant use FCONTROL FVIRTKEY+FNOINVERT+FALT,'N',IDM_NEW,\ FVIRTKEY+FNOINVERT+FALT,'X',IDM_EXIT,\ FVIRTKEY+FNOINVERT+FALT,'H',IDM_ABOUT how could i solve this? |
|||
18 Oct 2018, 20:23 |
|
revolution 18 Oct 2018, 21:14
Ali.A wrote: and why i cant get a custom name for _edit_class? why it have to be 'edit'? Have a look at the FEDIT.ASM source for the "FEDIT" class. |
|||
18 Oct 2018, 21:14 |
|
MacroZ 19 Oct 2018, 12:05
More text editors are always useful. I hope it will have syntax highlighting for asm. Keep up the good work.
_________________ The king auto-generates two things to degrade dangerous artists and intellectuals. The King reserves the right to be king and has made the culprits in advance. Half of the time or more, they are auto-generated. |
|||
19 Oct 2018, 12:05 |
|
Ali.Z 19 Oct 2018, 21:15
MacroZ wrote: More text editors are always useful. I hope it will have syntax highlighting for asm. Keep up the good work. yeah that what i wanted to make, but seems the project will be discarded. revolution wrote: Have a look at the FEDIT.ASM source for the "FEDIT" class. couldnt understand a single line, both fasmw and fedit are large in file size and total of 5000+ lines of code. seems Win GUI programming isnt suitable for me, its better to stick with consoles. (but i would say i was very happy for creating a window tho) _________________ Asm For Wise Humans |
|||
19 Oct 2018, 21:15 |
|
catafest 21 Oct 2018, 09:16
The code is an old code I saw on the internet ...
The debugger is the first tool to understand assembler ... I don't know the english language very well ! Ali.A wrote: im trying to make a simple text editor, but the problem is there is no edit box. |
|||
21 Oct 2018, 09:16 |
|
Ali.Z 21 Oct 2018, 13:40
catafest wrote: The code is an old code I saw on the internet ... useless + stupid post, by creating a new account on this forum doesnt mean im new assembley. i used to be a reverse engineer for something like 10 years, plus the code isnt a snippet from web its my own code. just failing to understand win gui programming doesnt mean im new to programming nor the code is stolen from web. _________________ Asm For Wise Humans |
|||
21 Oct 2018, 13:40 |
|
catafest 21 Oct 2018, 14:48
1. I don't like rude people.
Ali.A wrote:
I find a similar source code on internet. I cannot give the link because I don't have it. 2. Reply to @DimonSoft idea : I used WS_OVERLAPPEDWINDOW but you can used any part of MSDN SDK! The window is an overlapped window. Same as the WS_TILEDWINDOW style. Code: invoke CreateWindowEx,0,szClass,szTitle,WS_OVERLAPPEDWINDOW,\ CW_USEDEFAULT,CW_USEDEFAULT,\ 600,600,NULL,[h_menu],[wcex.hInstance],NULL The edit control can be done with : Code: invoke CreateWindowEx,WS_EX_CLIENTEDGE,szEdit,0,\ WS_VISIBLE+WS_CHILD+WS_VSCROLL+ES_AUTOVSCROLL+ES_MULTILINE,\ 0,0,0,0,[hwnd],0,[wcex.hInstance],NULL 3. FASM is very flexible... |
|||
21 Oct 2018, 14:48 |
|
Furs 21 Oct 2018, 15:01
Ali, you should read some books or tutorials on Win32 GUI programming, even if they're not in assembler, because the concepts are more general.
For example, you asked why you can't use a different class name. Well, a "class" in Windows is sort of like a "class" in C++, but for windows (note that all controls are also "windows"). You create windows (i.e. objects, instances of that class) from it, that have properties of that class. Most important such property is the "WNDPROC" which is a callback that receives a lot of messages from various places (the Win32 GUI system is event-driven) and defines most of what the window will do based upon various events. For example, when the Window gets destroyed, it receives (in its WNDPROC) a WM_DESTROY message so it can do whatever. The class defines the callback function that the window uses. "Edit" is the name of the class provided by Windows, its builtin edit control. Obviously, "_edit_control" does not exist because you didn't register this class, so it fails. It's like using a class in C++ that doesn't exist, or a label in asm, whatever. Don't think of it as a name but rather as an identifier. It's a shame they used strings for it, though. You can technically override the WNDPROC (this is called subclassing) after the window gets created with it, but that's more advanced concept, for now focus on basics. |
|||
21 Oct 2018, 15:01 |
|
DimonSoft 21 Oct 2018, 17:45
catafest wrote: 2. Reply to @DimonSoft idea : Are you sure I don’t know this stuff? Are you sure you’ve understood why my post contained the line with CreateWindowEx? We can also talk about using + instead of or some time later. |
|||
21 Oct 2018, 17:45 |
|
Ali.Z 22 Oct 2018, 01:29
Furs wrote: Ali, you should read some books or tutorials on Win32 GUI programming, even if they're not in assembler, because the concepts are more general. i read some, but most of them provide code samples and not explaining much stuff. Furs wrote: For example, you asked why you can't use a different class name. Well, a "class" in Windows is sort of like a "class" in C++, but for windows (note that all controls are also "windows"). You create windows (i.e. objects, instances of that class) from it, that have properties of that class. Most important such property is the "WNDPROC" which is a callback that receives a lot of messages from various places (the Win32 GUI system is event-driven) and defines most of what the window will do based upon various events. thanks for this one man, didnt know other controls are considered as "window" .. yeah i noticed that when debugging lot of stuff are sent in [msg] to main window procedure and 90% of the messages are unknown to me, and i dont handle them. Furs wrote: "Edit" is the name of the class provided by Windows, its builtin edit control. Obviously, "_edit_control" does not exist because you didn't register this class, so it fails. It's like using a class in C++ that doesn't exist, or a label in asm, whatever. Don't think of it as a name but rather as an identifier. It's a shame they used strings for it, though. i tried later then to register a custom class name for the edit control, but failed. also tried to learn some from fasmw.asm and fedit.inc but couldnt understand much. Furs wrote: for now focus on basics. thats right, i learnt some basics and im happy but thats not enough .. i wanna learn more advanced stuff. you probably will understand this: its like i was in a small room called "console programming" and that room fits me and my needs as well. and then went to big hall called "win gui programming" its kinda im lost. i would say win gui is similar to BF (brain f*ck) programming lol. btw thanks for the info Furs. _________________ Asm For Wise Humans |
|||
22 Oct 2018, 01:29 |
|
Furs 22 Oct 2018, 12:11
Ali.A wrote: i read some, but most of them provide code samples and not explaining much stuff. Ali.A wrote: thanks for this one man, didnt know other controls are considered as "window" .. yeah i noticed that when debugging lot of stuff are sent in [msg] to main window procedure and 90% of the messages are unknown to me, and i dont handle them. For unknown messages you should simply call DefWindowProc which handles default processing for such messages. So if it's a message you don't handle just pass it to DefWindowProc and return with its return value (from the callback). Ali.A wrote: i tried later then to register a custom class name for the edit control, but failed. BTW, Win32 GUI programming is event-driven so pretty much "object oriented" in design but with messages instead of vtables. I'm guessing you don't have much experience with OO concepts. It boils down to: window receives events (messages) based on whatever (user input, system stuff, or even custom messages). In a window you process these messages. There's no definite "flow chart" that you know, all you care about is inputs (message and parameters) and act accordingly. It doesn't matter when you get called. Since it's a callback. It's not as "linear" as console programming. Think of it as a function getting executed by the CPU when something happens (like interrupts) but at a much higher level. |
|||
22 Oct 2018, 12:11 |
|
catafest 22 Oct 2018, 12:19
@DimonSoft : I read your replay and is ok!
|
|||
22 Oct 2018, 12:19 |
|
Ali.Z 22 Oct 2018, 21:38
Furs wrote: Well most of them assume you know some basic C/C++ I think. If you know asm, it's not that difficult to learn C at least to be able to read it, since it's pretty simple language. Then code samples will be very good for you yes i can read C/C++ and what i read was C/C++ samples. Furs wrote: For unknown messages you should simply call DefWindowProc which handles default processing for such messages. So if it's a message you don't handle just pass it to DefWindowProc and return with its return value (from the callback). ehm, but i think it cant handle one thing: when you create a window with a status bar and you resize the window, the status bar wont get auto-resize. why i have to save if msg = wm_size then get client rect and then call move window function, why not defwndproc do this for me? Furs wrote: Did you populate the class structure properly before registering? Can you show the code? Code: ; i thought this code should be enough mov [wc.style],CS_DBLCLKS+CS_GLOBALCLASS mov [wc.lpfnWndProc],CESedit mov [wc.lpszClassName],_edit_class invoke RegisterClass,wc ; then i did this invoke CreateWindowEx,0,_edit_class,0,WS_CHILD+WS_VISIBLE+ES_MULTILINE+WS_VSCROLL+WS_HSCROLL+ES_AUTOVSCROLL+ES_AUTOHSCROLL,[rct.left],[rct.top],[rct.right],[rct.bottom],[hwnd],NULL,[wc.hInstance],NULL mov [hedit],eax Furs wrote: I'm guessing you don't have much experience with OO concepts. exactly, maybe thats why im facing difficulties to understand and program Win32 GUI? Furs wrote: It's not as "linear" as console programming. Think of it as a function getting executed by the CPU when something happens (like interrupts) but at a much higher level. yes i noticed that the day i started writing some gui code, also got stuck for the first couple hours saying exact same thing: its not linear as console. thanks for this, didnt think of it as case similar to interrupt. but now i can think of it properly, where WndProc is similar to OS-interrupt handling function and WM_? is similar to interrupt number. ehm Furs i learnt from these two sites and fasmw.asm and fedit.inc: zetcode winprog so read these and i feel like i got 90% of the tutorial, then i tried to write my own code. (do you know any better source providing examples and explaining some concepts) _________________ Asm For Wise Humans |
|||
22 Oct 2018, 21:38 |
|
DimonSoft 23 Oct 2018, 07:54
Ali.A wrote: ehm, but i think it cant handle one thing: What if you don’t want a control to resize when its parent gets resized? Having less code is better since you can write one for your preferred behaviour. If DefWindowProc did resize child windows that would pose a lot of questions. Say, should font sizes also change? What if this also changes the way window text is split into lines in a button or edit control? What if there’s no font of appropriate size? What if it’s a button with an icon (which is raster image)? What if resized child window starts showing on several monitors after the resize? And then, if all the questions were solved and DefWindowProc somehow implemented this behaviour (this way or that) there still would be people who need different behaviour and they would have to fight against DefWindowProc. It is sometimes easier to write zero lines of code than to write some and have to support them although nearly everyone just doesn’t use it. Ali.A wrote:
Not enough to tell the exact reason. Possible ones are: * class name is already taken by a system-wide class (if you use EDIT as the name); * cbSize field is not properly initialized. GetLastError will answer your question. Ali.A wrote: (do you know any better source providing examples and explaining some concepts) MSDN. It requires some experience reading official documentation but the only way to have the experience is to actually read the docs. Besides, it’s the original source for everything you’re going to find in the Internet. And, unlike third-party sources, this information is contractual, while third parties can have mistakes and misunderstandings by the authors themselves. |
|||
23 Oct 2018, 07:54 |
|
Furs 23 Oct 2018, 15:20
Ali.A wrote: ehm, but i think it cant handle one thing: What if they should be static and the window itself is just a canvas for child windows? (e.g. a dialog box, which is also a window). What if they're supposed to also be resized along with the parent? Not just "stick to an edge"? It can't know any of these things, so it doesn't do them. Ali.A wrote:
Also, note that the [rct.right] and [rct.bottom] are wrong. The window expects width and height, not a rectangle. So you need something like rct.right - rct.left for the width. Ali.A wrote: (do you know any better source providing examples and explaining some concepts) I don't know that many sources for beginners, unfortunately. You can try books like "Programming Windows 5th Edition" by Charles Petzold and start from Chapter 3 (I assume you know the basics so skip the first two). It's pretty old but the concepts are the same so it doesn't matter. (pretty sure you can get it for free if you look hard enough if you don't want to pay for it -- though of course, if it's useful to you consider paying for it to support the author) |
|||
23 Oct 2018, 15:20 |
|
Ali.Z 25 Oct 2018, 06:34
ehm, thanks DimonSoft and Furs.
yeah thats true its not friendly, and i was only looking into Docs section -> Function Reference |
|||
25 Oct 2018, 06:34 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.