Basic knowledge
The Easy Code visual project mode makes easy to build an application. However, in order to avoid problems, you have to know some basic principles:
Each Window, MDIWindow or DialogBox object created in a project is called an Owner window since it will contain (own) all child controls. The window procedure for any "owner window" must exist and it has to be named with its own name plus the word Procedure (all case sensitive). Also, it must have the four parameters for a window proceure. For example, for a window object named Window1, its procedure name will be Window1Proceure and will look like this:
Masm version:
Window1Procedure Proc hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
.If uMsg == WM_CREATE
;Initial code
.ElseIf uMsg == WM_CLOSE
;Final code
Invoke IsModal, hWnd
.If Eax
Invoke EndModal, hWnd, IDCANCEL
Mov Eax, TRUE ;Return TRUE
Ret
.EndIf
.EndIf
Xor Eax, Eax ;Return FALSE
Ret
Window1Procedure EndP
GoAsm version:
Window1Procedure Frame hWnd, uMsg, wParam, lParam
Cmp D[uMsg], WM_CREATE
Jne >
;Inital code
Jmp > L2
: Cmp D[uMsg], WM_CLOSE
Jne > L2
;Final code
Invoke IsModal, hWnd
Or Eax, Eax
Jz > L2
Invoke EndModal, hWnd, IDCANCEL
Mov Eax, TRUE ;Return TRUE
Ret
L2: Xor Eax, Eax ;Return FALSE
Ret
EndF
As you can see the window procedure always return TRUE or FALSE. When returning TRUE (any other value than 0), no further message processing will be performed and a cycle is complete. When returning FALSE, it will mean that the default window procedure will be called. This is the reason why the default return value, at the end of the procedure, is always FALSE. All messages you do not process, are processed by the default window procedure, which is part of the Windows API, in order to avoid undesirable results. So do not change the default return value FALSE. Also, when you process a message and you do not want further processing for it, return TRUE, but just for those messages you already processed. For example, after calling the EndModal method, you must return TRUE because the window is already destroyed (it does not exist) and returning FALSE would generate errors (the application would probably crash).
When a project has more than a window, one of them has to be the Main window, that is, the window being shown when the application starts (also called the StartUp window). The main window can be set in the Project properties. All other existing windows can be created at run time with the Create method. For example, to create a window named Settings, we will do the following:
Invoke Create, TextAddr("Settings"), hWndParent, lMode, lParam
The hWndParent parameter is a HWND (DWord) value with the handle to the window being the parent. This value can be NULL (except for MDI child windows) if the created window is going to have no parent. The lMode parameter is a LONG (DWord) value specifying how the window is to be shown, modal or modeless. Finally, the lParam parameter is the LPARAM (DWord) value passed to a dialog box in the lParam parameter of the WM_INITDIALOG message. This value is only for DialogBox objects, modal or not, and it may be NULL if not needed (it has no effect for Window objects).
Child controls may also have its own window procedure although it is not usually needed. The name for a child control window procedure must be "the owner window name plus the control name". For example, the window procedure name for a button named Button1 being inside a window named Window1, will be Window1Button1 and will look like this:
Masm version:
Window1Button1 Proc hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
Xor Eax, Eax ;Return FALSE
Ret
Window1Button1 EndP
GoAsm version:
Window1Button1 Frame hWnd, uMsg, wParam, lParam
Xor Eax, Eax ;Return FALSE
Ret
EndF
As said for window objects procedures, the default return value must be FALSE and must not be changed. However, window procedures for child controls are often not used as it is enough to process the WM_COMMAND and WM_NOTIFY received by their owner window. So, unless you are going to process some message (i.e. WM_RBUTTONDOWN), you can delete the corresponding window procedure (that will save some bytes in the final executable file).
For more information, please see the "Visual Projects (Easy Code Power Mode)" topic in the Easy Code help file.
See you!