Click here to Skip to main content
15,896,154 members
Articles / Programming Languages / C++

WindowsNT System Manager

Rate me:
Please Sign up or sign in to vote.
4.73/5 (8 votes)
30 Nov 19998 min read 90.3K   3.1K   40  
This article presents a comprehensive system control manager for NT
#include "SysMain.h"
#include "_GlobalVars.h"
#include "_Constants.h"
#include "_Utils.h"
#include "resource.h"

LRESULT CALLBACK 
MDIChild_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	LRESULT lResult = 0;

	switch(uMsg)
	{
		case WM_CREATE:
			MDIChild_OnCreate(hWnd, wParam, lParam, &lResult);
			break;

		case WM_SIZE:
			MDIChild_OnSize(hWnd, wParam, lParam, &lResult);
			break;

		case WM_CLOSE:
			MDIChild_OnClose(hWnd, wParam, lParam, &lResult);
			break;

		case WM_MDIACTIVATE:
			MDIChild_OnMDIActivate(hWnd, wParam, lParam, &lResult);
			break;

		case WM_DESTROY:
			MDIChild_OnDestroy(hWnd, wParam, lParam, &lResult);
			break;

		case WM_USER_REFRESH:
			MDIChild_OnRefresh(hWnd, wParam, lParam, &lResult);
			break;

		default:
			lResult = DefMDIChildProc(hWnd, uMsg, wParam, lParam);
			break;
	}

	return lResult;
}

#pragma warning(disable:4702)
LRESULT*
MDIChild_OnClose(HWND hWnd, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
{
	HWND hwndDlg = 0;
	LPSERVICEFILTER psf = 0;
	DLGPROC lpDlgProc;
		
	psf = (LPSERVICEFILTER)(GetWindowLong(hWnd, GWL_USERDATA));
	if(psf)
		SetEvent(psf->hCloseEvent);

	//	close also encapsulated dialog
	hwndDlg = (HWND)GetWindowLong(hWnd, GWLAPP_HDLG);

	lpDlgProc = (DLGPROC)GetWindowLong(hwndDlg, DWL_DLGPROC);
	FreeProcInstance(lpDlgProc);
	
	EndDialog(hwndDlg, IDOK);
	DestroyWindow(hwndDlg);

	*plResult = DefMDIChildProc(hWnd, WM_CLOSE, wParam, lParam);
	g_hWndActiveChild = (HWND)SendMessage(g_hMDIClientWnd, WM_MDIGETACTIVE, 0, 0);

	return plResult;
}

LRESULT*
MDIChild_OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
{
	HWND    hWndTemp;
	TCHAR lpszMachineName[MAX_COMPUTERNAME_LENGTH + 1];
	LPSERVICEFILTER psf = 0;
	register UINT x = 0;

	_UNREFERENCED_PARAMETER_(wParam);
	_UNREFERENCED_PARAMETER_(lParam);

	ComboBox_GetLBText(g_hComboToolbarWnd, ComboBox_GetCurSel(g_hComboToolbarWnd), lpszMachineName);

	psf = GlobalAlloc(GPTR, sizeof(SERVICEFILTER));
	if(!psf)
	{
		*plResult = 1;
		return plResult;
	}

	psf->fDevice		= g_fDevice;
	psf->fService		= g_fService;
	psf->fRunning		= g_fActive;
	psf->fPaused		= g_fPaused;
	psf->fStopped		= g_fStopped;
	psf->hCancelEvent	= 0;
	psf->hCloseEvent	= 0;
	psf->hwndProgr		= 0;
	psf->uThreadId		= 0;
	psf->hwndDlg		= 0;
	psf->hwndLV			= 0;
	_tcscpy(psf->lpszComputerName, lpszMachineName);

	g_hWndActiveChild = hWnd;
	hWndTemp = CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_MDICHILD), hWnd, MDIChild_DlgProc, (LPARAM)psf);

	if(!hWndTemp)
	{
		*plResult = -1;
		return plResult;
	}

	SetWindowLong(hWnd, GWLAPP_HDLG		, (LONG)hWndTemp);
 	SetWindowLong(hWnd, GWLAPP_TYPE		, (LONG)TypeToIntCode());
	SetWindowLong(hWnd, GWLAPP_STATUS	, (LONG)StatusToIntCode());
	SetWindowLong(hWnd, GWL_USERDATA	, (LONG)0); // has no thread (yet)

	for(x = 0; x < _tcslen(lpszMachineName); x++)
	{
		TCHAR tch = lpszMachineName[x];
		UINT  uGWLIndex = GWLAPP_MACHINE + x * sizeof(LONG);

		SetWindowLong(hWnd, uGWLIndex, (LONG)(tch)); // set associated computer name (all characters)
	}
	SetWindowLong(hWnd, GWLAPP_MACHINE + x* sizeof(LONG), (LONG)(_T('\0'))); // set NUL terminator

	ShowWindow(hWndTemp, SW_SHOW);
	UpdateWindow(hWndTemp);

	*plResult = 0;
	return plResult;
}

LRESULT *
MDIChild_OnSize(HWND hWnd, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
{
	DefMDIChildProc(hWnd, WM_SIZE, wParam, lParam);
	SendMessage((HWND)GetWindowLong(hWnd, GWLAPP_HDLG), WM_SIZE, wParam, lParam);

	*plResult = 0;
	return plResult;
}

LRESULT *
MDIChild_OnMDIActivate(HWND hWnd, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
{
	_UNREFERENCED_PARAMETER_(hWnd);
	_UNREFERENCED_PARAMETER_(wParam);
	_UNREFERENCED_PARAMETER_(lParam);

	g_hWndActiveChild = (HWND)SendMessage(g_hMDIClientWnd, WM_MDIGETACTIVE, 0, 0);

	SendMessage(g_hStatusBarWnd, SB_SETICON, (WPARAM)(INT)1, (LPARAM)hControllerIconI);
	SendMessage(g_hStatusBarWnd, SB_SETICON, (WPARAM)(INT)2, (LPARAM)hLegendIconI);

	*plResult = 0;
	return plResult;
}

#pragma warning(disable:4702)
LRESULT *
MDIChild_OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
{
	_UNREFERENCED_PARAMETER_(wParam);
	_UNREFERENCED_PARAMETER_(lParam);

	if(hWnd == g_hWndActiveChild)
		g_hWndActiveChild = (HWND)0;

	*plResult = 0;
	return plResult;
}

#pragma warning(disable:4702)
LRESULT*
MDIChild_OnRefresh(HWND hWnd, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
{
	TCHAR lpszMachineName[_MAX_PATH + 1];
	LONG lWndLong;
	register UINT x;

	LPSERVICEFILTER psf = 0;

	_UNREFERENCED_PARAMETER_(wParam);
	_UNREFERENCED_PARAMETER_(lParam);

	for(x = 0; x < MAX_COMPUTERNAME_LENGTH + 1; x++)
	{
		lWndLong = GetWindowLong(g_hWndActiveChild, GWLAPP_MACHINE + x * sizeof(LONG));
		lpszMachineName[x] = (TCHAR)lWndLong;
	}

	psf = GlobalAlloc(GPTR, sizeof(SERVICEFILTER));
	if(!psf)
	{
		*plResult = 1;
		return plResult;
	}

	psf->fDevice		= g_fDevice;
	psf->fService		= g_fService;
	psf->fRunning		= g_fActive;
	psf->fPaused		= g_fPaused;
	psf->fStopped		= g_fStopped;
	psf->hCancelEvent	= 0;
	psf->hCloseEvent	= 0;
	psf->hwndProgr		= 0;
	psf->uThreadId		= 0;
	psf->hwndDlg		= 0;
	psf->hwndLV			= 0;
	_tcscpy(psf->lpszComputerName, lpszMachineName);

	*plResult = SendMessage((HWND)GetWindowLong(hWnd, GWLAPP_HDLG), WM_USER_REFRESH, 0, (LPARAM)psf);
	return plResult;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions