|
|
1.1 ! root 1: ! 2: /******************************************************************************\ ! 3: * This is a part of the Microsoft Source Code Samples. ! 4: * Copyright (C) 1993 Microsoft Corporation. ! 5: * All rights reserved. ! 6: * This source code is only intended as a supplement to ! 7: * Microsoft Development Tools and/or WinHelp documentation. ! 8: * See these sources for detailed information regarding the ! 9: * Microsoft samples programs. ! 10: \******************************************************************************/ ! 11: ! 12: /**************************************************************************\ ! 13: * status.c - module to support the status bar. ! 14: * ! 15: * resized by main frame window. ! 16: * Title and type text may be set in display.c ! 17: * text and painting managed in this module. ! 18: \**************************************************************************/ ! 19: #define UNICODE ! 20: ! 21: #include <windows.h> ! 22: #include "uniput.h" ! 23: ! 24: ! 25: /* prototype for function to do pseudo-3D outline */ ! 26: VOID framechildwindow (HDC, HWND, HWND); ! 27: ! 28: ! 29: /* logfont for the font selected into the static windows on status bar */ ! 30: LOGFONT logfontsmall = { ! 31: UCFONTHEIGHT /2 , ! 32: UCFONTWIDTH /2, ! 33: 0 , ! 34: 0 , ! 35: 400 , ! 36: 0 , ! 37: 0 , ! 38: 0 , ! 39: UNICODE_CHARSET , ! 40: 0 , ! 41: 0 , ! 42: 2 , ! 43: 2 , ! 44: TEXT("Lucida Sans Unicode")}; ! 45: ! 46: ! 47: ! 48: HWND hwndStatic0, hwndStatic1, hwndStatic2; ! 49: ! 50: /**************************************************************************\ ! 51: * ! 52: * function: StatusWndProc() ! 53: * ! 54: * input parameters: normal window procedure parameters. ! 55: * ! 56: * global variables: ! 57: \**************************************************************************/ ! 58: LRESULT CALLBACK StatusWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) ! 59: { ! 60: static HFONT hfontStatic; ! 61: RECT rect, clientrect; ! 62: ! 63: ! 64: switch (message) { ! 65: ! 66: /**********************************************************************\ ! 67: * WM_CREATE ! 68: * ! 69: * Create two static child windows, and select a font for them. ! 70: \**********************************************************************/ ! 71: case WM_CREATE: { ! 72: GetClientRect (hwnd, &clientrect); ! 73: ! 74: hwndStatic0 = CreateWindow( ! 75: TEXT("STATIC"), ! 76: TEXT("Target Window"), ! 77: WS_CHILD | WS_VISIBLE | SS_CENTER, ! 78: 0,0,0,0, ! 79: hwnd, NULL, hInst, 0); ! 80: ! 81: hwndStatic1 = CreateWindow( ! 82: TEXT("STATIC"), ! 83: TEXT("Unicode/Ansi"), ! 84: WS_CHILD | WS_VISIBLE | SS_CENTER, ! 85: 0,0,0,0, ! 86: hwnd, NULL, hInst, 0); ! 87: ! 88: hwndStatic2 = CreateWindow( ! 89: TEXT("STATIC"), ! 90: TEXT(""), ! 91: WS_CHILD | WS_VISIBLE | SS_RIGHT, ! 92: 0,0,0,0, ! 93: hwnd, NULL, hInst, 0); ! 94: ! 95: ! 96: hfontStatic = CreateFontIndirect (&logfontsmall); ! 97: SendMessage (hwndStatic0, WM_SETFONT, (WPARAM) hfontStatic, 0); ! 98: SendMessage (hwndStatic1, WM_SETFONT, (WPARAM) hfontStatic, 0); ! 99: SendMessage (hwndStatic2, WM_SETFONT, (WPARAM) hfontStatic, 0); ! 100: } break; ! 101: ! 102: ! 103: /**********************************************************************\ ! 104: * WM_DESTROY ! 105: * ! 106: * free the font we created at WM_CREATE time. ! 107: * hwndStatic* child windows are destroyed automatically. ! 108: \**********************************************************************/ ! 109: case WM_DESTROY: ! 110: DeleteObject (hfontStatic); ! 111: break; ! 112: ! 113: ! 114: /**********************************************************************\ ! 115: * WM_CTLCOLORSTATIC ! 116: \**********************************************************************/ ! 117: case WM_CTLCOLORSTATIC: { ! 118: HDC hdc; ! 119: ! 120: hdc = (HDC) wParam; ! 121: SetBkMode (hdc, TRANSPARENT); ! 122: return (LRESULT)GetStockObject (LTGRAY_BRUSH); ! 123: } break; ! 124: ! 125: ! 126: /**********************************************************************\ ! 127: * WM_SIZE ! 128: * ! 129: * Resize the static controls to stretch them to always fill the status ! 130: * bar minus some border area. ! 131: \**********************************************************************/ ! 132: case WM_SIZE: { ! 133: GetClientRect (hwnd, &clientrect); ! 134: rect.top = clientrect.top + SBORDER; ! 135: rect.bottom = clientrect.bottom - SBORDER; ! 136: ! 137: rect.left = SBORDER; ! 138: rect.right = rect.left + SFIELD0; ! 139: ! 140: SetWindowPos (hwndStatic0, HWND_TOP, ! 141: rect.left, ! 142: rect.top, ! 143: rect.right - rect.left, ! 144: rect.bottom - rect.top, 0); ! 145: ! 146: ! 147: rect.left = 3*SBORDER + SFIELD0; ! 148: rect.right = rect.left + SFIELD1; ! 149: ! 150: SetWindowPos (hwndStatic1, HWND_TOP, ! 151: rect.left, ! 152: rect.top, ! 153: rect.right - rect.left, ! 154: rect.bottom - rect.top, 0); ! 155: ! 156: rect.left = 5*SBORDER + SFIELD0 + SFIELD1; ! 157: rect.right = clientrect.right - SBORDER; ! 158: ! 159: SetWindowPos (hwndStatic2, HWND_TOP, ! 160: rect.left, ! 161: rect.top, ! 162: rect.right - rect.left, ! 163: rect.bottom - rect.top, 0); ! 164: ! 165: return TRUE; ! 166: } break; ! 167: ! 168: ! 169: ! 170: ! 171: /**********************************************************************\ ! 172: * WMU_SETTARGETNAME ! 173: * ! 174: * wParam - BOOL... TRUE: hwndTarget is unicode, FALSE: ansi ! 175: * lParam - pointer to new string. ! 176: * ! 177: \**********************************************************************/ ! 178: case WMU_SETTARGETNAME: ! 179: ! 180: SetWindowText (hwndStatic0,(LPCTSTR) lParam); ! 181: ! 182: if (wParam == FALSE) ! 183: SetWindowText (hwndStatic1,TEXT ("Ansi")); ! 184: else ! 185: SetWindowText (hwndStatic1,TEXT ("Unicode")); ! 186: ! 187: break; ! 188: ! 189: ! 190: #define MAXCHARS 255 ! 191: ! 192: /**********************************************************************\ ! 193: * WMU_CHARACTER ! 194: * ! 195: * wParam - WCHAR value ! 196: * ! 197: * Display a string of characters in the second static window. This is ! 198: * a FIFO buffer, if we fill it, shift characters to the left, and ! 199: * set the string back into the static control. ! 200: * ! 201: \**********************************************************************/ ! 202: case WMU_CHARACTER: { ! 203: TCHAR buffer[MAXCHARS+1]; ! 204: int nchar; ! 205: int i; ! 206: ! 207: GetWindowText (hwndStatic2,buffer, MAXCHARS+1); ! 208: nchar = GetWindowTextLength (hwndStatic2); ! 209: ! 210: if (nchar >= MAXCHARS) { ! 211: nchar = MAXCHARS-1; ! 212: for (i= 0; i<(MAXCHARS-1); i++) ! 213: buffer[i] = buffer[i+1]; ! 214: } ! 215: ! 216: buffer[nchar] = (TCHAR) wParam; ! 217: buffer[nchar+1] = (TCHAR) '\000'; ! 218: ! 219: SetWindowText (hwndStatic2,buffer); ! 220: ! 221: } break; ! 222: ! 223: ! 224: ! 225: /**********************************************************************\ ! 226: * WM_PAINT ! 227: * ! 228: * Gray background is done automatically, just outline the two static ! 229: * text windows with 3-D effect. ! 230: \**********************************************************************/ ! 231: case WM_PAINT: { ! 232: HDC hdc; ! 233: PAINTSTRUCT ps; ! 234: ! 235: hdc = BeginPaint(hwnd, &ps); ! 236: ! 237: framechildwindow (hdc,hwnd, hwndStatic0); ! 238: framechildwindow (hdc,hwnd, hwndStatic1); ! 239: framechildwindow (hdc,hwnd, hwndStatic2); ! 240: ! 241: EndPaint (hwnd, &ps); ! 242: } return FALSE; /* end WM_PAINT */ ! 243: ! 244: } /* end switch */ ! 245: return (DefWindowProc(hwnd, message, wParam, lParam)); ! 246: } ! 247: ! 248: ! 249: ! 250: /**************************************************************************\ ! 251: * ! 252: * function: framechildwindow() ! 253: * ! 254: * Simply draw a 3D frame around child window. ! 255: * ! 256: \**************************************************************************/ ! 257: VOID framechildwindow (HDC hdc, HWND hwndParent, HWND hwndChild) ! 258: { ! 259: RECT rect; ! 260: ! 261: GetWindowRect (hwndChild, &rect); ! 262: ! 263: /* minor hack... assumes RECT is two points, right field starting first */ ! 264: ScreenToClient (hwndParent, (LPPOINT)&rect); ! 265: ScreenToClient (hwndParent, (LPPOINT)&(rect.right)); ! 266: ! 267: InflateRect (&rect, 1, 1); ! 268: FrameRect (hdc, &rect, GetStockObject (GRAY_BRUSH)); ! 269: InflateRect (&rect, -1, -1); ! 270: SelectObject (hdc, GetStockObject (WHITE_PEN)); ! 271: MoveToEx (hdc, rect.right, rect.top, NULL); ! 272: LineTo (hdc,rect.right, rect.bottom); ! 273: LineTo (hdc,rect.left, rect.bottom); ! 274: ! 275: return; ! 276: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.