Minor updates, added status bar support from TaskMgr.

svn path=/trunk/; revision=3171
This commit is contained in:
Robert Dickenson 2002-07-02 17:37:20 +00:00
parent 06560b36fd
commit a13ca47ccb
2 changed files with 245 additions and 125 deletions

View file

@ -15,6 +15,7 @@
// Windows Header Files: // Windows Header Files:
#include <windows.h> #include <windows.h>
#include <commctrl.h>
// C RunTime Header Files // C RunTime Header Files
#include <stdlib.h> #include <stdlib.h>

View file

@ -20,16 +20,42 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#ifdef _MSC_VER
#include "stdafx.h" #include "stdafx.h"
#else
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <commctrl.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <process.h>
#include <stdio.h>
#endif
#include "resource.h" #include "resource.h"
#include <shellapi.h> #include <shellapi.h>
//#include <winspool.h> //#include <winspool.h>
#define STATUS_WINDOW 2001
#define MAX_LOADSTRING 100 #define MAX_LOADSTRING 100
// Global Variables: // Global Variables:
HWND hMainWnd;
HINSTANCE hInst; // current instance HINSTANCE hInst; // current instance
HWND hMainWnd; // Main Window
HWND hStatusWnd; // Status Bar Window
HWND hTabWnd; // Tab Control Window
int nMinimumWidth; // Minimum width of the dialog (OnSize()'s cx)
int nMinimumHeight; // Minimum height of the dialog (OnSize()'s cy)
int nOldWidth; // Holds the previous client area width
int nOldHeight; // Holds the previous client area height
BOOL bInMenuLoop = FALSE; // Tells us if we are in the menu loop
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
TCHAR szFrameClass[MAX_LOADSTRING]; // The title bar text TCHAR szFrameClass[MAX_LOADSTRING]; // The title bar text
@ -47,7 +73,6 @@ int APIENTRY WinMain(HINSTANCE hInstance,
LPSTR lpCmdLine, LPSTR lpCmdLine,
int nCmdShow) int nCmdShow)
{ {
// TODO: Place code here.
MSG msg; MSG msg;
HACCEL hAccelTable; HACCEL hAccelTable;
@ -60,23 +85,18 @@ int APIENTRY WinMain(HINSTANCE hInstance,
MyRegisterClass2(hInstance); MyRegisterClass2(hInstance);
// Perform application initialization: // Perform application initialization:
if (!InitInstance (hInstance, nCmdShow)) if (!InitInstance(hInstance, nCmdShow)) {
{
return FALSE; return FALSE;
} }
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDT32); hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDT32);
// Main message loop: // Main message loop:
while (GetMessage(&msg, NULL, 0, 0)) while (GetMessage(&msg, NULL, 0, 0)) {
{ if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
} }
} }
return msg.wParam; return msg.wParam;
} }
@ -100,7 +120,6 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
WNDCLASSEX wcex; WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX); wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0; wcex.cbClsExtra = 0;
@ -122,7 +141,6 @@ ATOM MyRegisterClass2(HINSTANCE hInstance)
WNDCLASSEX wcex; WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX); wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)FrameWndProc; wcex.lpfnWndProc = (WNDPROC)FrameWndProc;
wcex.cbClsExtra = 0; wcex.cbClsExtra = 0;
@ -135,7 +153,6 @@ ATOM MyRegisterClass2(HINSTANCE hInstance)
// wcex.lpszMenuName = (LPCSTR)IDR_REGEDT32_MENU; // wcex.lpszMenuName = (LPCSTR)IDR_REGEDT32_MENU;
wcex.lpszClassName = szFrameClass; wcex.lpszClassName = szFrameClass;
wcex.hIconSm = LoadIcon((HINSTANCE)wcex.hInstance, (LPCTSTR)IDI_SMALL); wcex.hIconSm = LoadIcon((HINSTANCE)wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex); return RegisterClassEx(&wcex);
} }
@ -152,26 +169,119 @@ ATOM MyRegisterClass2(HINSTANCE hInstance)
// //
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{ {
HWND hWnd; int nParts[3];
// Initialize the Windows Common Controls DLL
InitCommonControls();
hInst = hInstance; // Store instance handle in our global variable hInst = hInstance; // Store instance handle in our global variable
hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hMainWnd) {
if (!hWnd)
{
return FALSE; return FALSE;
} }
hMainWnd = hWnd;
ShowWindow(hWnd, nCmdShow); // Get the minimum window sizes
UpdateWindow(hWnd); // GetWindowRect(hMainWnd, &rc);
// nMinimumWidth = (rc.right - rc.left);
// nMinimumHeight = (rc.bottom - rc.top);
// Create the status bar
hStatusWnd = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
"", hMainWnd, STATUS_WINDOW);
if (!hStatusWnd)
return FALSE;
// Create the status bar panes
nParts[0] = 100;
nParts[1] = 210;
nParts[2] = 400;
SendMessage(hStatusWnd, SB_SETPARTS, 3, (long)nParts);
ShowWindow(hMainWnd, nCmdShow);
UpdateWindow(hMainWnd);
return TRUE; return TRUE;
} }
// OnSize()
// This function handles all the sizing events for the application
// It re-sizes every window, and child window that needs re-sizing
void OnSize(UINT nType, int cx, int cy)
{
int nParts[3];
int nXDifference;
int nYDifference;
RECT rc;
if (nType == SIZE_MINIMIZED)
return;
nXDifference = cx - nOldWidth;
nYDifference = cy - nOldHeight;
nOldWidth = cx;
nOldHeight = cy;
// Update the status bar size
GetWindowRect(hStatusWnd, &rc);
SendMessage(hStatusWnd, WM_SIZE, nType, MAKELPARAM(cx, cy + (rc.bottom - rc.top)));
// Update the status bar pane sizes
nParts[0] = bInMenuLoop ? -1 : 100;
nParts[1] = 210;
nParts[2] = cx;
SendMessage(hStatusWnd, SB_SETPARTS, bInMenuLoop ? 1 : 3, (long)nParts);
}
void OnEnterMenuLoop(HWND hWnd)
{
int nParts;
// Update the status bar pane sizes
nParts = -1;
SendMessage(hStatusWnd, SB_SETPARTS, 1, (long)&nParts);
bInMenuLoop = TRUE;
SendMessage(hStatusWnd, SB_SETTEXT, (WPARAM)0, (LPARAM)_T(""));
}
void OnExitMenuLoop(HWND hWnd)
{
RECT rc;
int nParts[3];
TCHAR text[260];
bInMenuLoop = FALSE;
// Update the status bar pane sizes
GetClientRect(hWnd, &rc);
nParts[0] = 100;
nParts[1] = 210;
nParts[2] = rc.right;
SendMessage(hStatusWnd, SB_SETPARTS, 3, (long)nParts);
SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)_T(""));
// wsprintf(text, _T("CPU Usage: %3d%%"), PerfDataGetProcessorUsage());
// SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text);
// wsprintf(text, _T("Processes: %d"), PerfDataGetProcessCount());
// SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text);
}
void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
{
TCHAR str[100];
strcpy(str, TEXT(""));
if (LoadString(hInst, nItemID, str, 100)) {
// load appropriate string
LPTSTR lpsz = str;
// first newline terminates actual string
lpsz = _tcschr(lpsz, '\n');
if (lpsz != NULL)
*lpsz = '\0';
}
SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)str);
}
LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
int wmId, wmEvent; int wmId, wmEvent;
@ -180,14 +290,12 @@ LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
TCHAR szHello[MAX_LOADSTRING]; TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message) switch (message) {
{
case WM_COMMAND: case WM_COMMAND:
wmId = LOWORD(wParam); wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam); wmEvent = HIWORD(wParam);
// Parse the menu selections: // Parse the menu selections:
switch (wmId) switch (wmId) {
{
case IDM_ABOUT: case IDM_ABOUT:
// DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); // DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
{ {
@ -239,14 +347,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
//TCHAR szHello[MAX_LOADSTRING]; //TCHAR szHello[MAX_LOADSTRING];
//LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); //LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message) switch (message) {
{
case WM_COMMAND: case WM_COMMAND:
wmId = LOWORD(wParam); wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam); wmEvent = HIWORD(wParam);
// Parse the menu selections: // Parse the menu selections:
switch (wmId) switch (wmId) {
{
case ID_REGISTRY_PRINTERSETUP: case ID_REGISTRY_PRINTERSETUP:
//PRINTDLG pd; //PRINTDLG pd;
//PrintDlg(&pd); //PrintDlg(&pd);
@ -281,6 +387,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return DefWindowProc(hWnd, message, wParam, lParam); return DefWindowProc(hWnd, message, wParam, lParam);
} }
break; break;
case WM_SIZE:
// Handle the window sizing in it's own function
OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
break;
case WM_PAINT: case WM_PAINT:
hdc = BeginPaint(hWnd, &ps); hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here... // TODO: Add any drawing code here...
@ -292,6 +402,18 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_DESTROY: case WM_DESTROY:
PostQuitMessage(0); PostQuitMessage(0);
break; break;
case WM_TIMER:
break;
case WM_ENTERMENULOOP:
OnEnterMenuLoop(hWnd);
break;
case WM_EXITMENULOOP:
OnExitMenuLoop(hWnd);
break;
case WM_MENUSELECT:
OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
break;
default: default:
return DefWindowProc(hWnd, message, wParam, lParam); return DefWindowProc(hWnd, message, wParam, lParam);
} }
@ -301,14 +423,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// Mesage handler for about box. // Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{ {
switch (message) switch (message) {
{
case WM_INITDIALOG: case WM_INITDIALOG:
return TRUE; return TRUE;
case WM_COMMAND: case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
{
EndDialog(hDlg, LOWORD(wParam)); EndDialog(hDlg, LOWORD(wParam));
return TRUE; return TRUE;
} }