In the spirit of things here, I thought i would post my latest venture (in not finished, but its in an 'alpha' sorta state).

Its a CWIndow Class for my OOP model. I wanted a simple way to quickly make controls and do a lot of 'default' stuff to them that would normally be done with Dialog box rsrc files etc..

This example Makes a basic Dialog-Like window, except its not, its a registered window class. I have made wrappers around alot of the standard window API's as well. The going idea is that once a window is created via this class, it stores internally the handle, so i can call these api on the internal handle without having to make temp variables and other such things.

In some cases the wrapper would be more code than the standard API, such as SendMessage. However i tossed it in for that 1% chance its more handy as a wrapper, and the file size is not the primary focus ;)

Anywho, check it out, lemme know what you think. Or any styles i should add to the equates. I plan to add a Status / Tool bar creates, ListView, and TreeView. However, these are more complicated, so they will most likely become a separate method from the CreateWindow method.

Please give feedback so far... (good or bad)
:alright:
NaN
Posted on 2003-08-20 17:57:45 by NaN
Hello, NaN!

Why not create some macro to avoid repeating C-like code as this:
    $$ CWnd.SendMessage, LB_ADDSTRING, 0, CStr("Testing")

$$ CWnd.SendMessage, LB_ADDSTRING, 0, CStr("txt1")
$$ CWnd.SendMessage, LB_ADDSTRING, 0, CStr("txt2")
$$ CWnd.SendMessage, LB_ADDSTRING, 0, CStr("txt3")
$$ CWnd.SendMessage, LB_ADDSTRING, 0, CStr("txt4")
$$ CWnd.SendMessage, LB_ADDSTRING, 0, CStr("txt5")


My dummy suggestion is to create "txt1","txt2",etc, END_OF_MSGs with DB
and use some loop with SendMessage, that will scan untill END_OF_MSGs byte (probably 0, after previous ZERO_END) and send your data.
This can save some bytes when your object is used in large apps.
And, imho, asm list will be clearer

Some like:
SendMessageS LB_ADDSTRING, CStr("Txt1",0,"Txt2",0,"Txt3",0)
SendMessageS CB_ADDSTRING, CStr("Txt1",0,"Txt2",0,"Txt3",0)
Posted on 2003-08-20 22:03:58 by S.T.A.S.
I'm lazy all the time and do something like:
MultiAdd MACRO args:VARARG

FOR arg, <args>
$$ CWnd.SendMessage, LB_ADDSTRING, 0, CStr(arg)
ENDM
ENDM

MultiAdd "Test","Tester","Testing","Testee","Testy"
...it is the whole reason I learn macros. :)
Posted on 2003-08-20 22:12:20 by bitRAKE
Hi, bitRAKE!
That's nice :alright:

another half of work is to remove "$$ CWnd.SendMessage" into separate proc (method) to avoid generating of ma-a-ny invokes
Posted on 2003-08-20 22:43:28 by S.T.A.S.
Or more generally:

MultiAdd MACRO Mesg:REQ, args:VARARG

FOR arg, <args>
$$ CWnd.SendMessage, Mesg, 0, CStr(arg)
ENDM
ENDM


Then you can use it on ListBoxes, as well as Combo boxes, and probably others..

So what do you guys think about this approach?? You like it? Im hoping to make it simple to quickly get stuff up and going.. Im trying to pay attention to the overhead of extra function calls, but its a trade off im willing to sacrifice if it means i can spend less time in the future out simple controls ;)

I got more or less an inherited CTab::CWnd finished. I can quickly add and remove tabs, as well as load an image list from resource, and it will automatically clean up after itself (assuming you Destroy the CTab instance ;) ).

I Was thinkin of doing the same for ListView and TreeView (inheriting from CWnd).
Again, your thoughts?

:NaN:
Posted on 2003-08-21 00:41:11 by NaN
Sorry, NaN,
This because of my poor english :(

This is my poor asm, but i hope you'll cath the idea
proc SendMessageS  pMessages:DWORD

mov edi, pMessages
@1
$$ CWnd.SendMessage, LB_ADDSTRING, 0,edi
@2: inc edi
cmp byte ptr [edi-1], 0 ; look for the end of one message
jne @2
cmp byte ptr[edi], 0 ; look for the end of Messages Set
jne @1


As I know one of OOP's goal is "code reuse"
so we can use just one invoke instead of many :)

For now i'm writting some code for DX, and CWindow is of some other kind, but I've got many ideas from "NaN and Thomas Object model", so I belive this is good One.:alright:
Posted on 2003-08-21 02:05:29 by S.T.A.S.
Ok, i will add this.. however i will make it more generalized (since this will be available to all window entities that inherit from CWnd or use CWnd explicitly.

Something Like
SendMessageS PROC uses ebx esi edi LoopVar:DWORD, hMsg:DWORD, wParam:DWORD, lParam:DWORD, pMessages:DWORD


.if( LoopVar )
lea esi, wParam
.else
lea esi, lParam
.endif

@Begin:
mov ebx, [esi]
xor eax, eax
mov edx, eax
mov al, [ebx]
cmp eax, edx
je @Finished

invoke SendMessage, [edi].hWindow, hMsg, wParam, lParam

xor eax, eax
mov edx, eax
@@:
inc ebx
mov al, [ebx]
cmp eax, edx
jne @B
inc ebx
mov [esi], ebx
jmp @Begin
@Finished:

xor eax, eax
ret

SendMessageS ENDP

This way you can specify which param is to hold a string of text data by setting the first param. The rest is as usual, except its desgined to loop... (didnt test this.. just typed it up quickly)

:NaN:
Posted on 2003-08-21 23:01:02 by NaN
Nan,

I really like what your doing.
GREAT!!!



:D
Posted on 2003-08-22 03:07:02 by packetvb
Hi, NaN
I personally know nothing about OOP, but will learn some day (I think your tutorials and posts are going to be really useful :alright: ).
Anyway I'm interested in this macros to save code when calling SendMessage repeatedly. Is there a way to calculate at wich point it begins to save bytes (how many calls)? And, is there a way to make a macro, so it automatically detects when to call SendMessage several times, and when to do it in a loop? (perhaps it's too much to ask from MASM's macro language :grin: )
Posted on 2003-08-22 10:20:13 by QvasiModo
Well here is what i have to date on the topic..

I got the Tab control pretty well where i want it. I might provide a Delete method, but thats about it.

As always, feedback is welcome..
:NaN:
Posted on 2003-08-22 23:39:40 by NaN

Hi, NaN
I personally know nothing about OOP, but will learn some day (I think your tutorials and posts are going to be really useful :alright: ).
Anyway I'm interested in this macros to save code when calling SendMessage repeatedly. Is there a way to calculate at wich point it begins to save bytes (how many calls)? And, is there a way to make a macro, so it automatically detects when to call SendMessage several times, and when to do it in a loop? (perhaps it's too much to ask from MASM's macro language :grin: )


It is possible. You just have to do the computations by hand first. Or assemble a version of that and disassemble it to see its length. You need to determine the number of bytes a loop would take, and one when the SendMessages are in sequence. Then determine the point where it saves more in a loop. Then put an IF statement in the macro checking if the number of arguments is less than your pre-determined limit, if so, do it in sequence, otherwise, do it in series.

I can show you a macro package that puts MASM's macros to the max... MASM's macros are VERY powerful, believe bitRAKE, use the macro!
Posted on 2003-08-25 02:29:10 by AmkG

assemble a version of that and disassemble it to see its length.

Another old thing
Syntax: .LISTALL

Description:

Enables listing of all statements to the .LST file. The .LST file
must first be enabled with a PWB MASM option or the /Fl command-line
option. This directive is equivalent to the combination of the
.LIST, .LISTIF, and .LISTMACROALL directives.
Posted on 2003-08-27 03:14:16 by S.T.A.S.