NO MFC, ONLY API - Creation and Use of Status Bar:
There are two ways to create a status bar: 1. Use the CreateStatusWindow function; 2. Use the CREATEWINDOWEX function. No matter which function calls, you must call the InitCommonControls function to ensure that the dynamic link library is successfully loaded.
Type and style of the status bar:
The default location of the status bar is low in the window, you can specify the CCS_TOP style to display it at the top of the client area. Specify the sbars_sizegrip style, and change the handle of the window size in the right of the status bar.
Note: CCS_TOP and SBARS_SIZEGRIP do not specify at the same time, causing the handle that the drag and drop window size invalid.
Text display in the status bar:
Specify the pointer of the status bar index and string by sending a SB_SETTEXT message. Generally, the display of text is left align, you can change this default setting, use '/ t' to align the text, '/ t / t' makes the text right align.
To display status information and do not want to create a status bar, you can use the DrawStatusText function. This function displays information with the same method as the status bar, but it does not automatically set the size and location of the display status information. When this function is called, the size and location must be specified.
In the status bar, the prompt information of the response menu option can be used, and the parameters are as follows:
Menuhelp (// Menuhelp parameter introduction
UINT UMSG, / / This function response message type WM_MENUSELECT or WM_COMMAND
WPARAM WPARAM, WPARAM in //
LPARAM LPARAM, // LPARAM
HMENU HmainMenu, // Menu Bar Handle
Hinstance hinst, // application instance
HWND HWNDSTATUS, / / Status Bar Handle
LPUINT LPWIDS / / An array address of the logo menu index
);
Example 1: Creation and use of the status bar
#define Win32_Lean_and_mean
#include "stdafx.h"
#include "resource.h"
#include
Char * szappname = "statusbar";
Hinstance g_hinst;
HWND G_STATUSBAR; // Global Status Bar Handle
HMENU HmainMenu; // Global menu handle
Lresult Callback WndProc (HWND, UINT, WPARAM, LPARAM);
// Declare the function of creating a status bar
HWnd DocreateStatusbar (HWND, INT, Hinstance, int);
Int apientry Winmain (Hinstance Hinstance,
Hinstance Hprevinstance,
LPSTR LPCMDLINE,
INT ncmdshow)
{
MSG msg;
Hwnd hwnd;
WNDCLASSEX WC;
wc.cbclsextra = 0;
Wc.cbsize = sizeof (wc);
wc.cbWndextra = 0;
Wc.hbrbackground = (Hbrush) getStockObject (White_brush);
Wc.hcursor = loadingcursor (null, idc_arrow); wc.hicon = loadicon (null, idi_application);
Wc.hiconsm = 0;
wc.hinstance = hinstance;
Wc.lpfnWndProc = (WndProc) WndProc;
wc.lpszclassname = szappname;
Wc.lpszMenuname = makeintResource (iDR_Menu1);
wc.style = CS_VREDREDRAW | CS_HREDRAW |
CS_OWNDC | CS_DBLCLKS;
RegisterClassex (& WC);
HWND = CREATEWINDOWEX (0, Szappname, Szappname, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
NULL, HINSTANCE, NULL
HmainMenu = GetMenu (hwnd);
g_hinst = hinstance;
/ / Here, call the function to create a status bar
g_statusbar =
DocreateStatusbar (HWND, 60105, Hinstance, 4);
ShowWindow (HWND, NCMDSHOW);
UpdateWindow (HWND);
While (GetMessage (& MSG, NULL, 0, 0))
{
TranslateMessage (& MSG);
DispatchMessage (& MSG);
}
Return msg.wparam;
}
LResult Callback WndProc (HWND HWND, UINT MESSAGE,
WPARAM WPARAM, LPARAM LPARAM)
{
HDC HDC;
Paintstruct PS;
// Menu item index
Unsigned int Mes [] = {0, 1, 2};
Switch (Message)
{
Case WM_CREATE:
Return 0;
Case WM_MENUSELECT:
// Show prompt information when selecting a menu item
Menuhelp (WM_MENUSELECT, WPARAM, LPARAM,
HmainMenu, G_HINST, G_STATUSBAR, MES);
Return 0;
Case WM_SIZE:
// When the window size changes, recreate the status bar and disappear the original status bar.
DestroyWindow (g_statusbar);
g_statusbar =
DOCREATESTATUSBAR (HWND, 60105, G_HINST, 4);
Return 0;
Case WM_Paint:
HDC = BeginPaint (HWND, & PS);
// Do Drawing
Endpaint (hwnd, & ps);
Return 0;
Case WM_Close:
PostquitMessage (0);
Return 0;
}
Return DefWindowProc (Hwnd, Message, WPARAM, LPARAM);
}
HWnd docreatestatusbar (hwnd hwndparent, // main window handle
INT NSTATUSID, / / Status Bar List
Hinstance hinst, // application instance
INT NPARTS / / Status section is divided into parts)
{
HWND HWNDSTATUS;
Rect rcclient;
Hlocal hloc;
LPINT LPPARTS;
INT I, NWIDTH;
/ / Load Dynamic Connection Library
INITCOMMONCONTROLS ();
// Create a status bar
HWndStatus = CREATEWINDOWEX
0,
StatusclassName,
(LPCTSTR) NULL,
SBARs_sizegrip |
WS_CHILD | WS_VISIBLE,
0, 0, 0, 0,
HWndParent,
(HMENU) NSTATUSID,
Hinst,
NULL);
GetClientRect (hwndparent, & rcclient);
Hloc = Localalloc (LHND, SIZEOF (INT) * NPARTS);
LPPARTS = (int *) Locallock (HLOC);
/ / Calculate the width of each part in the status bar
NWIDTH = RcClient.right / nparts;
For (i = 0; i { LPPARTS [I] = NWIDTH; NWIDTH = nwidth; } / / Sleep in a number of status columns SendMessage (HWndStatus, Sb_SetParts, (WPARAM) NPARTS, (LParam) LPPARTS; Localunlock (Hloc); Localfree (Hloc); // Return to the handle of the status bar Return hwndstatus; } To display additional information in the status bar, you can send SB_SETTEXT messages through the SendMessage function, specify the index of the status bar in WPARAM, and specify the string to be displayed in the LPARAM. There is any opinion, it is recommended to please email: y_h_zhang@sohu.com.