6.0 - The Tiles WINDOW Tile Window
WE WILL NOW CREATE A Static Control Which We Will Draw The Tiles ON.
We will create a static control. We will draw blocks above it.
6.1 - Creating The Control Create Controls
We make a new procedure caled initcontrols That Will Initialize all the controls on the main window.
We create a process of "initcontrols" named "initcontrols" that will initialize the control on all main windows.
.data classstatic db "static", 0.data? hStatic dd? .code; ================================= ======================================================================================== init Controls; ==================================================== ==================================================================================================== ClassStatic, Null, / WS_Visible WS_CHILD SS_OWNERDRAW, / 15, 55, 220, 220, / HWND, CID_STATIC, HINSTANCE, NULL MOV HSTATIC, EAXRETITCONTROLS ENDP
At The Start of the File, WHERE The Prototypes Are, Add A Prototype for this Procedure:
At the beginning of the file, there is a function prototype. Join the prototype of this process:
InitControls Proto stdcall: DWord
And in the mosaic.inc file:
Add this to Mosaic.inc file: CID_STATIC EQU 601
The Initcontrols Procedure Takes One Parameter, HWnd Which Is The Window Handle of The Main Window. The CreateWindowEx Function Creates A Styles:
The InitControls process with a parameter-the window handle of the main window HWnd. CreateWindowEx creates a static control:
ClientEdge (Window Has A Sunken Border Like An Edit Control)
"Static" AS Window Class, This Creates A Static Control
Child Window (WS_CHILD), The Window Is A Child Window of The Main Window
OwnerDrawn Window (SS_OWNERDRAWN). THIS Means That The Program Takes Care of The Drawing of the Control.
Cid_static is the id of the window, this constant is deflated in the include file mosaic.inc
Left Top Position: (15, 55), Size 220x220
Customer Arbor (ClientE) (window like editing box control)
"Static" as the window class name. This creates a static control.
The sub-window (WS_CHILD) is a window of the child window of the main window.
OwnerDrawn window (SS_OWNERDRAW). This intention of the program handling the painting of the control.
CID_STATIC is the ID of the window, which is defined in the included file mosaic.inc.inc.
Coordinate position (15, 55), size 220 × 220.
Finally, The Window Handle Is Stored In The DWORD HSTATIC (Defined IN .DATA?)
Finally, the window handle is stored in DWORD HSTATIC (defined in .data?)
Now We Have to Call this Procedure:
Now we have to call this function:
..... if eax == wm_create invoke initcontrols, hwnd ....
This Creates of the Window. THIS CREAS IS CALED AND THIS INTCONTROLS IS.
This code is sent when the window is created in the window process (WNDPROC). Then invoke InitControls and create a static control.
When the Program is Assembled, this will be the result:
After the program is compiled, the result will be like this:
6.2 - Add More Controls Add to more controls
There will also be a toolbar and a statusbar on the window. You can use CreateWindowEx to create both controls, but there are two functions that simplify creating these controls. They are CreateToolbarEx and CreateStatusWindow. These functions reside in the common controls library, which we Have Included (Include). The Library Should Also Be Initialized with INITCOMMONCONTROLS But We've Already DONE THIS. There is also a toolbar and status bar on the window. You can create these two controls with CREATEWINDOWEX. But these two functions simplified the creation of these controls. They are CreatToolBarex and CreateStatusWindow. These functions have in a general control. This we have already included (including includeLIB ComctL32.lib and Include Comctl32.inc). The library should also be initialized by INITCOMMONCONTROLS. But we have done this.
.data statusparts dd? Data Statusparts DB 90, 170, -1 DefaultStatustext DB "MOSAIC 1.0", 0 .codeinitControls Proc HWND: DWordLocal DefaultFont: DWORD; --- Create a static control --- ...... ....... Static Control Code Here ............; --- Save Default Font --- Invoke GetStockObject, default_gui_font mov defaultfont, Eax; Create Statusbar Window: Invoke CreatestatusWindow, WS_CHILD WS_VISIBLE, / ADDR DefaultStatusText, hWnd, CID_STATUS mov hStatus, eax invoke SendMessage, hStatus, WM_SETFONT, DefaultFont, TRUE invoke SendMessage, hStatus, SB_SETPARTS, 3, ADDR StatusParts ...
In mosaic.inc:
CID_STATUS EQU 600
There are some changes to the procedure here:. There's a new local variable, DefaultFont GetStockObject returns a standard handle for the default system font This handle is stored in DefaultFont The handle does not have to be deleted because it's a system handle... Then CreateStatusWindow is called. This function creates a statusbar, with the string DefaultStatusText as default string. Then SendMessage is called twice. The first time, a WM_SETFONT message is sent to the status window to set the font of the control to the default system font . The second time, the status window is divided in 3 part with the SB_SETPARTS message. StatusParts is an array of bytes that contain the coordinates of the right edge of each part. -1 means that it's size is maximal. here of the process some changes : A new partial variable default. GetStockObject returns a standard handle from the default system font. This handle is stored in DefaultFont. This handle does not have to delete because it is a system handle. Then call CreateStatusWindow. This function creates a status bar as a default string with string defaultstatustext. Then SendMessage is called twice. For the first time, the WM_SETFONT message is sent to the status bar window to set the font of the control for the default system font. The second time, the status bar is divided into three parts by the SB_SETPARTS message. StatusParts Time bytes an array. Among them, the right edge coordinates of each part are included. -1 means maximizing it.
STATUSPARTS DB 90, 170, -1
As you can see, this is a byte array (db) with the value is used by sb_setparts used by sb_setparts. Addr is buy in parameter to give a pointer to the array as the parameter, and not The value itself.
As you can see, this is an array of bytes worth 90, 170 and -1. These are coordinates used by SB_SETPARTS. Use AddR in the parameter to use the addr to the pointer to the array as a parameter instead of the value itself.
6.3 - Toolbar Toolbar
The Toolbar Will Be Created with CreateToolbarex. The Win32 Programmer's Reference Gives this on CreateToolbarex:
The toolbar is created by CreateToolbarex. "Win32 Programmer Reference" has the following narrative for CreateToolbarex:
HWND CREATOOLBAREX
HWND hwnd, DWORD ws, UINT wID, int nBitmaps, HINSTANCE hBMInst, UINT wBMID, LPCTBBUTTON lpButtons, int iNumButtons, int dxButton, int dyButton, int dxBitmap, int dyBitmap, UINT uStructSize); hwnd: Handle of the parent windowws: The toolbar window stylewID: Control ID for the toolbarnBitmaps: Number of button images in the resource bitmaphBMInst: Instance handle of the aplication that contains the button resource imagewBMID: Resource ID of the buttons bitmaplpButtons: Pointer to an array of TBBUTTON structuresdxButton / dyButton: Width and height Of The Buttons on The ToolbardxBitmap / Dybitmap: Width and Height of the Images on The Buttons.
HWND: The handle of the parent window. WS: Toolbar window style. WID: The control ID of the toolbar. Nbitmaps: The number of ports in the bitmap resource. HBminst: Example handle of the program. It contains a button image resource. WBMID: The resource ID of the button bitmap. LpButtons: Pointer to the array of TBButton structures. DXButton / Dybutton: The lengths and width of the button on the toolbar. DXBitmap / Dybitmap: The lengths and width of the picture on the toolbar.
As you can see, we need two things for the toolbar:. A bitmap resource that contains the images for the buttons, and an array of TBBUTTON structures Each structure in this array contains information for one button.
As you can see, we use Toolbar to have two things: a bitmap resource containing images for buttons, and an array of TBButton structures. Each structure of the array contains information of a button.
Creating The Resource Creating Resources
Open Your Resource File Again (Mosaic.rc) Andd The Following to the file:
Open your resource file (MOSAIC.RC) and add a copy to file:
#define bmp_toolbar 801bmp_toolbar Bitmap Discardable "Resources // Toolbar.BMP"
This will define a new resource ID, 801 to BMP_TOOLBAR The second line includes the file toolbar.bmp in the resource file as BMP_TOOLBAR As usual you'll have to define this ID in your include file too..:
This gives BMP_Toolbar a new resource ID, 801. The second line contains file Toolbar.bmp as BMP_Toolbar in the resource file. Like us, you must define this ID in your included file: BMP_Toolbar EQU 801
The Resource You Just Included Is A Simple Bitmap:
The resources you have just contained are a simple bitmap:
The bitmap consists of 6 images with size 32x32 pixels. The toolbar control will extract the button image from this bitmap. It can do this automatically because it knows how many images there are and the size of them.
This figure contains 6 pictures with a size of 32 × 32 pixels. Toolbar Control will expand these buttons images from this bitmap. This can be done automatically because it is handling how many pictures and their size.
TBButton
Furthermore, CreateToolbarex Wants An Array of Tbbutton Structures. The definition of tbbutton is:
In addition, CreateToolbarex requires an array of TBButton structures. The definition of tbutton is:
Typedef struct _tbbutton {int ionmap; int idcommand; byte fsstate; byte fsstyle; dword dwdata; int istring;} tbutton
iBitmap: zero based index to the button image to use for the buttonidCommand: Command ID for the button (sent with WM_COMMAND) fsState: State flags for the buttonfsStyle: Style flags for the buttondwData: Application defined valueiString: zero based index of button string ( NOT USED Here)
iBitmap: The button image index started with 0 starts. IDCommand: The button's CommandID (and WM_COMMAND) FSState: The status flag of the button. FSStyle: Style Sign of Button. DWDATA: The value defined by the program. Istring: The index started at 0 (not used here)
idCommand is an identifier that is sent with the WM_COMMAND message if a button is pressed. We will use the same IDs as the in the menu, this makes pressing a button the same as choosing a menu item. We already defined these IDs in the include File So We can use the the the will use three style:
IDCommand is sent with the WM_COMMAND message when the button is pressed. We will use the same ID as the menu. This makes the same role in pressing the button and selects a menu item. We have defined these IDs in the included file. Therefore, we can use them directly. We used 3 statters here:
TBSTYLE_BUTTON: just a normal pushbuttonTBSTYLE_CHECKGROUP: A group of buttons of which one at a time can be pressed into the 'enabled state' We use this style for the tree types of displaying the titles:. As numbers, as the demo bitmap, or as a user defined bitmap
TbStyle_sep: This Is A Special Style, IT Doesn't Create A Button, Just A SEPERATOR. A SEPERATOR CAN SEPERATE The Button Groups, But you can use the the button.
TBStyle_Button: just a normal button
TBStyle_CheckGroup: A set of buttons. One of them can only be called an active state. We use this style for the three modes of the display block: "Use Digital", "Demo Diagram", "User-Defined Pictures".
TBStyle_sep: This is a special style, it won't create buttons, just partitioning columns (SEPERATOR). A partition bar can separate the button group, but you can use them when you need it.
[In your .data] ToolbarButtons TBBUTTON <0, MI_OPENBITMAP, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, NULL, NULL> TBBUTTON <1, MI_NEWGAME, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, NULL, NULL> TBBUTTON
The brackets <> initialize a structure, each structure member is seperated by a comma. The MI_XXXs are the identifiers used in the menus. The seperators do not need any members of the structures except for the style TBSTYLE_SEP. One of the checkgroup buttons has The Style TBState_enabled, Which Enables The Button By Default. Brand <> Initialize a structure, each structural member is separated by a comma. MI_XXX is the identifier used by the menu. Separation columns In addition to styles TBStyle_sep do not require any other structures. A button in CheckGroup has style TBSTATE_ENABED, which makes this button to select.
Creating The Toolbar Creating Toolbars
Now it's time to create the Toolbar:
[in Your .Data?] HTOOLBAR DD?
[In your .code] invoke CreateToolbarEx, hWnd, WS_CHILD WS_VISIBLE TBSTYLE_FLAT WS_BORDER, / CID_TOOLBAR, 6, hInstance, BMP_TOOLBAR, ADDR ToolbarButtons, / 8, 32, 32, 32, 32, SIZEOF TBBUTTONmov hToolbar, eaxinvoke SendMessage, eax , TB_AUTOSIZE, NULL, NULL
[in mosaic.inc] CID_TOOLBAR EQU 602
THIS CREATES A TOOLBAR WITH:
This uses something to create a toolbar:
Style: child window, visible, border and TBSTYLE_FLAT (nice flat toolbar buttons) Control id: CID_TOOLBAR (602) Bitmap with button images:. BMP_TOOLBAR resource in the module with handle hInstance The fourth parameter (6) indicates the number of buttons in the bitmapTBBUTTON structure: ToolbarButtons (ADDR is used to give a pointer to the array) Buttons: 8 buttons in the array of TBBUTTONs, 32x32 pixels The bitmaps on the buttons are 32x32 pixels too TBBUTTON size:.. SIZEOF TBBUTTON gives the size of the structure .
Style: Child Window, Visible, Border, and TBStyle_Flat (Good-viewed Sort Toolbar Button) Control ID: CID_TOOLBAR (602) Bitmap of the Button Image: The handle is BMP_ToolBar resource in the Hinstance module. The fourth parameter (6) indicates the number of buttons in the bitmap. TBButton Structure: Toolbar Button (addr is used to give a pointer to array). Button: 8 buttons in the array of TBButton, 32 × 32 pixels. The bitmap on the button is also 32 × 32 pixels. TbButton Size: Siezof Tbbutton gives the size of this structure. The Toolbar Handle Is Stored in Htoolbar (DWORD VARIABLE). Finally, The Tb_autosize Message Is Sent To The Toolbar. This Ensures That The Control Has The Proper Size To Display The Buttons and images.
The toolbar handle is stored in the HToolbar (DWORD variable). Finally, the TB_AUTOSIZE message is sent to the toolbar. This ensures that the control has the right size of the display buttons and images.
6.4 - DONE
If You'Ve Done Everything Correctly, IT Should Look Like this:
If you have finished all things correctly, it should be like this:
IF you mesed everything up, here is the capital files: mosaic3.zip.
If you have to complete all things quickly, here there is a current file:
Mosaic3.zip
.