|
|
1.1 ! root 1: /************************************************************************* ! 2: ** ! 3: ** OLE 2.0 Sample Code ! 4: ** ! 5: ** status.c ! 6: ** ! 7: ** This file contains the window handlers, and various initialization ! 8: ** and utility functions for an application status bar. ! 9: ** ! 10: ** (c) Copyright Microsoft Corp. 1992 - 1993 All Rights Reserved ! 11: ** ! 12: *************************************************************************/ ! 13: ! 14: // Application specific include files ! 15: #include "outline.h" ! 16: #include "message.h" ! 17: #include "status.h" ! 18: ! 19: // Current status message. ! 20: static char *szStatusMessage = NULL; ! 21: ! 22: // Holder for string messages. ! 23: static char szMessageHold[MAX_MESSAGE]; ! 24: ! 25: // Window proc for status window. ! 26: LRESULT FAR PASCAL StatusWndProc ! 27: (HWND hwnd, unsigned message, WPARAM wParam, LPARAM lParam); ! 28: ! 29: // List of all constant messages. ! 30: static STATMESG ControlList[2] = ! 31: { ! 32: { STATUS_READY, "Ready." }, ! 33: { STATUS_BLANK, " " } ! 34: }; ! 35: ! 36: // List of all system menu messages. ! 37: static STATMESG SysMenuList[16] = ! 38: { ! 39: { SC_SIZE, "Change the size of the window." }, ! 40: { SC_MOVE, "Move the window." }, ! 41: { SC_MINIMIZE, "Make the window iconic." }, ! 42: { SC_MAXIMIZE, "Make the window the size of the screen." }, ! 43: { SC_NEXTWINDOW, "Activate the next window." }, ! 44: { SC_PREVWINDOW, "Activate the previous window." }, ! 45: { SC_CLOSE, "Close this window." }, ! 46: { SC_VSCROLL, "Vertical scroll?" }, ! 47: { SC_HSCROLL, "Horizontal scroll?" }, ! 48: { SC_MOUSEMENU, "A menu for mice." }, ! 49: { SC_KEYMENU, "A menu for keys (I guess)." }, ! 50: { SC_ARRANGE, "Arrange something." }, ! 51: { SC_RESTORE, "Make the window noramally sized." }, ! 52: { SC_TASKLIST, "Put up the task list dialog." }, ! 53: { SC_SCREENSAVE, "Save the screen! Run for your life!" }, ! 54: { SC_HOTKEY, "Boy, is this key hot!" } ! 55: }; ! 56: ! 57: // Message type for popup messages. ! 58: typedef struct { ! 59: HMENU hmenu; ! 60: char string[MAX_MESSAGE]; ! 61: } STATPOPUP; ! 62: ! 63: // List of all popup messages. ! 64: static STATPOPUP PopupList[NUM_POPUP]; ! 65: ! 66: static UINT nCurrentPopup = 0; ! 67: ! 68: ! 69: ! 70: /* RegisterStatusClass ! 71: * ------------------- ! 72: * ! 73: * Creates classes for status window. ! 74: * ! 75: * HINSTANCE hInstance ! 76: * ! 77: * RETURNS: TRUE if class successfully registered. ! 78: * FALSE otherwise. ! 79: * ! 80: * CUSTOMIZATION: Change class name. ! 81: * ! 82: */ ! 83: BOOL RegisterStatusClass(HINSTANCE hInstance) ! 84: { ! 85: WNDCLASS wc; ! 86: ! 87: wc.lpszClassName = "ObjStatus"; ! 88: wc.lpfnWndProc = StatusWndProc; ! 89: wc.style = 0; ! 90: wc.hInstance = hInstance; ! 91: wc.hIcon = NULL; ! 92: wc.cbClsExtra = 4; ! 93: wc.cbWndExtra = 0; ! 94: wc.lpszMenuName = NULL; ! 95: wc.hCursor = LoadCursor(NULL, IDC_ARROW); ! 96: wc.hbrBackground = GetStockObject(LTGRAY_BRUSH); ! 97: ! 98: if (!RegisterClass(&wc)) ! 99: return FALSE; ! 100: ! 101: return TRUE; ! 102: } ! 103: ! 104: ! 105: /* CreateStatusWindow ! 106: * ------------------ ! 107: * ! 108: * Creates status window. ! 109: * ! 110: * HWND hwndMain ! 111: * ! 112: * RETURNS: HWND of status window if creation is successful. ! 113: * NULL otherwise. ! 114: * ! 115: * CUSTOMIZATION: Change class name. ! 116: * ! 117: */ ! 118: HWND CreateStatusWindow(HWND hWndApp, HINSTANCE hInst) ! 119: { ! 120: RECT rect; ! 121: int width, height; ! 122: HWND hWndStatusBar; ! 123: ! 124: szStatusMessage = ControlList[0].string; ! 125: GetClientRect(hWndApp, &rect); ! 126: width = rect.right - rect.left; ! 127: height = rect.bottom - rect.top; ! 128: ! 129: hWndStatusBar = CreateWindow ( ! 130: "ObjStatus", ! 131: "SvrStatus", ! 132: WS_CHILD | WS_VISIBLE, ! 133: 0, height - STATUS_HEIGHT, ! 134: width, ! 135: STATUS_HEIGHT, ! 136: hWndApp, ! 137: NULL, ! 138: hInst, ! 139: NULL ! 140: ); ! 141: ! 142: return hWndStatusBar; ! 143: } ! 144: ! 145: ! 146: /* DestroyStatusWindow ! 147: * ------------------- ! 148: * ! 149: * Destroys status window. ! 150: * ! 151: * CUSTOMIZATION: None. ! 152: * ! 153: */ ! 154: void DestroyStatusWindow(HWND hWndStatusBar) ! 155: { ! 156: DestroyWindow(hWndStatusBar); ! 157: } ! 158: ! 159: ! 160: /* AssignPopupMessage ! 161: * ------------------ ! 162: * ! 163: * Associates a string with a popup menu handle. ! 164: * ! 165: * HMENU hmenuPopup ! 166: * char *szMessage ! 167: * ! 168: * CUSTOMIZATION: None. ! 169: * ! 170: */ ! 171: void AssignPopupMessage(HMENU hmenuPopup, char *szMessage) ! 172: { ! 173: if (nCurrentPopup < NUM_POPUP) { ! 174: PopupList[nCurrentPopup].hmenu = hmenuPopup; ! 175: lstrcpy(PopupList[nCurrentPopup].string, szMessage); ! 176: ++nCurrentPopup; ! 177: } ! 178: } ! 179: ! 180: static void WriteStatusMessage(HWND hWndStatusBar, LPVOID lpDoc) ! 181: { ! 182: #if defined( INPLACE_LATER ) ! 183: if (lpDoc && lpDoc->lpIpData != NULL) { ! 184: lpDoc->lpIpData->lpFrame->lpVtbl->SetStatusText ! 185: (lpDoc->lpIpData->lpFrame, szStatusMessage); ! 186: } ! 187: else ! 188: #endif ! 189: { ! 190: InvalidateRect (hWndStatusBar, (LPRECT)NULL, TRUE); ! 191: UpdateWindow (hWndStatusBar); ! 192: } ! 193: } ! 194: ! 195: /* ItemMessage ! 196: * ----------- ! 197: * ! 198: * Prints message associated with the given item number. ! 199: * ! 200: * UINT wIDItem ! 201: * LPVOID lpDoc ! 202: * ! 203: * CUSTOMIZATION: None. ! 204: * ! 205: */ ! 206: void ItemMessage(HWND hWndStatusBar, UINT wIDItem, LPVOID lpDoc) ! 207: { ! 208: UINT i; ! 209: ! 210: szStatusMessage = ControlList[1].string; ! 211: for (i = 0; i < NUM_STATS; ++i) { ! 212: if (wIDItem == MesgList[i].wIDItem) { ! 213: szStatusMessage = MesgList[i].string; ! 214: break; ! 215: } ! 216: } ! 217: WriteStatusMessage(hWndStatusBar, lpDoc); ! 218: } ! 219: ! 220: ! 221: /* PopupMessage ! 222: * ------------ ! 223: * ! 224: * Prints message associated with the given popup menu. ! 225: * ! 226: * HMENU hmenuPopup ! 227: * LPVOID lpDoc ! 228: * ! 229: * CUSTOMIZATION: None. ! 230: * ! 231: */ ! 232: void PopupMessage(HWND hWndStatusBar, HMENU hmenuPopup, LPVOID lpDoc) ! 233: { ! 234: UINT i; ! 235: ! 236: szStatusMessage = ControlList[1].string; ! 237: for (i = 0; i < nCurrentPopup; ++i) { ! 238: if (hmenuPopup == PopupList[i].hmenu) { ! 239: szStatusMessage = PopupList[i].string; ! 240: break; ! 241: } ! 242: } ! 243: WriteStatusMessage(hWndStatusBar, lpDoc); ! 244: } ! 245: ! 246: ! 247: /* SysMenuMessage ! 248: * -------------- ! 249: * ! 250: * Prints messages to correspond to items on the system menu. ! 251: * ! 252: * ! 253: * UINT wIDItem ! 254: * LPVOID lpDoc ! 255: * ! 256: * CUSTOMIZATION: None. ! 257: * ! 258: */ ! 259: void SysMenuMessage(HWND hWndStatusBar, UINT wIDItem, LPVOID lpDoc) ! 260: { ! 261: UINT i; ! 262: ! 263: szStatusMessage = ControlList[1].string; ! 264: for (i = 0; i < 16; ++i) { ! 265: if (wIDItem == SysMenuList[i].wIDItem) { ! 266: szStatusMessage = SysMenuList[i].string; ! 267: break; ! 268: } ! 269: } ! 270: WriteStatusMessage(hWndStatusBar, lpDoc); ! 271: } ! 272: ! 273: ! 274: /* ControlMessage ! 275: * -------------- ! 276: * ! 277: * Prints general system messages. ! 278: * ! 279: * ! 280: * STATCONTROL scCommand ! 281: * LPVOID lpDoc ! 282: * ! 283: * CUSTOMIZATION: Add new messages. ! 284: * ! 285: */ ! 286: void ControlMessage(HWND hWndStatusBar, STATCONTROL scCommand, LPVOID lpDoc) ! 287: { ! 288: UINT i; ! 289: ! 290: szStatusMessage = ControlList[1].string; ! 291: for (i = 0; i < 2; ++i) { ! 292: if ((UINT)scCommand == ControlList[i].wIDItem) { ! 293: szStatusMessage = ControlList[i].string; ! 294: break; ! 295: } ! 296: } ! 297: WriteStatusMessage(hWndStatusBar, lpDoc); ! 298: } ! 299: ! 300: ! 301: /* StringMessage ! 302: * ------------- ! 303: * ! 304: * Prints messages specially sent by the application. ! 305: * ! 306: * char *szMessage ! 307: * LPVOID lpDoc ! 308: * ! 309: * CUSTOMIZATION: Add new messages. ! 310: * ! 311: */ ! 312: void StringMessage(HWND hWndStatusBar, char *szMessage, LPVOID lpDoc) ! 313: { ! 314: lstrcpy(szMessageHold, szMessage); ! 315: szStatusMessage = szMessageHold; ! 316: WriteStatusMessage(hWndStatusBar, lpDoc); ! 317: } ! 318: ! 319: ! 320: ! 321: /* StatusWndProc ! 322: * ------------- ! 323: * ! 324: * Message handler for the statusbar window. ! 325: * ! 326: * ! 327: * CUSTOMIZATION: None ! 328: * ! 329: */ ! 330: LRESULT FAR PASCAL StatusWndProc ! 331: (HWND hwnd, unsigned message, WPARAM wParam, LPARAM lParam) ! 332: { ! 333: if (message == WM_PAINT) { ! 334: RECT rc; ! 335: HDC hdc; ! 336: PAINTSTRUCT paintstruct; ! 337: HPEN hpenOld; ! 338: HPEN hpen; ! 339: HFONT hfontOld; ! 340: HFONT hfont; ! 341: HPALETTE hpalOld = NULL; ! 342: POINT point; ! 343: ! 344: BeginPaint (hwnd, &paintstruct); ! 345: hdc = GetDC (hwnd); ! 346: ! 347: GetClientRect (hwnd, (LPRECT) &rc); ! 348: ! 349: hpenOld = SelectObject (hdc, GetStockObject (BLACK_PEN)); ! 350: ! 351: MoveToEx (hdc, 0, 0, &point); ! 352: LineTo (hdc, rc.right, 0); ! 353: ! 354: SelectObject (hdc, GetStockObject (WHITE_PEN)); ! 355: ! 356: MoveToEx (hdc, STATUS_RRIGHT, STATUS_RTOP, &point); ! 357: LineTo (hdc, STATUS_RRIGHT, STATUS_RBOTTOM); ! 358: LineTo (hdc, STATUS_RLEFT-1, STATUS_RBOTTOM); ! 359: ! 360: hpen = CreatePen (PS_SOLID, 1, /* DKGRAY */ 0x00808080); ! 361: SelectObject (hdc, hpen); ! 362: ! 363: MoveToEx (hdc, STATUS_RLEFT, STATUS_RBOTTOM-1, &point); ! 364: LineTo (hdc, STATUS_RLEFT, STATUS_RTOP); ! 365: LineTo (hdc, STATUS_RRIGHT, STATUS_RTOP); ! 366: ! 367: SetBkMode (hdc, TRANSPARENT); ! 368: SetTextAlign (hdc, TA_LEFT | TA_TOP); ! 369: hfont = CreateFont (STATUS_THEIGHT, 0, 0, 0, FW_NORMAL, FALSE, FALSE, ! 370: FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, ! 371: CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, ! 372: DEFAULT_PITCH | FF_DONTCARE, "MS Sans Serif"); ! 373: ! 374: hfontOld = SelectObject(hdc, hfont); ! 375: ! 376: TextOut (hdc, STATUS_TLEFT, STATUS_TTOP, ! 377: szStatusMessage, ! 378: lstrlen(szStatusMessage)); ! 379: ! 380: // Restore original objects ! 381: SelectObject (hdc, hfontOld); ! 382: SelectObject (hdc, hpenOld); ! 383: DeleteObject (hpen); ! 384: DeleteObject (hfont); ! 385: ! 386: ReleaseDC (hwnd, hdc); ! 387: EndPaint (hwnd, &paintstruct); ! 388: ! 389: return 0; ! 390: } ! 391: else { ! 392: return DefWindowProc(hwnd, message, wParam, lParam); ! 393: } ! 394: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.