Well im done :grin:

My MenuButton control is finished and well pollished, so in the next comming days im going to make my attempt at writting a tutorial out of it.

However, for those who do not care for tutorials, here is the control up front and ready. There is a good amount of commenting as already, so most should not have any problems reading it.

As well, i make use of a new 'lib' entry to the masm32.inc lib. Its a function to copy bitmaps to a DC with a transparency mask. I make use of it in the control, and thus it is needed if you wish to link the control to any future projects. I have added it into the package under "MASM32". You need to manually copy it to M32LIB and follow two simple steps outlined in the README to recompile your masm32.lib.

I also have a basic example of how the controls are used. In the readme.txt there is also a breakdown of suported messages to send to the control. Its realy simple so i cant see anyone getting confused here.

Anywho.. There it is.. Make use of it and have fun... and Feedback is welcome!
Posted on 2002-04-23 05:02:19 by NaN
Hi NaN

Great control. :alright:

Seem to have a little bug.
On my XP the button displays garbage text if no text is set (I guess).

Posted on 2002-04-23 05:58:56 by KetilO

This works fine on my win95b, library module looks interesting and I am sure many people will like it.

Make sure I get the final version so i can add it to the next service pack.


Posted on 2002-04-23 07:06:39 by hutch--
good work
thanks for sharing nan
Posted on 2002-04-23 07:48:52 by adapix
Originally posted by KetilO
Seem to have a little bug.
On my XP the button displays garbage text if no text is set (I guess).

As well as under NT5/W2K - the same behaviour.
Posted on 2002-04-23 08:43:44 by MikeJ
Good stuff NaN, i like the links on the button 3 menu.
Posted on 2002-04-23 08:48:03 by sluggy
Here's how it looks on win2k...
other than that, I have one little more gripe :). It would be nice if
the buttons acted a bit more like "standard buttons" in the sense
that if you click the button, keep the mousebutton pressed, and
drag the mouse off the button, two things should happen. First,
the button should go to its unpressed state, and secondly no click
should be generated when mouse is released.

Oh, do you have the CS_DBLCLKS style on?

Other than that, good work.
Posted on 2002-04-23 10:13:41 by f0dder
great, forgot to attach as always.
Posted on 2002-04-23 10:14:30 by f0dder
I don't know what to say: this is a great control, very great.
GOOD JOB !!:alright: :alright:

PS:just a small bug: you know, when you click on a button and you stay clicked, and then you move out from the button, you can press up the button then the function is not executed. (hope you understand, I don't explain very good!!),

but here in your control, once we have press the mouse button down, the function cannot be prevented. (just have a look at IE button--> back)

after reading what I've just written, I see that it does not look so clear, but I hope everybody will understand...

--> works great on Win98SE (French)
Posted on 2002-04-23 10:22:38 by Vom-bonjour:-()

just a small bug: you know, when you click on a button and you stay clicked, and then you move out from the button, you can press up the button then the function is not executed. (hope you understand, I don't explain very good!!),

thats what fodder pointed out already...

i printed out the source and stumbled over it... this
DrawFrameControl API was new to me, seems to be very
usefull for custom controls... nan, are you really going
to write a gdi tutorial? this would be very cool because
i never saw a good one for asm programming... if you
do i bet there are a bunch of people on this board ready
to help you (including myself)...

good work...
Posted on 2002-04-23 10:40:11 by mob
well, I'm sorry, maybe I've not read all, well, I don't really understand why I've not seen what f0dder said.

sorry for that.

Posted on 2002-04-23 11:00:57 by Vom-bonjour:-()
Thanx all:

So there is two major things to work out:
    [*]Fix the text on any form of NT box. Hmm, this will be slow (as i dont have an NT OS anywhere), if i can email proto's to someone this would rock. However i will look up the MSDN and see why the 'DrawTextEx' API if failing. I suspect its due to NT's obsesion with unicode strings :grin: .
    [*] Make mouse clicks specific when the mouse is still over the control. I will give it a whirl, but to be honest, this was one area that was challenging. Its hard to get the right messages sent to you on this, i debugged alot of sceenarios to get it to work this well. Its really a juggle of where the best place to evaluated state variables are. I will give it a try.

    However im glad you like it. And also glad to see that the 'DrawTransparentBitmap' method works on all platforms :)

    I will hack out a revision very soon..
    Thanx for the feedback, and let me know if other 'quirks' pop up.


    PS: Mob, ya It was kinda an upset learning about this api, I stumbled upon it by accident using the "group" lists in the API reference .hlp file. It kinda annoyed me at first, as i had at that point written gdi functions to do the exact same thing! (so there was alot of wasted time here). The upside from the API is i no longer needed to build an arsenal of pens and brushes, and manage them with the DC's ( real savings here! ). I actually printed that page off the API help, as it has alot of neat things in it. Definitely a source for any other control development!!.
Posted on 2002-04-23 13:27:50 by NaN
NaN, sounds very unlikely that unicode should be the problem,
the 'A' versions of the APIs still exist on NT (though they do ansi->uni
conversion and call the 'W' version of the API). It's probably something else.

As for the mouse stuff, you should probably look at SetCapture.
Posted on 2002-04-23 13:35:24 by f0dder
Thanx, i am using SetCapture. As for the text i've looked it up on the MSDN and it says it suports it, however i have a hunch if I drop the 'ex' it will work fine.

Im just finishing a test program to get some info back..

Posted on 2002-04-23 14:20:06 by NaN
Can XP,NT,2000 users please download this test file and tell me if you see lines A, B, C, D. (Cant hurt for 9x users as well).

Removed Test program... No need to waste space
Posted on 2002-04-23 14:33:19 by NaN
Can you read this ANSI DrawText A
Can you Read this ANSI DrawTextEx B
Posted on 2002-04-23 14:37:52 by f0dder
Looks like this (WinXP):
Posted on 2002-04-23 14:39:33 by bazik
Ok, Now im completely stumped!!

Both work fine on NT. So what am i doing wrong?

For inerested helpers:

    [*]The Back buffer DC is created on lines 147-153. I build a compatible DC as the thead's own DC.
    [*]I use DrawTextEx on line 242, for noraml siuations (button unclicked). The text pointer is stored in lpText. -1 is cause i dont need to specify length (as i did in the above test demo). The rect is ok (as you see *something* at the bottom), and the style if POP'ed off the stack from previous evals. NULL is cause i dont care about other *special* features.
    [*]The text is drawn on the Back buffer to prevent flicker. However, the only difference betwwen the control, and the above test, is that in the above test, i draw directly to PS.hdc provided by begin paint. (Could this be a factor somehow?)
    [*]Lastly, i bitblt it to the PS.hdc in one go and im done.

    I guess the only *logical* solution is somehow the PS.hdc has proper font info, and the back buffer doesnt?? (This make sense?). Nowhere in the control do i create a pen for drawing. Im useing the default pen that comes on the private DC. Is it possible in NT machines there is some differene here?

    Any sugestions? Pehaps i should try 'GetStockObject' and select a default textfont/pen and select it into the backbuffer dc???

    Thoughts welcome! (I dont want to flood the board with 'test' revisions of the control if i dont have to).

    Can you NT guys run the original program again and click the first button's drop menu (upper left corner), and select the last menu option (set menu buton 1 font). See if it fix's the font on this button. I use GetStockObject here for a default system font, and select it into the DC. This will help determine if these guesses are correct.

    PS: This is the only remaining problem, i got the button clicking fixed up the first try ;) . Should have thought of it sooner.

    Thanx alot fodder and bazik for you help so far!
Posted on 2002-04-23 14:52:53 by NaN

By trial and Error with a budy on ICQ, i've determined that its NOT in the GDI at all!!!

Some how on NT machines only, the rules are being broken, and the lpText pointer vaiable on the heap is being corrupted. However, on 9x machines the pointer is not being violated.


Still hacking at it.. but its soooooo slow when you dont have NT.

Posted on 2002-04-23 17:58:55 by NaN
Ok.. no promises.. cause everything *works* on 9x anyways.

But here is what i think is happening:

On WM_CREATE, the lParam == addr CREATESTRUCT. I use this struct to get info that you specify in the CreateWindowEx. While all other info menu, size, etc. is being recieved and and stored the *lpName* (I think is not).

Before i simply copied the pointer to the string that was to be the caption name. Now, I've added a buffer on the heap, and am directly copying the contents into the heap (copying the caption string).

By trial and error, i found that if i povided a 'hard coded' string handle, the text will display fine on NT.

By deduction, im Guessing that on NT machines, the CREATESTRUCT.lpName is not the actual pointer to the sting passed in CreateWindowEx, but a pointer to a copy in the OS's memory. So I would then save the pointer to OS memory. Later the OS destroys this data. So when it comes time to paint, the pointer points to crap (that was once the string). This is also proven by doing the followin with the original example (for NT people): Click on the second button, select the AddMenu to 3 option, goto the third button and select the first menu option (Set Text). In this option I reset the text by passing a NEW string pointer using SendMessage. (before the pointers came by CreateWindowEx). When you do this on a NT machine you will see that the text becomes corrected and readable.

This is my best guess. As on 98SE, and using softice, i see that the pointer given in the CREATESTRUCT is the actual address the text, and not copied by the OS.

So again, this version has a buffer, and it copies the data as soon as it gets it. Hopefully this is the fix needed for NT machines.

Please Download this and Try it and let me know if it works!
Thanx alot!
Posted on 2002-04-23 19:07:30 by NaN