File:  [OS/2 SDKs] / pmsdk / samples / newcard / cfmain.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:28:12 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: pmsdk-1988, HEAD
Microsoft OS/2 SDK PM 08-08-1988

#include "cardfile.h"


/*********************************************************************/
/*  Windows/PM Cardfile Shared Code                                  */
/*                                                                   */
/*  (c) Copyright Microsoft Corp. 1987,1988 - All Rights Reserved    */
/*********************************************************************/

/*********************************************************************/
/*    The following shared code was developed from the original      */
/* Cardfile application.  This code can be compiled to run under     */
/* either the Windows or the PM manager environment.  All            */
/* functionality associated with bitmaps or printing has been        */
/* deleted.  Some comments refering to these functions may still be  */
/* present in the code and should be disregarded. jw.                */
/*********************************************************************/


/*********************************************************************/
/* CardfileWndProc -                                                 */
/*    This routine processes messages to the main card window in     */
/* both Cardfile and Phonebook mode.                                 */
/*                                                                   */
/* Substantially different in PM and Windows                         */
/*********************************************************************/

/* this is the main Window Procedure for cardfile's window */
long far PASCAL CardfileWndProc(hwnd, message, wParam, lParam)
HWND hwnd;
unsigned message;
WINWORD wParam;
DWORD lParam;
{
    PAINTSTRUCT ps;
    LPCARDHEADER lpCards;
    int range;
    HMENU hMenu;
    char buf[30];
    HDC hDC;
    MSG msg;
    RECT rect;
    int y;

    switch (message)
        {
        case WM_CREATE:
            /* save the window handle */
            hCardfileWnd = hwnd;

#ifdef   IN_WINDOWS
            /* In PM, the style for the about box is to have the about */
            /* Command separated from the last item in the first menu  */
            /* In other words, using ChangeMenu is unneccessary in PM */

            /* add "About" to the system menu */
            hMenu = GetSystemMenu(hwnd, FALSE);
            ChangeMenu(hMenu, 0, (LPSTR)NULL, -1, MF_APPEND | MF_SEPARATOR);
            LoadString(hCardfileInstance, IDS_ABOUT, (LPSTR)buf, 30);
            ChangeMenu(hMenu, 0, (LPSTR)buf, IDM_ABOUT, MF_APPEND | MF_STRING);
#endif

            /* set the caption */
            SetCaption();

            /* initialize the scroll bars */
            /* Use macro which sets Range and Pos all at once   */
            SCROLL_RANGE(hwnd, SB_HORZ, 0, 0, cCards-1);
            SCROLL_RANGE(hwnd, SB_VERT, 0, 0, 0);
            break;

        case WM_LBUTTONDOWN:
        case WM_LBUTTONDBLCLK:
            /* handle mouse input */
#ifndef  IN_WINDOWS
            /* In PM, mouse point comes in wParam, just move to lParam */
            lParam = wParam;
#endif
            CardfileMouse(hwnd, message, MAKEPOINT(lParam));
            break;

#ifdef   IN_WINDOWS
        /* In PM, ignore EndSession stuff.  In PM, application will */
        /*  receive close message and can prompt user whether to close */
        /*  or not */

        case WM_ENDSESSION:
            /* windows is about to close down */
            if (wParam)
                /* make sure temp file goes away */
                Fdelete(TmpFile);
            break;

        case WM_QUERYENDSESSION:
            /* windows is asking if it is ok to close down */
            /* if there are changes in cardfile, ask if user wants to */
            /* save them, and give user a chance to cancel end session */
            if (MaybeSaveFile())
                {
                /* user says it's ok to end session.  make sure that */
                /* cardfile is in a position to continue in case user */
                /* cancels end session from some other application */
                SetCurCard(iFirstCard);
                return(TRUE);
                }
            else
                /* user cancelled.  Tell windows not to end session */
                return(FALSE);
            break;

#endif
        case WM_CLOSE:

            /* user is trying to close cardfile's window */
            /* if changes in cardfile, ask user if he wants to save, or */
            /* wants to cancel close */
            if (MaybeSaveFile())
                {
                /* everything is ok to close */
                /* ok, time to quit */

            /* The PostQuitMessage doesn't haven't enough information,  */
            /*  i.e. the window handle, to remap it into WinPostMsg.    */
            /*  Therefore, use separate compilation.  */

#ifdef   IN_WINDOWS
                PostQuitMessage(0);
#else
                WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
#endif
                }
            return(TRUE);

        case WM_DESTROY:
            /* cardfile's window is going away: clean up */
            /* get rid of temp file */
            Fdelete(TmpFile);

            /* if last instance of cardfile, get rid of brushes */
            /* if not last instance, then other's will still use them */

            /* The idea of the last instance and shared data between  */
            /* instances are windows concepts only.  Also, for PM, this */
            /* application doesn't allocate memory for brushes */

#ifdef   IN_WINDOWS
            if (GetModuleUsage(hCardfileInstance) == 1)
                {
                DeleteObject(hbrGray);
                DeleteObject(hbrBack);
                DeleteObject(hbrLine);
                }
#endif
            return(TRUE);

        case WM_INITMENU:
            /* the user has clicked on a menu.  Enable and check everything*/
            /* that should be, before the menu is actually brought up */
            UpdateMenu();
            break;

        case WM_COMMAND:
            /* one of three things */
            /* the edit control may be reporting that it has run out of */
            /* memory and can't accept any more input */

            /* For Windows version, check lParam in if statement */
            /* For PM version, don't worry about check, just compile */
            /* statement in else clause */

#ifdef   IN_WINDOWS
            if (LOWORD(lParam) == hCardWnd && HIWORD(lParam) == EN_ERRSPACE)
                CardfileOkError(IDS_EINSMEMORY);
            else
#endif
                /* or, the common thing, the user has executed a menu command */
                CardfileInput(hwnd, LOUSHORT(wParam));
            break;

        /* In PM version, don't worry about background color of  */
        /* edit control.  It should always be white anyway.      */

#ifdef   IN_WINDOWS
        case WM_CTLCOLOR:
            /* this message gives cardfile a chance to set the background */
            /* color of the edit control, which should always be white */
            if (LOWORD(lParam) == hCardWnd)
                {
                SetBkColor((HDC)wParam, 0x00ffffff);
                SetTextColor((HDC)wParam, 0L);
                return((long)hbrWhite);
                }
            /* if not edit control, pass message on */
            goto CallDefProc;
#endif

        /* In Windows, process erase background message.  In PM,  */
        /*  the 'equivalent' message really isn't the same.  The  */
        /*  PM message is sent when the frame window needs to be  */
        /*  erased; in response to the repainting of any of the   */
        /*  control windows, not just the client area.  In PM,    */
        /*  it's easier (safer) to erase the client area when a   */
        /*  WM_PAINT message comes. */

#ifdef   IN_WINDOWS
        case WM_ERASEBKGND:
            /* paint the background, which will be BLUE or GRAY */
            CardfileEraseBkGnd(hwnd, (HDC)wParam);
            break;
#endif

        case WM_PAINT:
            /* Time to paint, either a phonebook paint,  */
            /* or a cardfile paint */
            BeginPaint(hwnd, (LPPAINTSTRUCT)&ps);

            /* See comment for WM_ERASEBKGND message.  In PM, erase  */
            /* client area background when WM_PAINT message comes */
#ifndef  IN_WINDOWS
            CardfileEraseBkGnd(hwnd, ps.hdc);
#endif

            if (CardPhone == IDM_PHONEBOOK)
                PhonePaint(hwnd, ps.hdc);
            else
                CardfilePaint(hwnd, ps.hdc);

            EndPaint(hwnd, (LPPAINTSTRUCT)&ps);
            break;

        case WM_SIZE:

            /* the main window has changed size */
            CardfileSize(hwnd, LOWORD(lParam), HIWORD(lParam));
            break;

        case WM_HSCROLL:
            /* there is a horizontal scroll bar only in cardfile mode */

            /* In PM, Scroll message is similar except that command is */
            /*  the low word of lParam instead of wParam */            
#ifndef  IN_WINDOWS
            wParam = (long) HIUSHORT(lParam);
#endif            
            CardfileScroll(hwnd, LOUSHORT(wParam), LOWORD(lParam));
            break;

        case WM_VSCROLL:
            /* the vertical scroll bar only appears in phonebook mode */

            /* In PM, Scroll message is similar except that command is */
            /*  the low word of lParam instead of wParam */            
#ifndef  IN_WINDOWS
            wParam = (long) HIUSHORT(lParam);
#endif            
            PhoneScroll(hwnd, LOUSHORT(wParam), LOWORD(lParam));
            break;

        case WM_CHAR:
            /* handle character input for phonebook mode.      */

            if(CardPhone != IDM_PHONEBOOK)
                break;

            /* In Windows, the WM_CHAR message contains only valid  */
            /*  characters, so just send the message to the char    */
            /*  routine.  */
#ifdef   IN_WINDOWS
	    if (GetKeyState(VK_CTRL))
               CardChar(wParam);
#else
            /* In PM, WM_CHAR message may contain a ascii char, system */
            /* char, key up or key down message.  Need to distinguish  */
            /* between the cases.  */

            /* If key up or dead key, ignore */
            if (wParam & (KC_KEYUP | KC_DEADKEY))
               break;

            /* If virtual key is valid, check if arrow or PGUP */
            if (wParam & KC_VIRTUALKEY)
               if (PhoneKey(hwnd, HIUSHORT(lParam)))
                  return( TRUE );

            /* If ctrl-char valid, check if first letter in index line */
            if ((wParam & KC_CHAR) && (wParam & KC_CTRL))
               if (CardChar(LOUSHORT(lParam)))
                  return( TRUE );
#endif
            break;

            /* WM_KEYDOWN message is handled through WM_CHAR message in */
            /* PM.  */

#ifdef   IN_WINDOWS
        case WM_KEYDOWN:
            /* handle keys.  Again, this will only come through when */
            /* cardfile is in phonebook mode */
            PhoneKey(hwnd, wParam);
            break;
#endif

        case WM_ACTIVATE:
            /* activate, and set focus to either edit control, or main window*/
            /* depending upon which mode we are in */

            if (LOUSHORT(wParam))
                if (CardPhone == IDM_CARDFILE)
                    SetFocus(hCardWnd);
                else
                    SetFocus(hCardfileWnd);
            break;

   /* In PM, KillFocus message is incorporated in SetFocus message.  */
   /* Because all that is done for the SetFocus or KillFocus message is */
   /* to toggle the hilight state, just add extra case for Windows  */
   /* version */

        case WM_SETFOCUS:
#ifdef   IN_WINDOWS
        case WM_KILLFOCUS:
#endif
            /* if in phonebook, take down highlighting */
            if(CardPhone == IDM_PHONEBOOK)
                {
                hDC = GetDC(hCardfileWnd);
                y = (iFirstCard - iTopCard) * CharFixHeight;
                TRANSLATE_COORDS( cyMainWindow );

                SetRect((LPRECT)&rect, 0, y, (LINELENGTH+2) * CharFixWidth, 
                        y+CharFixHeight);

                TRANSLATE_RECT( rect );

                InvertRect(hDC, (LPRECT)&rect);
                ReleaseDC(hCardfileWnd, hDC);

                TRANSLATE_COORDS( 0 );
                }
            break;

        /* In PM, the about box is not in the system menu so ignore this */
#ifdef   IN_WINDOWS
        case WM_SYSCOMMAND:
            /* user has chosen ABOUT, put up dialog */
            if (wParam == IDM_ABOUT)
                {
                CardfileInput(hwnd, wParam);
                break;
                }
#endif

        default:
            /* some other message, let default handler take care of it */
CallDefProc:
            return(DefWindowProc(hwnd, message, wParam, lParam));
            break;
        }
    return(0L);
}


unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.