Posted to tcl by kostix at Tue Oct 23 22:16:42 GMT 2007view pretty

static int
CreateMonitorWindow (
	Tcl_Interp *interp,
	Winpm_InterpData *statePtr)
{
	CONST TCHAR name[]  = _T("TkWinPMMonitorWindow");
	CONST TCHAR titlePfx[] = _T("TkWinPMMonitorWindow");

	HINSTANCE   hinst;
	WNDCLASSEX  wc;
	ATOM        rc;
	TCHAR       title[256];
	HWND        hwnd;

	hinst = Tk_GetHINSTANCE();

	if (!globalState.classRegistered) {
		memset(&wc, 0, sizeof(wc));
		
		wc.cbSize        = sizeof(WNDCLASSEX);
		wc.style         = CS_HREDRAW | CS_VREDRAW;
		wc.lpfnWndProc   = (WNDPROC) WndProc;
		wc.cbClsExtra    = 0;
		wc.cbWndExtra    = 0;
		wc.hInstance     = hinst;
		wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
		wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
		wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
		wc.hbrBackground = (HBRUSH) COLOR_WINDOW;
		wc.lpszMenuName  = name;
		wc.lpszClassName = name;

		rc = RegisterClassEx(&wc);
		if (rc == 0) {
			Tcl_ResetResult(interp);
			AppendSystemError(interp, GetLastError());
			return TCL_ERROR;
		}

		globalState.classRegistered = 1;
	}

	_tcscpy(title, titlePfx);
	if (globalState.instances >= 1) {
		_stprintf(title + _tcslen(title),
				_T(" #%d"), globalState.instances);
	}

	hwnd = CreateWindow(name, title, WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
		NULL, NULL, hinst, NULL);
	if (hwnd == NULL) {
		Tcl_ResetResult(interp);
		AppendSystemError(interp, GetLastError());
		return TCL_ERROR;
	}

	SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG)statePtr);

	ShowWindow(hwnd, SW_HIDE);
	UpdateWindow(hwnd);

	statePtr->hwndMonitor = hwnd;

	return TCL_OK;
}