Win32 Public Control - Status Bar and Toolbar

xiaoxiao2021-03-06  19

This article introduces Part 2 of the Public Control Series, describes two new public controls: status bar and toolbar. Other articles in this series covers the following topics: Part 1: Basis 3: Slide strips, progress bars and upper and lower controls Part 4: Head Window and List View Window Part 5: Images list and tree view window 6 Part: Tag controls and property pages 2 to 6 are equipped with relevant source code. WARNING: This supporting toolbar executable is built and tested using Windows 95 initial development packages. This executable can only run in Windows 95 without running in Windows 3.1 or Windows NT 3.5. If your machine is installed with Windows 95 but if you can't run, please copy the individual files of the project to the machine to rebuild. The status bar status bar is a horizontal window that is used by default, it is placed on the bottom of the parent window to display the application definition information. If you want to display the status information of multiple categories, you can segment the status bar. You can create a status bar by calling CREATEWINDOW or CREATEWINDOWEX and specifies the window class of the function parameters as statusclassname. After you created, you can segment it and set the text of each segment, and control its appearance by sending a status bar message. The default window procedure is automatically resized when the WM_SIZE message is received. Figure 1 shows a status bar that displays the current location of the mouse.

Figure 1. Simple status bar sample I found that the status bar is very beneficial to use the status bar when the debugger is used. When you are tired of the debugger, you may usually use a message box with a message box when you reach a line of code, I suggest you use the status bar in this time. The style of the status bar and the default behavior status bar unique new style is the SBS_SIZEGRIP style, which places a size controller in the lower right corner of the status bar. This controller is the same as the border - it is a rectangular area, the user can click and drag it to reset the size of the parent window. Warning: If you decide to include a size controller, do not combine the CCS_TOP and SBS_SIZEGRIP style, otherwise the size controller will fail. Because the system still draws the size controller on the status bar, if the user tries to use it, it will think that your application has faults. You can set the minimum height (in pixel meter) and the minimum drawing area of ​​the minimum draw area by sending a SB_SETMINHEIGHT message. Note that the drawing area does not include the border of the window. If you want to set the border width of the status bar, you can send a SB_setBorders message. This message passes a three-member array address, which is the width of the horizontal border, the width of the vertical border, and the width of each segment of the separated status bar. These widths are in pixels. If you want to use the default width, you can pass a -1 value. Creating a status bar window You can create a status bar using the CREATEWINDOWEX function. The default size value of the status bar is (-100, -100, 10, 10). The following example creates a status bar and displays the current mouse cursor position (like Figure 1), which is located in the window of the status bar parent window.

Switch (Message) {case wm_create: hWndStatus = CreateWindowEx (0L, // Non-extended style statusclassname, // status bar "", // no text WS_CHILD | WS_BORDER | WS_VISIBLE, // Style -100, -100, 10, 10 , // x, y, hmenu) 100, // window ID hinst, // instance handle null); // window data IF (hwndstatus == null) MessageBox (null, " Status Bar Not Created! ", NULL, MB_OK; BREAK; Case WM_Mousemove: WSPrintf (Szbuf," Mouse Position:% D,% D ", Loword (LPARAM), HiWord (LPARAM)); SendMessage (HWndStatus, Sb_Settext, 0 In the above code, I use CreateWindowEx to emphasize that these new public controls are windows - you create them, send them messages, and from them There are notification messages there - just like you have other windows. A function called createStatusWindow allows you to create a status bar at the bottom of the parent window, which creates this status bar by calling CREATEWINDOWEX and delivering the default location (-100, -100, 10, 10). This function comes with four parameters, as follows: long style: status bar window style. LPCSTR LPSZTEXT: Status bar default text. HWND HWNDPARENT: The parent window handle. UINT WID: Window ID. The single-segment and multi-stage status bar single status bar is usually used to display a single line text description when the user uses a mouse to a menu item. You can convert between a single status bar and a multi-stage status bar by sending a SB_SIMPLE message, but remember that the single status bar does not support yourself. The multi-stage status bar can display different texts per segment. You can send SB_SETPARTS messages to the status bar to segment it, where you need to specify the number of segments and sizes of each segment. The status bar can have 255 segments. The single text and multi-segment text of the status bar are saved separately. That is, you can set the status bar as a single segment, then set the text, and switch the text when switching to multiple modes. You can customize other controls by adding self-drawing from the status bar to the status bar, just like you customize other controls. Use the self-drawn to display a bitmap in the status bar or use different fonts. To define a paragraph of the status bar as self-drawn, you need to send SB_SETTEXT messages to it, and specify SBT_OWNERDRAW drawing technology. When you specify SBT_OWNERDRAW, the LPARAM parameter becomes a value defined by an application, and you can use this value when drawn.

At this point, you can treat this space as any other self-drawing control: you handle the WM_DRAWITEM message and use the information included in the passing DrawItemStruct. Status Bar Message lists messages you can send to status bar in this section. You will find that many messages can be used to send to the header window. In fact, the head window process is indeed calling the window procedure of the status bar. For the head window, you can refer to this series of "WIN32 Public Controls - Part 4: Head Window and List View Window". Several messages of the status bar need to return a plotting operation type. These operation types you can use are listed in the table below. Table 1. The text drawn text drawn by the status bar is slightly lower than the window layout. The SBT_OWNERDRAW application draws text or bitmap when receiving the WM_DRAWITEM message. Note that the CTLTYPE, ItemState, and ItemAction domains of the DrawItemstruct structure are not defined for the status bar. SBT_NOBORDERS draws text, but does not draw borders. SBT_POPOUT drawn text slightly above the window layout. The text or bitmap drawn by hbt_spring has a resilient, that is, the status bar has a minimum length, but can be at will (as long as the window has enough space). Multiple items (projects in the multi-stage status bar) can also extend (this type originally created for the head control, which is why it is "HBT" instead of "SBT".) SB_GetBordersWParam = 0; // Do not use LParam = (LPINT) Aborder; // Used to receive a array description of the boundary value: SB_GetBorders message is used to get the current level of the status bar or the header window and the width of the vertical border. This measurement method determines the spacing between the outer boundaries of the window and the number of the rectangles of the text and the spacing between the rectangles and the rectangles. Parameters: WPARAM is not used, LPARAM represents an address of three element arrays. This is the first element receives the width of the horizontal border, the second receiving the width of the vertical border, the width of the third reception rectangle. Return Value: Successfully returns true, otherwise returns false. SB_GETPARTSWPARAM = nParts; // The number of segments to be obtained lParam = (LPINT) ARIGHTCOORD; / / Receive the array description of the right boundary: SB_GETPARTS message is used to obtain the number of segments of the status bar and the coordinates of the right border to the right. Parameters: WPARAM defines the number of segments to get this message. If this parameter is larger than the actual number of status columns, this message only gives the number of segments. LPARAM is an integer array address, its number of elements is equal to the number specified by WPARAM. Each element in the array receives the client area coordinates of the respective segments. If an element is set to -1, then this section is a segment of the rightmost. Return Value: If success, return the number of segments of the status bar, otherwise returns 0. SB_GETTEXTWPARAM = IPART; / / Status Raider Index LPARAM = (LPSTR) Sztext; / / Receive String Buffer Pointer Description: SB_Text is used to get the text of the status bar or the header window given the segment. Parameters: WPARAM is the segment index (starting with 0), and lparam is used to receive the buffer address of the text, which is the end of the empty character. Return value: SB_Text returns a 32-bit value, which consists of two 16-bit values. The low word represents the character length of the text, and the high word represents the type of operation of the text.

If the type of text is SBT_OWNERDRAW, then this message returns a 32-bit value, this value is associated with text, not the length and type. With regard to the type of operation, you can view Table 1. SB_GETTEXTLENGTHWPARAM = iPart; // Status field index lparam = 0; // Does not use the description: SB_GETTEXTLENGTH message is used to get the text character length of the status bar or the header window given the segment. Parameters: WPARAM is the segment index of the text (starting with 0), LPARAM is not used. Return Value: SB_GETTEXTLENGTH returns a 32-bit value, which consists of two 16-bit values. The low word represents the character length of the text, and the high word represents the type of operation of the text. If the type of text is SBT_OWNERDRAW, then this message returns a 32-bit value, this value is associated with text, not the length and type. With regard to the type of operation, you can view Table 1. SB_setBordersWParam = 0; // Does not use LPARAM = (LPINT) Aborder; // Contains Array Description of Border Values: SB_SetBorders Messages Used to set the level of status bar or header window and the width of the vertical border. This measurement method determines the spacing between the outer boundaries of the window and the number of the rectangles of the text and the spacing between the rectangles and the rectangles. Parameters: WPARAM is not used, LPARAM represents an address of three element arrays. The first element specifies the width of the horizontal border, the second specified the width of the vertical border, the width of the border between the third specified rectangle. Return Value: Successfully returns true, otherwise returns false. SB_SETMINHEIGHTWPARAM = MinHeight; // The minimum pixel height lParam = 0; // Does not use the description: SB_SETMIINHEIGHT message is used to set the minimum height of the status bar or the header window, the minimum height of the window is the minimum height (wparam) and vertical borders Sum. Parameters: WPARAM is the minimum pixel width of the window, LPARAM is not used. Return Value: None. SB_SETPARTSWPARAM = NPARTS; // Segment number (<= 255) LPARAM = (LPINT) AWIDTHS; / / Contains an array address description of the width: SB_SETPARTS is used to set the number of segments of the status bar and the rightmost coordinates of each segment. Parameters: WPARAM is the number of segments to set, this number cannot exceed 255. LPARAM is an address of a plastic array, which has the number of elements and the number of segments specified by WPARAM. Each element in the array specifies the client area coordinates of the respective segment right boundary. If an element is -1, then the segment is located at the rightmost segment. Return Value: Successfully returns true, otherwise returns false. SB_SETTEXTWPARAM = iPart | Upart; // Segment index and drawing operation type LPARAM = (lpstr) sztext; // String buffer pointer description: SB_SETTEXT message Used to set the text of the status bar or the header window. This message will fail to change the window part of the text, causing the window to display new text.

Parameters: WPARAM is 0 start segment index and the type of drawing operations listed in Table 1, if this value is 255, indicating that this status bar is a simple single-segment state bar. LPARAM is an empty character of the tail string, which specifies the text to be set. If WPARAM is SBT_OWNERDRAW, LPARAM is a 32-bit data. The parent window must handle this data when it receives WM_DRAWITEM. Return Value: Successfully returns true, otherwise returns false. SB_SIMplewParam = (BOOL) fsimple; // If it is simple text, use TruelParam = 0; // Do not use the description: SB_SIMPLE message is used to specify whether the status bar displays simple single text, or display a multi-segment previously set by SB_SETPARTS messages text. Parameters: If wparam is True, the status bar displays simple text. If wparam is false, the status bar displays a multi-segment. LPARAM is not used. Return Value: If an error occurs, it returns false. The toolbar toolbar is a horizontal window with a button at the top of the parent window, and the user can complete the corresponding command by selecting the button's button. You can create a toolbar by calling the CREATEWINDOWEX or CREATEWINDOW function, and you can also increase, delete and manage the buttons on the toolbar by sending toolbar messages. If you are familiar with the status bar in MFC or Visual Basic, then you will find that toolbar controls in Win32 will be very easy to get started. If you are not familiar with the toolbar, don't be disappointed - they are very easy to implement. Figure 2 is a toolbar with 4 buttons, you will notice the first three buttons (with numbers) are close together, and the other has the door icon (no matter what, assume it like a door. The button is a point of space from them. This space is called Separator, which is used to implement the logical grouping of the status bar button. Figure 2. Simple toolbar sample toolbar style and its default behavior toolbar window procedure is the default settings and size. By default, the toolbar is displayed at the top of the parent window customer area; however, you can also enable it in the bottom of the customer area by specifying the CCS_BOTTOM style. The toolbar is unique to a new style is TBStyle_Tooltips, which makes the toolbar to display tooltips (that when you stay on the toolbar button). The system will send a WM_NOTIFY message to it when the population needs to display pop-up text. The following sample code demonstrates the implementation of the tooltip feature. Creating a toolbar as described above, create a toolbar is simple: You populate a button structure, create a large bitmap containing the button, then call the CREATEWINDOWEX function, and specify the ToolbarclassName window class. When the toolbar is created, you need to send a message to add a button and a bitmap. Then, if you don't have any special things to do, you can let the system handle the toolbar. The following code creates a toolbar that loads a bitmap and adds some buttons to the toolbar.

// fill toolbar button structure described TBBUTTON tbButtons [] = {{0, IDM_OPT1, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0}, {1, IDM_OPT2, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0}, {2, IDM_OPT3, TBSTATE_ENABLED, TBStyle_Button, 0L, 0}, {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, -1}, {3, IDM_EXIT, TBSTATE_ENABED, TBSTYLE_BUTTON, 0L, 0}}; // If in Win32, then declare a bitmap Structure TBADDBITMAP TBBITAMPS; // Initialization Member ... TBbitamps.hinst = Hinstance; // Current instance TBbitMaps.nid = IDB_TOOLBAR; // Bitmap Resource ID ... // Create a function of a Win32 toolbar // parameter: // hwnd hwndparent - parent window handle // long lnumbitmaps - bitmap number // tbaddbitmap tbitmaps - Bitmap structure under Win32 // long lnumbuttons - Toolbar's button // tbbuton tbuttons - button structure Pointer / / DWORD DWSTYLE - Specifies the toolbar window style, which can be a combination of public control style or toolbar-specific style // int itoolbarid - Toolbar ID // Return Value: // If success, return the toolbar handle, otherwise return NULL // HWND MyCreateTooolBar (HWND hWndParent, LONG lNumBitmaps, TBADDBITMAP tbBitmaps, LONG lNumButtons, TBBUTON tbButtons, WORD wStyle, UINT uToolBarID) {HWND hWndToolBar; // Create the toolbar control hWndToolBar = CreateWindowEx. (0L, // Non-extended style ToolbarclassName, // Toolbar window ", // no default text WS_CHILD | WS_BORDER | WS_VISIBLE | DWSTYLE, // Style and default 0, 0, 100, 30, // Standard Tool Boot size and position hwndparent, // Toolbar Parent Window (HMENU) Itoolbarid, / / ​​Toolbar ID TBBITMAPS-> Hinst, // Current instance null); // No class data If (hwndtoolbar) {// load toolbar Figure if (SendMessage (hWndToolBar, TB_ADDBITMAP, lNumBitmaps, (LONG) & tbBitmaps) == -1) return (NULL); // add button SendMessage (hWndToolBar, TB_ADDBUTTONS, lNumButtons, (LONG) & tbButtons); // successfully created a toolbar ,

Returns the handle return (hwndtoolbar); // Create a failure, return null return null;} Another way to create a status bar is to call the CreateToolbarex function, the functionality of this function, and the MYCREATOOLBAR I have written on the top. The CreateToolbarex function comes with the following parameters: • HWND HWND: The parent window handle of the toolbar. DWORD WS: Window style of the toolbar. · Word WID: The ID of the toolbar. INT NBITMAPS: The number of images included in the bitmap specified by HBminst and WBMID. · Hinstance HBMinst: An instance of executable file module with bitmap resources. · Word WBMID: Bitmap Resource ID. If hbminst is null, then this value must be a valid bitmap handle. • LPCTTBB /TON LPBUTTONS: The address of the TBButton structure. · INT Inumbuttons: The number of buttons added to the toolbar. · Int DXButton, Dybutton: The pixel width and length of the button. · Int DXBitmap, Dybitmap: pixel width and length of bitmaps. • UINT USTRUCTSIZE: The size of the TBButton structure. You can add support to the toolbar by specifying the TBStyle_Tooltips style and create a stringTable in the .rc file. If you do this, then you need to handle the WM_NOTIFY message of the toolbar father window, as shown below: // This is the contentablebegin IDM_OPT1, "Option 1" IDM_OPT2, "Option 2" IDM_OPT3, "Option 2" IDM_OPT2, "Option 2" IDM_OPT2, "Option 2" IDM_OPT3 3 "IDM_EXIT," Exit Tool bar Sample "END // this is the content of the .C file TOOLINFO tbToolInfo; // capture the WM_NOTIFY case WM_NOTIFY: lpToolTipText = (lPTOOLTIPTEXT) lParam; if (lpToolTipText-> hdr.code == TTN_NEEDTEXT) {// If the system needs text, load LoadString from the resource (Hinst, LptoolTipText-> HDR.IDFROM, // String ID == Command ID SZBUF, SIZEOF (SZBUF)); // Point Structure LPTooltiptext -> lpsztext = szbuf;} Break; You can click here to download the project file and run Toolbar.exe to see how this code is working. WARNING: The executable of the toolbar is built and tested using the first development package for Windows 95. This executable can only run under Windows 95 and cannot run in Windows 3.1 or Windows NT 3.5. If your machine is equipped with Windows 95, but there is a problem when running this instance, copy the project file and re-build, and finally re-run the executable. Toolbar Structure This section describes some structures, you can use them to create and manage toolbars and their buttons in Win32. Each button you add can have a pattern listed in the table below, which can be used in a TBButton structure. Table 2. Toolbar Button Style TBStyle_Button Standard Button.

TBStyle_Check is similar to Checkbox's selection button with two status. TBStyle_CheckGroup is similar to the Radiobox packet selection button. TBStyle_Group is the same. TBStyle_sep separator, point space between the button group. When you specify your toolbar and its buttons, you may need to query status information for the toolbar button. The current state is saved in a TBButton structure, as described below. If you need to dynamically decide the status of the button, then you can send TB_GETSTATE messages to the toolbar. Table 3. Toolbar Button Status TBSTATE_CHECKED is selected. TBSTATE_ENABLED is valid. TBSTATE_HIDEN hides. TBState_indeterminate blurred. TBSTATE_PRESSED Press. TbButtynTyped {int ion mapp; // button bitmap index int idcommand; // button command id byte fsstate; // button status flag, see Table 3 Byte fsStyle; // button style, see Table 2 DWord dwdata; // Application Program defined data int istring; // button help text string index} TBButton; TBButton structure contains information of the toolbar button, including the following member: • int ionmap: 0 Start index, identify button image in the bitmap s position. · INT IDCOMMAND: The command identifier associated with the button. This identifier will be transmitted via WM_COMMAND when the button is pressed. If the FSStyle member is TBStyle_sep, then this member must be 0. · BYTE FSSTATE: Button Status Sign, which can be a value combination in Table 3. · Byte FSStyle: Button style flag, which can be a combination of values ​​in Table 2. · DWORD DWDATA: Values ​​defined by the application. Int istring: Help text index of the button in the string list. AdjustInfotyPedef struct tagadjustinfo {tbutton tbutton; // Contains the structure of the button information Char szdescription [1]; // TBD}; AdjustInfo structure contains information of the user-defined button in the toolbar, which includes the following members: · TbButton TbButton: Contains the structure of the button information. · Char szdescription: The method of use of this member has not been decided. TBADDBITMAPTYPEF STRUCT TAGTBADDBITMAP {hinstance hinst; // contains an instance handle of bitmaps Uint NID; // bitmap resource ID} TBADDBitMap; TBADDBITMAP structure contains information about bitmaps added to the toolbar, this structure is written Win32 application It is very useful when it includes the following members: Hinstance Hinst: Contains an instance handle of a bitmap. · UINT NID: The resource ID of the bitmap. The toolbar message system and application can send messages to the toolbar, just like sending messages to other windows. This section lists messages that can be sent to the toolbar space, as well as WPARAM and LPARAM values ​​for each message.

TB_ADDBITMAPWPARAM = NBUTTONS; // // // Bit Map Number LParam = (LPTBADDBITMAP) LPTBAB; // Bit Tibet Handle Description: TB_ADDBITMAP Message Used to add a new bitmap to the toolbar, this message is only Can be used in non-Win32 applications. Parameters: WPARAM represents the number of buttons in the bitmap, lparam is a pointer to a TBAddBitmap structure. Return Value: The low word contains the index of the first button bitmap. If the function call is successful, the high word is not used; if the call is unsuccessful, the low word is -1. TB_ADDBUTTONSWPARAM = nbuttons; // Number LPARAM = (LPTBB / /) LPButtons; // Button Structure Array Address Description: TB_ADDBUTTONS Message Used to add one or more buttons to the toolbar. Parameters: WPARAM represents the number of buttons you want to add, LPARAM is a pointer for a TBButton structure array, which contains information about the button to be added. This array must contain the same elements as the number of buttons specified by WPARAM. Return Value: Successfully returns true, otherwise returns false. Tb_addstringwparam = (hinstance) hinst; // contains an instance handle of a string (idString, 0); // String ID or string buffer description: TB_ADDSTRING message is used to the string list available to the toolbar Add a new string to it. Parameters: WPARAM is a module instance handle that contains a string resource - if lparam points to one or more strings, WPARAM should be 0. LPARAM is a resource ID of a string resource, or a buffer that is to be added to a string list containing one or more empty characters ending, and the number of strings is specified by WPARAM. The last string must be ended by two NULL characters. Return Value: If success, return the index of the first new string, otherwise returns -1. TB_AUTOSIZEWPARAM = 0; // Does not use LPARAM = 0; // Do not use the description: TB_AUTOSIZE message is used to reset the toolbar to reset the size. The application can change this message after setting the button or bitmap, and can send this message to change the size of the toolbar. Parameters: WPARAM and LPARAM are not used. Return Value: None. Tb_ButtonCountWParam = 0; // Do not use lparam = 0; // Do not use the description: TB_ButtonCount message is used to get the total number of toolbar current buttons. Parameters: WPARAM and LPARAM are not used. Return Value: The number of buttons in the toolbar. Tb_ButtonStructSizeWParam = CB; // TbButton structure byte size LPARAM = 0; // Does not use Description: TB_BUTTONSTRUCTSIZE is used to specify the size of the TBButton structure, the system uses this size to determine the current CommCtrl.dll version. If the application uses CREATEWINDOW to create a toolbar, it must send this message before adding all buttons.

The CreateToolbarex function automatically sends this message and the TBButton structure as a parameter of this function. Parameters: WPARAM is the byte size of the TBButton structure, and LParam is not used. Return Value: None. TB_CHECKBUTTONWPARAM = idbutton; // To select the button command idlparam = makelong (fCheck, 0); // Selection tag - TRUE is added, false is the removal description: TB_CHECKBUTTON message is used to select or do not select a given button. When a button is selected, its appearance is pressed. Parameters: WPARAM is the button command ID to be selected. If LPARAM is True, add a selected tag; if lparam is false, the selected tag is removed. Return Value: Successfully returns true, otherwise returns false. TB_COMMANDTOINDEXWPARAM = idButton; // button command idlparam = 0; // Does not use the description: TB_COMMANDTOINDEX message is used to get button indexes associated with the command ID. Parameters: WPARAM is associated with the button associated with the command ID, LPARAM is not used. Return Value: The index of the button. TB_CUSTOMizeWParam = 0; // Do not use lparam = 0; // Do not use description: TB_CUSTOMIZE message is used to display the custom toolbar dialog. Parameters: WPARAM and LPARAM are not used. Return Value: None. TB_DELETEBUTTONWPARAM = ibutton; // To delete the index lparam = 0; // Do not use the description: TB_DELETEBUTTON message is used to delete a button from the toolbar. Parameters: WPARAM is the index of the delete button, LPARAM is not used. Return Value: Successfully returns true, otherwise false. TB_ENABLEBUTTONWPARAM = IDBUTTON; / / The command idlparam = makelong (fenable, 0); // tag - TRUE is effective, false is a failure description: TB_ENABLEBUTTON is used to take the specified button to take effect or fail. When the button takes effect, it can be pressed and selected. Parameters: WPARAM is the command ID of the button to take effect or invalid. If lparam is True, the button takes effect; if lparam is false, the button is invalid. Return Value: Successfully returns true, otherwise returns false. Tb_getButtonWParam = ibutton; // The button index lParam = (lptbutton) lpButton; / / receives a buffer description of the button information: The TB_GetButton message is used to receive the information of the given button. Parameters: WPARAM is the button index to get the information, LPARAM is an address of the TBButton structure used to receive button information. Return Value: Successfully returns true, otherwise returns false.

TB_GETITEMRECTWPARAM = IBUTTON; / / The index lParam = (LPRECT) LPRC; // Used to receive the array description of the rectangum value: TB_GETITEMRECT message is used to obtain a rectangular range of the toolbar button, which cannot be used to obtain a button rectangle with a TBSTATE_HIDEN state range. Parameters: WPARAM is a button index to get information, and lparam is a RECT structure pointer for receiving a rectangular range coordinate. Return Value: Successfully returns true, otherwise returns false. TB_GETSTATEWPARAM = idButton; // button command idlparam = 0; // Does not use the description: TB_GETSTATE message is used to obtain the status information of the button, that is, the button is taken effect, pressed or selected. Parameters: WPARAM is the button command ID to get information, LPARAM is not used. Return Value: If the call is successful, the message returns the status information of the button (see Table 3). Returns -1 if the call fails. Tb_HideButtonwParam = IDButton; // The command idlparam = makelong (fshow, 0); // true is hidden, false is a display description: TB_HIDeButton message is used to hide or display the specified button. Parameters: WPARAM is the button command ID to be hidden or displayed. If lparam is true, hide the button; if false is false, the button is displayed. Return Value: Successfully returns true, otherwise returns false. Tb_indeeeterminatewparam = idbutton; // button command idlparam = makelong (Findeterminate, 0); // true is set, false is a clear description: TB_IndeterMinate message is used to set or clear the fuzzy state of the specified button. Parameters: WPARAM is the button command ID to set or clear the status. If lparam is true, set the blurred state; if false is false, clear this status. Return Value: Successfully returns true, otherwise returns false. TB_INSERTBUTTONWPARAM = IBUTTON; // button Index LParam = (LPTBB /TTON) LPButton; // Button Information Structure Description: TB_INSERTBUTTON message is used to add a button to the toolbar. Parameters: WPARAM is the index value of the button. This message is inserted into the new button before the button indexed the WPARAM. LPARAM is a TBButton structure that contains information to be inserted into the button. Return Value: Successfully returns true, otherwise returns false. TB_ISBUTTONCHECKED, TB_ISBUTTONENABED, TB_ISBUTTONENEN, TB_ISBUTTONHIDDEN, TB_ISBUTTONDETERMINATE, TB_ISBUTTONPRESSEDETE, TB_ISBUTTONPRESSEDWPARAM = idButton; // button command idlparam = 0; // Does not use Description: These messages determine if a given button is selected, effective, hidden or depressed. Parameters: WPARAM is the command ID of the button, LPARAM is not used.

Return Value: If the status is true, then return to a 0 value, otherwise it returns 0. TB_PRESSBUTTONWPARAM = idButton; // button command idlparam = makelong (fpress, 0); // true is depressed, false is a released description: TB_PRESSBUTTON message is used to depress or release a given button. Parameters: wparam is the button command ID to be depressed or released. LParam If is TRUE, the button is depressed; if it is false, the button is released. Return Value: Successfully returns true, otherwise returns false. Tb_saverestorewParam = (BOOL) fsave; // true is saved, false is a string description for restoring LPARAM = (LPSTR) lpszsectionFile; // Used to save information: TB_saveRestore message is used to save or restore the status of the toolbar. Parameters: If wparam is True, save the information; otherwise, restore information. LPARAM is an address of two consecutive zero tail strings. The first string specifies the segment name in an initialization file, the second specified file name of the initialization file. If the second string is empty, the message uses the default value Win.ini file. Return Value: None. TB_SETBITMAPSIZEWPARAM = 0; // Does not use LParam = Makelong (DXBitMap, Dybitmap); // To set the width and height description: TB_SETBITMAPSIZE message is used to set the size of bitmap images to be added to the toolbar, this size must be added Set before any bitmap. If the application does not explicitly set bitmap size, this size is set to 16 × 15 pixels. Parameters: WPARAM is not used, LPARAM is the pixel width and height of bitmap images. Return Value: Successfully returns true, otherwise returns false. Tb_setButtonsizeWParam = 0; // Does not use lparam = makelong (dxbutton, dybutton); // To set the width and height description: TB_SETBUTTONSIZE message is used to set the button size to be added to the toolbar, this size must be before adding any button Set. This size will be set to 24 × 22 pixels if the application does not explicitly set the button size. Parameters: WPARAM is not used, lparam is the pixel width and height of the button. Return Value: Successfully returns true, otherwise returns false. TB_SETSTATEWPARAM = IDBUTTON; / / The command idlparam = makelong (fstate, 0); // To set the status (see Table 3) Description: The TB_SETSTATE message is used to set the status of the given button. Parameters: WPARAM is the command ID of the button, and the LPARAM consists of the status flag in Table 3. Return Value: Successfully returns true, otherwise returns false. Toolbar Notification Message This section lists the notification messages sent to the toolbar window, and the parent window of the toolbar receives these messages via WM_Command. In addition to another instruction, Windows ignores the return value of these messages. In all cases, WPARAM contains the ID of the toolbar. Table 4. Toolbar Notification Message

Summary Status Bar and Toolbar are very convenient controls because users can quickly get started and easily implemented. These controls are built in Windows 95, so you don't have to worry about whether your toolbar or status bar can be compatible with the operating system or other companies. If you plan to add a status bar or toolbar to your existing app, then I suggest you try these new public controls, using this method is simple.

转载请注明原文地址:https://www.9cbs.com/read-56655.html

New Post(0)