-------------------------------------------------- ------------------------------
Toolbar and status bar
The toolbar and status bar are also an integral part of the Windows standard interface, and the toolbar is usually located below the menu bar. The above is some system defined or its own defined pictures, which can display this button. The status bar is typically located at the bottom of the window to display some information in the program run. The toolbar and status bar are two universal controls for the Windows system. You can create them through two dedicated APIs or using CreateWindowEx to use CreateWindowEx to create them to create them. These two APIs are CreateToolbarex and CreateStatusWindow. Let's take them below.
CreateToolbarex's statement is:
HWND CREATOOLBAREX
HWND HWND,
DWORD WS,
UINT WID,
INT NBITMAPS,
Hinstance HBminst,
UINT WBMID,
LPCTBB / LPBUTTONS,
Int Inumbuttons,
Int DxButton,
Int Dybutton,
Int dxbitmap,
INT DYBITMAP,
Uint ustructsize}
In its parameter, hwnd is the handle of the parent window (that is, our main window), WS is the style of the toolbar, can be synthesized, such as WS_Visible is a visible, tbstyle_flat means a flat button, WS_Border means a side line, etc. Specific manual can be seen. WID is the logo of the toolbar, nbitmaps is the number of pictures of the definition button, because if you want to use your own picture, all the images are going to be in the same line, then you specify the number of the middle, HBminst is included The resource handle of the system image has been defined. When you don't want to draw it yourself, use the memory standard picture, generally containing the Hinstance of these images has been defined as hinst_commctrl in widnows.inc, the same WBMID is generally idb_std_small_color, indicating that the big picture is still small Pictures, etc. Next is the data structure of the definition button, the command number, picture number, and other properties of each button are defined in the middle, the structure is as follows:
TBButton Struct
IBITMAP DWORD?
IDCOMMAND DWORD?
FSSTATE BYTE?
FSStyle Byte?
BRESERVED BYTE 2 DUP (?)
DWData DWORD?
Istring DWORD?
TBButton Ends
Where each structure defines a button, IBITMAP is the image ID, IDCommand is the command number of the button. When you press the button, you will appear in the WPARAM of the WM_COMMAND message, you can know which button is Press. FSState is the initial state of the button, such as TBState_Pressed is already pressed, see more, fsStyle is a style.
The declaration of CreateStatusWindow in the status bar is as follows:
HWND CREATESTATUSWINDOW
Long Style,
LPCTSTR LPSZTEXT,
HWND HWNDPARENT,
Uint WID
);
Style is the style of the status bar, and LPSZText points to the initialization of the text to display the text on the status bar, you can point to NULL. HWndParent is the handle of the parent window. The WID is the window ID. Use the source program for toolbars and status bar
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
Whether to include debug code
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
Debug = 1
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
PROGRAMMED by Luo Yunbin, Bigluo@telekbird.com.cn
; Website: http://asm.yeah.net
Luoyunbin's Win32 ASM Page (Luo Yunbin's Programming Park)
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
; Version Information
; Toolbar and Status Bar Test Program Ver 1.0
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
.386
.Model flat, stdcall
Option Casemap: None; Case Sensitive
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Folder data
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
INCLUDE Windows.inc
INCLUDE User32.inc
INCLUDE KERNEL32.INC
INCLUDE COMCTL32.INC
INCLUDE COMDLG32.INC
INCLUDE GDI32.INC
INCLUDELIB USER32.LIB
IncludeLib kernel32.lib
INCLUDELIB COMCTL32.LIB
INCLUDELIB COMDLG32.LIB
IncludeLib GDI32.LIB
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
; EQU data
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
IDI_MAIN EQU 1000; icon
IDM_MAIN EQU 4000; Menu
IDM_TOOLBAR EQU 4001
IDM_STATUSBAR EQU 4002
IDM_EXIT EQU 4003
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>> Data segments
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
.DATA?
Hinstance DD?
HwinMain DD?
HMENU DD?
Hicon DD?
HTOOLBAR DD?
HSTATUSBAR DD?
SZBuffer DB 256 DUP (?)
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
Data segment
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
.DATA
SzclassName DB "Toolbar Template", 0
SZCAPTIONMAIN DB 'Toolbar and Status Bar Test - Luo Yunbin', 0
DWFLAG DD F_TOOLBAR OR F_STATUSBAR
*********************************************************** *******************
Sign Definition
F_toolbar EQU 00000001B
F_statusbar EQU 00000010B
Sttoolbar Tbbutton
TBButton <0, 0, TBSTATE_ENABED, TBSTYLE_SEP, 2 DUP (0), - 1>
TBButton
TBButton
TBButton
Tbbutton
Num_Buttons EQU 7
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
Code segment
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
.code
IF Debug
INCLUDE Debug.asm
ENDIF
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
Procedure
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
Start:
Call_winmain
Invoke EXITPROCESS, NULL
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
_WinMain Proc
Local @stwcmain: WNDCLASSEX
Local @stmsg: msg
*********************************************************** *******************
If it is already running, activate the running process
*********************************************************** *******************
Invoke Findwindow, Offset SzclassName, NULL
.IF EAX! = NULL
Invoke ShowWindow, Eax, SW_SHOWNORMAL
Invoke EXITPROCESS, NULL
.endif
Invoke INITCOMMONCONTROLS
Invoke getModuleHandle, NULL
Mov Hinstance, EAX
Invoke Loadicon, Hinstance, IDI_MAIN
MOV Hicon, EAX
Invoke loadmenu, hinstance, idm_main
Mov Hmenu, EAX
************** Register window **************************************** **********
Invoke loadCursor, 0, IDC_ARROW
Mov @ stwcmain.hcursor, EAX
Mov @ stwcmain.cbsize, sizeof wndclassex
Mov @ stwcmain.hiconsm, 0
Mov @ stwcmain.style, cs_hredraw or cs_vredraw
Mov @ stwcmain.lpfnwndproc, Offset WNDMAINPROC
Mov @ stwcmain.cbclsextra, 0
Mov @ stwcmain.cbwndextra, 0
Mov Eax, Hinstance
Mov @ stwcmain.hinstance, EAX
Mov @ stwcmain.hicon, 0
Mov @ stwcmain.hbrbackground, color_btnface 1
Mov @ stwcmain.lpszclassname, offset szclassname
Mov @ stwcmain.lpszMenuname, 0
Invoke registerclassex, addr @stwcmain
; ************** Establish an output window ****************************************** ******** Invoke CreateWindowEx, NULL, /; WS_EX_CLIENTEDGE, /
Offset szclassname, Offset Szcaptionmain, /
WS_OVERLAPPEDWINDOW, /; or WS_VSCROLL or WS_HSCROLL, /
50, 50, 550, 350, /
NULL, HMENU, HINSTANCE, NULL
Invoke ShowWindow, Hwinmain, SW_SHOWNORMAL
Invoke UpdateWindow, HwinMain
************** Message loop ***************************************** ***********
.While true
Invoke GetMsg, NULL, 0, 0
.break .if eax == 0
Invoke TranslateMsg, Addr @stmsg
Invoke DispatchMessage, Addr @STMSG
.endw
RET
_WinMain ENDP
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
WNDMAINPROC PROC Uses EBX EDI ESI, /
HWnd: DWORD, UMSG: DWORD, WPARAM: DWORD, LPARAM: DWORD
MOV EAX, UMSG
.IF EAX == WM_CREATE
Mov Eax, HWnd
Mov Hwinmain, EAX
Call_init
*********************************************************** *******************
.ELSEIF EAX == WM_SIZE
Invoke SendMessage, Hstatusbar, UMSG, WPARAM, LPARAM
Invoke SendMessage, Htoolbar, UMSG, WPARAM, LPARAM
*********************************************************** *******************
.ELSEIF EAX == WM_COMMAND
Mov Eax, WPARAM
Movzx Eax, AX
.IF eax == idm_exit
Call_quit
.ELSEIF EAX == IDM_TOOLBAR
XOR dwflag, f_toolbar
Call_AranGewindow
.ELSEIF EAX == IDM_STATUSBAR
XOR dwflag, f_statusbar
Call_AranGewindow
.lse
_Debug "Menu and Toolbar Command", "Command ID", EAX
.endif
*********************************************************** *******************
.ELSEIF EAX == WM_Close
Call _quit; ******************************************************************************************************************************************************************************************************************************************************************************************* ********************
.lse
Invoke DefWindowProc, Hwnd, UMSG, WPARAM, LPARAM
RET
.endif
*********************************************************** *******************
Note: After WndProc processes the Windows message, you must return 0 in Eax.
But the return value after the DEFWINDOWPROC cannot be changed, otherwise the window
; Will not be displayed!
*********************************************************** *******************
XOR EAX, EAX
RET
WNDMAINPROC ENDP
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
Main window control subroutine
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>
_Init proc
Invoke SendMessage, HwinMain, WM_SETITION, ICON_SMALL, HICON
Invoke CreateToolbarex, HwinMain, /
WS_VISible or WS_CHILD or TBSTYLE_FLAT or WS_BORDER, /
1,0, hinst_commctrl, idb_std_small_color, offset attoolbar, /
Num_Buttons, 0,0,0,0, sizeof tbutton
Mov Htoolbar, EAX
Invoke CreateStatusWindow, WS_CHILD or WS_Visible, Null, Hwinmain, 2
Mov Hstatusbar, EAX
Call_AranGewindow
RET
_Init ENDP
*********************************************************** *******************
_Quit Proc
Invoke DestroyWindow, HwinMain
Invoke PostquitMessage, NULL
RET
_Quit ENDP
*********************************************************** *******************
_ArrangeWindow Proc
Local @STRECT: RECT
Local @stRectTemp: Rect
Local @dwwidth: DWORD
Test dwflag, f_toolbar
.IF ZERO? Invoke showwindow, htoolbar, sw_hide
Invoke Checkmenuitem, Hmenu, IDM_Toolbar, MF_unchecked
.lse
Invoke ShowWindow, HTOOLBAR, SW_SHOW
Invoke Checkmenuitem, Hmenu, IDM_Toolbar, MF_CHECKED
.endif
Test dwflag, f_statusbar
.IF ZERO?
Invoke ShowWindow, Hstatusbar, SW_HIDE
Invoke CHECKMENUITEM, HMENU, IDM_STATUSBAR, MF_UNCHECKED
.lse
Invoke ShowWindow, Hstatusbar, SW_SHOW
Invoke Checkmenuitem, Hmenu, IDM_STATUSBAR, MF_CHECKED
.endif
RET
_ArrangeWindow Endp
*********************************************************** *******************
End Start
Program analysis and points
In the toolbar and status bar program, you should pay attention to the toolbar and status bar without changing your own adjustment position and size with the size of the porn, so you can move and adjust them in the WM_SIZE message of the parent window. Simply pass the WM_SIZE message to them. Don't calculate yourself.
.ELSEIF EAX == WM_SIZE
Invoke SendMessage, Hstatusbar, UMSG, WPARAM, LPARAM
Invoke SendMessage, Htoolbar, UMSG, WPARAM, LPARAM
In addition, the toolbar and status bar are also a sub-window, so if you want to hide or display them, you can use the standard showWindow to process.