-= Using Tab Controls in Win32Asm =- ************* *800*600 * *Wordwrap On* ************* By Latigo Noticing the lack of information on the subject, i decided to make a tutorial based on my experience. I must confess that i had a hard time learning the 'ins and outs' of Tab Controls. But painfull learning proves to be good in the end :). Ok enough blah blah . What we are going to do here is a small Tab Control with 2 'tabs' each one containing a different child dialogbox. In case you reader still dont know what a tab control is, i shall sugest you pay a visit to say your keyboard configuration in the windows Control Panel..there you got a nice one :) (they are all over windows and windows apps anyway). The theory behind the Tab control is the following: 1) Create a dialog box containing a Tab Control (with code or with a resource editor,i rather the latter) 2) After you decide how many tabs your control is going to have, create the same number of child dialog boxes (borderless also for better appearance). 3) Later, in your 'Winprok' you should analize the TCN_SELCHANGE message which comes in the form of a WM_NOTIFY message. This message is triggered when the user changes from one tab to other. 4) ..and now for the magic 'click-one-tab-so-the-previous-disapears-and-a-new-one-appears' thing. First you must Hide the visible child dialog box. Then send a TCM_GETCURSEL to your WinProk in order to know which tab the user is clicking, and based on this you show the corresponding child dialog box. I know, all this may sound complicated..but its just the outline of the things to do. No worry, ill present you some neat asm code fully commented. Step by Step: ------------- 1 y 2) I cannot teach you nothing here, just create the dialogs and the tab control in your favorite resource editor. I named them this way: * Main Dialog Box = "IDD_DIALOG1" * First Child Dlg = "IDD_CHILD1" * Second Child Dlg = "IDD_CHILD2" * Tab Control ID = "IDC_TAB1" 3 & 4) Filtering the right messages "... ; The TCN_SELCHANGE message comes in a WM_NOTIFY thus, we filter WM_NOTIFY CMP EAX,WM_NOTIFY JZ _notify xor EAX,EAX RET _notify: MOV EAX,lParam MOV EAX, (NMHDR PTR [eax]).code CMP EAX, TCN_SELCHANGE JZ ChangingTab ; Ok Some explanations here.. the lParam member of the WM_NOTIFY message is a pointer to ; a NMHDR structure. The member 'code' of this structure contains the 'notification ; code' if this one is TCN_SELCHANGE then it means that we are on the right track ; (check your local Win32Api for more detailed help on this) RET ; Here we land ChangingTab: MOV EBX,WhichTabChosen ; WhichTabChosen is a DWORD variable used as a flag. It contains the index of the current ; chosen Tab. (i declare it in the .DATA? section..you will see in the FULL asm code ; provided in this same zip). ; This is a neat thing (i worked out after a looooooong time ..lame of me :) which will ; let us do many things with very little code. 'Handles' is a location inside the .DATA? ; section. All the handles to the child dialog boxes lie after it. So if i 'say' ; LEA EAX,[HANDLES+4] that would put in EAX the address of the first handle. And to be ; able to reach ANY of the handles i multilpy the chosen tab index by 4 (a DWORD or ; HANDLE) to get the desired handle. ; Maybe this is not very clear the first times you see it, but trust me, look at it in ; the source code and it will be very clear. MOV EAX,[Handles+EBX*4] ; So we load in EAX the handle belonging to the current dialogbox INVOKE ShowWindow,EAX,SW_HIDE ; and we hide it damn it! INVOKE SendMessage,hwndTab,TCM_GETCURSEL,0,0 ; I now send a TCM_GETCURSEL message which will return in EAX the tab which is being ; selected. MOV WhichTabChosen,EAX ; Lets update the flag MOV EBX,[Handles+EAX*4] ; Now lets retrieve the handle of the dialog box that belongs to the chosen tab. INVOKE ShowWindow,EBX,SW_SHOWDEFAULT ; and now lets show it :) RET ..." I did not make the explanations foolproof since i assume some knowlege on win32asm. But im sure that if you have some experience, you wont have any problem understanding the code. In the zip you'll be able to find ALL the required files. .asm,.rc,.h etc etc. Ah..dont forget to include comctl32 in your includes and libs..cos the Tab control is a common control; and also make sure you include the InitCommonControls API somewhere in your code. I hope i was clear in the tutorial and i also hope that you learned :). It took me lots of time to research,reverse and learn all this stuff. Thanks to Iczelion who teached me LOTS of win32asm with his EXCELLENT (i mean it!!!) tutorials. If you have any doubt,complaint..or maybe you wish that i enlarge this tutorial,or maybe you would like me to shoot my left foot and suffer while YOU laugh,looking at my bleeding limb and thinking that i really deserve this for writting such a tab control tutorial... mail me to latigo@ciudad.com.ar hehe :)..thanks for reading this and may you have a nice life. Greetings to Zito and MAC my brothers.. also to all that nice people at #cracking4newbies..R!SC i love you too :D. Ciao! Latigo