|
|
1.1 ! root 1: #define NOCOMM ! 2: #include "cardfile.h" ! 3: ! 4: ! 5: /*********************************************************************/ ! 6: /* Windows/PM Cardfile Shared Code */ ! 7: /* */ ! 8: /* (c) Copyright Microsoft Corp. 1987,1988 - All Rights Reserved */ ! 9: /*********************************************************************/ ! 10: ! 11: /*********************************************************************/ ! 12: /* The following shared code was developed from the original */ ! 13: /* Cardfile application. This code can be compiled to run under */ ! 14: /* either the Windows or the PM manager environment. All */ ! 15: /* functionality associated with bitmaps or printing has been */ ! 16: /* deleted. Some comments refering to these functions may still be */ ! 17: /* present in the code and should be disregarded. jw. */ ! 18: /*********************************************************************/ ! 19: ! 20: ! 21: ! 22: /*********************************************************************/ ! 23: /* GetOldData - ! 24: /* Gets data from a previous instance. This routine is only ! 25: /* applicable in Windows. ! 26: /*********************************************************************/ ! 27: ! 28: void FAR GetOldData(hInstance) ! 29: HINST hInstance; ! 30: { ! 31: GetInstanceData(hInstance, (PSTR)&hbrWhite, 2); ! 32: GetInstanceData(hInstance, (PSTR)&hbrBlack, 2); ! 33: GetInstanceData(hInstance, (PSTR)&hbrGray, 2); ! 34: GetInstanceData(hInstance, (PSTR)&hbrLine, 2); ! 35: GetInstanceData(hInstance, (PSTR)&hbrBack, 2); ! 36: GetInstanceData(hInstance, (PSTR)&CharFixHeight, 2); ! 37: GetInstanceData(hInstance, (PSTR)&CharFixWidth, 2); ! 38: GetInstanceData(hInstance, (PSTR)&ySpacing, 2); ! 39: GetInstanceData(hInstance, (PSTR)&CardWidth, 2); ! 40: GetInstanceData(hInstance, (PSTR)&CardHeight, 2); ! 41: GetInstanceData(hInstance, (PSTR)&hAccel, 2); ! 42: } ! 43: ! 44: ! 45: /*********************************************************************/ ! 46: /* InitInstance - */ ! 47: /* Performs initialization for each instance, i.e., loads */ ! 48: /* resources, creates windows, ... */ ! 49: /* */ ! 50: /* Different in Windows and PM. */ ! 51: /*********************************************************************/ ! 52: ! 53: BOOL FAR InitInstance(hInstance, lpszCommandLine, cmdShow) ! 54: HINST hInstance; ! 55: LPSTR lpszCommandLine; ! 56: int cmdShow; ! 57: { ! 58: int i; ! 59: LPCARDHEADER lpCards; ! 60: HWND hwnd = NULL; ! 61: LPSTR lpchTmp; ! 62: PSTR pchTmp; ! 63: FARPROC lpCardWndProc; ! 64: char buf[3]; ! 65: RECT rect; ! 66: #ifndef IN_WINDOWS ! 67: ULONG ctlData; ! 68: #endif ! 69: ! 70: /* get resident strings */ ! 71: LoadString(hInstance, IDS_EINSMEMORY, (LPSTR)NotEnoughMem, 50); ! 72: LoadString(hInstance, IDS_UNTITLED, (LPSTR)rgchUntitled, 30); ! 73: LoadString(hInstance, IDS_CARDDATA, (LPSTR)rgchCardData, 40); ! 74: LoadString(hInstance, IDS_STRINGINSERT, (LPSTR)buf, 3); ! 75: if (!LoadString(hInstance, IDS_CARDFILE, (LPSTR)rgchCardfile, 40)) ! 76: goto InitError; ! 77: ! 78: /* this is used in MergeStrings */ ! 79: wMerge = *(unsigned *)buf; ! 80: ! 81: /* make ProcInstances for all dialog procedures, and for the */ ! 82: /* filter proc for the edit control */ ! 83: lpDlgProc = MakeProcInstance( DlgProc, hInstance ); ! 84: lpfnOpen = MakeProcInstance( fnOpen, hInstance ); ! 85: lpfnSave = MakeProcInstance( fnSave, hInstance ); ! 86: lpfnAbout = MakeProcInstance( fnAbout, hInstance ); ! 87: lpCardWndProc = MakeProcInstance( (FARPROC) CardWndProc, hInstance); ! 88: ! 89: /* unlikely that last one will work but others won't */ ! 90: if (!lpCardWndProc) ! 91: goto InitError; ! 92: ! 93: /* allocate the basic data structure for storing the card headers */ ! 94: hCards = GlobalAlloc(GHND, ! 95: (long)sizeof(CARDHEADER)); /* alloc first card */ ! 96: ! 97: if (!hCards) ! 98: goto InitError; ! 99: ! 100: /* make a single blank card */ ! 101: CurIFile[0] = 0; /* file is untitled */ ! 102: cCards = 1; ! 103: CurCardHead.line[0] = 0; ! 104: CurCard.hBitmap = 0; ! 105: CurCardHead.flags = FNEW; ! 106: lpCards = (LPCARDHEADER)GlobalLock(hCards); ! 107: *lpCards = CurCardHead; ! 108: GlobalUnlock(hCards); ! 109: ! 110: /* Note: PM mapping for CreateWindow is only */ ! 111: /* applicable for the main window */ ! 112: ! 113: /* create the Cardfile window */ ! 114: hwnd = CreateWindow( ! 115: (LPSTR) rgchCardfileClass, ! 116: (LPSTR) "", ! 117: WS_TILEDWINDOW | WS_HSCROLL | WS_VSCROLL, ! 118: 0, 0, 0, 100, ! 119: NULL, NULL, ! 120: hInstance, ! 121: (LPSTR)NULL); ! 122: ! 123: if (!hwnd) ! 124: goto InitError; ! 125: ! 126: /* Since the CreateWindow mapping is only applicable for the main */ ! 127: /* window, separate compilation must be used. */ ! 128: ! 129: #ifdef IN_WINDOWS ! 130: /* create the edit control window */ ! 131: hCardWnd = CreateWindow( ! 132: (LPSTR)"Edit", ! 133: (LPSTR)"", ! 134: WS_CHILD | WS_VISIBLE | ES_MULTILINE, ! 135: 0, 0, 0, 0, ! 136: hwnd, ! 137: IDM_EDITWINDOW, ! 138: hInstance, ! 139: (LPSTR)NULL); ! 140: #else ! 141: /* Before creating child, make sure main window is updated. */ ! 142: WinUpdateWindow( FRAME(hwnd) ); ! 143: ! 144: hCardWnd = WinCreateWindow( hwnd, ! 145: (PSZ) WC_ENTRYFIELD, ! 146: (PSZ) "", ! 147: WS_VISIBLE, ! 148: 0, 0, 0, 0, ! 149: hwnd, ! 150: HWND_TOP, ! 151: IDM_EDITWINDOW, ! 152: (PSZ) NULL, ! 153: (PSZ) NULL ); ! 154: ! 155: /* When a window is created, the initial size message has 0, 0 as */ ! 156: /* the size. Get the real size and call the size routine as if */ ! 157: /* the proper size was sent. This also positions the Cardfile */ ! 158: /* Edit window in the correct position in the main window */ ! 159: ! 160: WinQueryWindowRect( FRAME(hwnd), (PRECTL)&rect ); ! 161: CardfileSize( hwnd, rect.xRight, rect.yTop ); ! 162: ! 163: /* Because the edit control window wasn't created when the main */ ! 164: /* window was activated, the main window now has the focus. Need */ ! 165: /* to give the focus to the edit window. */ ! 166: ! 167: WinSetFocus( hAB, hCardWnd ); ! 168: #endif ! 169: ! 170: if (!hCardWnd) ! 171: { ! 172: /* some kind of failure */ ! 173: InitError: ! 174: MessageBox(hwnd, (LPSTR)NotEnoughMem, (LPSTR)NULL, MB_OK | MB_ICONEXCLAMATION); ! 175: return(FALSE); ! 176: } ! 177: ! 178: /* limit the number of characters that can be typed into the */ ! 179: /* edit control to the number that will fit on a card */ ! 180: SendMessage(hCardWnd, EM_LIMITTEXT, CARDTEXTSIZE, 0L); ! 181: ! 182: /* filter the messages going to the edit control */ ! 183: lpEditWndProc = (FARPROC)GetWindowLong(hCardWnd, GWL_WNDPROC); ! 184: SetWindowLong(hCardWnd, GWL_WNDPROC, (LONG)lpCardWndProc); ! 185: ! 186: SetEditText((LPSTR)""); ! 187: ! 188: ShowWindow(FRAME(hwnd), cmdShow); ! 189: ! 190: MakeTmpFile(); ! 191: ! 192: /* if a file was passed as a command line argument, try to read it in */ ! 193: for (lpchTmp = lpszCommandLine; *lpchTmp == ' '; lpchTmp++) ! 194: ; ! 195: for (pchTmp = CurIFile, i = 0; i < PATHMAX-1 && (BYTE)*lpchTmp > ' '; ++i) ! 196: *pchTmp++ = *lpchTmp++; ! 197: *pchTmp = 0; ! 198: AnsiUpper((LPSTR)CurIFile); ! 199: ! 200: if (*CurIFile) ! 201: if (!DoOpen(CurIFile)) ! 202: CurIFile[0] = 0; ! 203: ! 204: return(TRUE); ! 205: } ! 206: ! 207: ! 208: /*********************************************************************/ ! 209: /* CardfileInit - */ ! 210: /* Performs the one time initialization, such as class */ ! 211: /* registration. */ ! 212: /* */ ! 213: /* Different in PM and Windows */ ! 214: /*********************************************************************/ ! 215: ! 216: BOOL FAR CardfileInit() ! 217: { ! 218: PWNDCLASS pClass; ! 219: HANDLE hIcon; ! 220: TEXTMETRIC Metrics; /* structure filled with font info */ ! 221: LOGBRUSH logBrush; ! 222: HDC hIC; ! 223: ! 224: /* In the PM version, brushes are treated as longs (the color). */ ! 225: ! 226: /* initialize the brushes */ ! 227: #ifdef IN_WINDOWS ! 228: hbrWhite = GetStockObject(WHITE_BRUSH); ! 229: hbrBlack = GetStockObject(BLACK_BRUSH); ! 230: hbrGray = GetStockObject(GRAY_BRUSH); ! 231: GetObject(hbrGray, sizeof(LOGBRUSH), (LPSTR)&logBrush); ! 232: if (!(hbrGray = CreateBrushIndirect((LPLOGBRUSH)&logBrush))) ! 233: hbrGray = hbrWhite; ! 234: #else ! 235: hbrWhite = WHITE_COLOR; ! 236: hbrBlack = BLACK_COLOR; ! 237: hbrGray = WHITE_COLOR; ! 238: #endif ! 239: ! 240: hIC = CreateIC((LPSTR)"DISPLAY", (LPSTR)NULL, (LPSTR)NULL, (LPSTR)NULL); ! 241: if (!hIC) ! 242: return(FALSE); ! 243: ! 244: /* For now, set the brushes to be blue and red in PM */ ! 245: ! 246: /* background should be BLUE, and the line should be RED */ ! 247: #ifdef IN_WINDOWS ! 248: if (!(hbrBack = (HBRUSH) CreateSolidBrush( CONVERT_RGB( RGBBLUE )))) ! 249: hbrBack = hbrGray; ! 250: if (!(hbrLine = (HBRUSH) CreateSolidBrush( CONVERT_RGB( RGBRED )))) ! 251: hbrLine = hbrBlack; ! 252: #else ! 253: hbrBack = BLUE_COLOR; ! 254: hbrLine = RED_COLOR; ! 255: #endif ! 256: ! 257: ! 258: ! 259: /* Setup the font, and get metrics */ ! 260: GetTextMetrics(hIC, (LPTEXTMETRIC)(&Metrics)); ! 261: ! 262: DeleteDC(hIC); ! 263: ! 264: /* In PM, application needs to specify the character height to the */ ! 265: /* binding system so that subsequent TextOut calls can be remapped to */ ! 266: /* have the proper y coordinate. */ ! 267: SET_CHARHEIGHT( (int) Metrics.tmHeight ); ! 268: ! 269: CharFixHeight = (int) (Metrics.tmHeight+Metrics.tmExternalLeading); /* the height */ ! 270: ExtLeading = (int) Metrics.tmExternalLeading; ! 271: CharFixWidth = (int) Metrics.tmAveCharWidth; /* the average width */ ! 272: ySpacing = CharFixHeight+1; ! 273: ! 274: CardWidth = (LINELENGTH * CharFixWidth) + 3; ! 275: CardHeight = (CARDLINES*CharFixHeight) + CharFixHeight + 1 + 2 + 2; ! 276: ! 277: /* Get the resource file info, such as icons, and accelerator tables */ ! 278: /* Register the class */ ! 279: ! 280: #ifdef IN_WINDOWS ! 281: hIcon = LoadIcon(hCardfileInstance,(LPSTR)CFICON); ! 282: hAccel = LoadAccelerators(hCardfileInstance, (LPSTR)CFACCEL); ! 283: ! 284: /* register the cardfile class */ ! 285: pClass = (PWNDCLASS) LocalAlloc(LPTR, sizeof(WNDCLASS)); ! 286: if (!pClass) ! 287: return(FALSE); ! 288: pClass->lpszClassName = (LPSTR)rgchCardfileClass; ! 289: pClass->hCursor = NULL; /* normal cursor is arrow */ ! 290: pClass->hIcon = hIcon; ! 291: pClass->hbrBackground = NULL; ! 292: pClass->style = CS_VREDRAW | CS_DBLCLKS; ! 293: pClass->lpfnWndProc = CardfileWndProc; ! 294: pClass->hInstance = hCardfileInstance; ! 295: pClass->lpszMenuName = (LPSTR)CFMENU; ! 296: if (!RegisterClass((LPWNDCLASS) pClass)) ! 297: return FALSE; ! 298: LocalFree((HANDLE)pClass); ! 299: #else ! 300: /* Register the PM class */ ! 301: ! 302: if ( !WinRegisterClass( hAB, ! 303: (PSZ) rgchCardfileClass, ! 304: (PFNWP) CardfileWndProc, ! 305: CS_SIZEREDRAW, ! 306: NULL ) ) ! 307: return FALSE; ! 308: #endif ! 309: ! 310: ! 311: return TRUE; ! 312: } ! 313:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.