15,979
社区成员
发帖
与我相关
我的任务
分享
HWND DoCreateStatusBar(HWND hwndParent, int idStatus, HINSTANCE hinst, int cParts)
{
HWND hwndStatus;
RECT rcClient;
HLOCAL hloc;
PINT paParts;
int i, nWidth;
// Ensure that the common control DLL is loaded.
InitCommonControls();
// Create the status bar.
hwndStatus = CreateWindowEx(
0, // no extended styles
STATUSCLASSNAME, // name of status bar class
NULL, // no text when first created
SBARS_SIZEGRIP | // includes a sizing grip
WS_CHILD | WS_VISIBLE, // creates a visible child window
0, 0, 0, 0, // ignores size and position
hwndParent, // handle to parent window
(HMENU) idStatus, // child window identifier
hinst, // handle to application instance
NULL); // no window creation data
// Get the coordinates of the parent window's client area.
GetClientRect(hwndParent, &rcClient);
// Allocate an array for holding the right edge coordinates.
hloc = LocalAlloc(LHND, sizeof(int) * cParts);
paParts = (PINT) LocalLock(hloc);
// Calculate the right edge coordinate for each part, and
// copy the coordinates to the array.
nWidth = rcClient.right / cParts;
for (i = 0; i < cParts; i++) {
paParts[i] = nWidth;
nWidth += nWidth;
}
// Tell the status bar to create the window parts.
SendMessage(hwndStatus, SB_SETPARTS, (WPARAM) cParts, (LPARAM)
paParts);
// Free the array, and return.
LocalUnlock(hloc);
LocalFree(hloc);
return hwndStatus;
}
// 调用
case WM_CREATE:
hStatus = DoCreateStatusBar(hWnd, 0x1010, hInst, 4);
break;
HWND DoCreateStatusBar(HWND hwndParent, int idStatus, HINSTANCE
hinst, int cParts)
{
HWND hwndStatus;
RECT rcClient;
HLOCAL hloc;
PINT paParts;
int i, nWidth;
// Ensure that the common control DLL is loaded.
InitCommonControls();
// Create the status bar.
hwndStatus = CreateWindowEx(
0, // no extended styles
STATUSCLASSNAME, // name of status bar class
NULL, // no text when first created
SBARS_SIZEGRIP | // includes a sizing grip
WS_CHILD | WS_VISIBLE, // creates a visible child window
0, 0, 0, 0, // ignores size and position
hwndParent, // handle to parent window
(HMENU) idStatus, // child window identifier
hinst, // handle to application instance
NULL); // no window creation data
// Get the coordinates of the parent window's client area.
GetClientRect(hwndParent, &rcClient);
// Allocate an array for holding the right edge coordinates.
hloc = LocalAlloc(LHND, sizeof(int) * cParts);
paParts = (PINT) LocalLock(hloc);
// Calculate the right edge coordinate for each part, and
// copy the coordinates to the array.
nWidth = rcClient.right / cParts;
for (i = 0; i < cParts; i++) {
paParts[i] = nWidth;
nWidth += nWidth;
}
// Tell the status bar to create the window parts.
SendMessage(hwndStatus, SB_SETPARTS, (WPARAM) cParts, (LPARAM)
paParts);
// Free the array, and return.
LocalUnlock(hloc);
LocalFree(hloc);
return hwndStatus;
}
// 调用
WM_CREATE:
hStatus = DoCreateStatusBar(hWnd, 0x1010, hInst, 4);
break;