Ejemplo n.º 1
0
/******************************************************************************
 *  BOOL OnInitAbout(HWND hwndDlg)
 *
 *  WM_INITDIALOG handler for about box
 *
 *  parameters:
 *      hwndDlg - window handle for about box
 *
 *  returns:
 *      FALSE if an error occurs initializing the about box controls, else TRUE
 *
 *  notes:
 *      Version string is constructed from the FileVersion entry in the version
 *      resource just so we only have to change it one place (in the .RC file)
 *
 *      Executable description and copyright also come from the version resource
 *
 *      List box has one line for each loaded opcode.  The legend for the opcode
 *      comes from the respective opcode table entry (e.g., pOpenOpTable[2]).
 *      The construction of the DLL filename is hard-coded here (PICN%.2lu%.2u)
 *      In so doing, we're also hard-coding the dependency between the opcode
 *      number in the DLL name and the actual opcode stuffed in PIC_PARM.Op.
 *
 *      After the list box is loaded, the height to display all the items without
 *      scrolling is computed and the list box and dialog are sized as needed, then
 *      the dialog is centered in the frame
 ******************************************************************************/
static BOOL OnInitAbout(HWND hwndDlg)
{
    char sz[_MAX_PATH + 1];
    char szFmt[256];
    char szVersion[256];
    LPVOID pvVersionData;
    DWORD  handle;
    DWORD  dwSize;
    LPBYTE p;
    char *psz;
    UINT uSize;
    int i;
    HWND hwndList;
    int nHeight;
    int nCount;
    RECT rectW;
    RECT rectC;
    POINT ptTlc;
    int incrHeight;
    /* following because fully-optimized, large-model MSC puts a literal string
        compiled into the call to VerQueryValue into the code segment which GP's
        because, even though the function is prototyped with LPCSTR for that parameter,
        MS actually modifies, then restores the string in the bowels of VerQueryValue */
    static char szVarFileInfoTranslation[] = "\\VarFileInfo\\Translation";

    /**************************************************************************
        read version, copyright, and description from the version resource
    */

    i = GetModuleFileName(hinstThis, sz, sizeof(sz));
    assert(i < sizeof(sz) - 1);
    dwSize = GetFileVersionInfoSize(sz, &handle);
    if ( dwSize == 0 )
        return ( FALSE );
    pvVersionData = GlobalAllocPtr(GMEM_MOVEABLE, dwSize);
    if ( pvVersionData == 0 )
        return ( FALSE );
    if ( GetFileVersionInfo(sz, handle, dwSize, pvVersionData) &&
            VerQueryValue(pvVersionData, szVarFileInfoTranslation, &(LPVOID)p, &uSize) )
    {
        /* following constructs the language id for the version resource -- this
          is very poorly documented in the SDK and the SDK help example is incorrect. */
        wsprintf(sz, "\\StringFileInfo\\%.4x%.4x\\", ((LPWORD)p)[0], ((LPWORD)p)[1]);
        psz = sz + strlen(sz);
        /* now psz -> following trailing \\ in "\\StringFieldInfo\\%4.x%.4x\\" so we
            can copy partial keys to that location and use sz as a full key path for
            whatever we're looking for */

        strcpy(psz, "FileDescription");
        VerQueryValue(pvVersionData, sz, &(LPVOID)p, &uSize);
        SetDlgItemText(hwndDlg, IDC_ABOUT_FILEDESCRIPTION, (LPCSTR)p);

        strcpy(psz, "FileVersion");
        VerQueryValue(pvVersionData, sz, &(LPVOID)p, &uSize);
        /* This is a little wierd.  The static text in the dialog resource is
            a printf format string so we an put the FileVersion and ParmVer
            numbers in the correct places.  Otherwise we'd have to have a bunch
            of separate static strings */
        GetDlgItemText(hwndDlg, IDC_ABOUT_VERSION, szFmt, sizeof(szFmt));
#ifndef NDEBUG
        strcpy(szVersion, "Debug ");
#else
        szVersion[0] = '\0';
#endif
        wsprintf(szVersion + strlen(szVersion), szFmt, p, CURRENT_PARMVER / 10, CURRENT_PARMVER % 10);
        SetDlgItemText(hwndDlg, IDC_ABOUT_VERSION, szVersion);

        strcpy(psz, "LegalCopyright");
        VerQueryValue(pvVersionData, sz, &(LPVOID)p, &uSize);
        SetDlgItemText(hwndDlg, IDC_ABOUT_LEGALCOPYRIGHT, (LPCSTR)p);
        MiscGlobalFreePtr(&pvVersionData);
    }
    else
    {
        /* some error with the version resource */
        MiscGlobalFreePtr(&pvVersionData);
        return ( FALSE );
    }

    /* initialize szFmt with memory model and executable format */
#if defined(WIN32)
    i = LoadString(hinstThis, IDS_WIN32, szFmt, sizeof(szFmt));
    assert(i != 0 && i < sizeof(szFmt) - 1);
#elif defined(__MEDIUM__) || defined(_M_I86MM)
    i = LoadString(hinstThis, IDS_WIN16MEDIUM, szFmt, sizeof(szFmt));
    assert(i != 0 && i < sizeof(szFmt) - 1);
#elif defined(__LARGE__) || defined(_M_I86LM)
    i = LoadString(hinstThis, IDS_WIN16LARGE, szFmt, sizeof(szFmt));
    assert(i != 0 && i < sizeof(szFmt) - 1);
#else
    assert(FALSE);
#endif

    /* initialize szVersion with a description of the compiler */
#if   defined(_MSC_VER)
    i = LoadString(hinstThis, IDS_MSC, szVersion, sizeof(szVersion));
    assert(i != 0 && i < sizeof(szVersion) - 1);
#elif defined(__BORLANDC__)
    i = LoadString(hinstThis, IDS_BORLANDC, szVersion, sizeof(szVersion));
    assert(i != 0 && i < sizeof(szVersion) - 1);
#elif defined(__WATCOMC__)
    i = LoadString(hinstThis, IDS_WATCOMC, szVersion, sizeof(szVersion));
    assert(i != 0 && i < sizeof(szVersion) - 1);
#else
    assert(FALSE);
    i = LoadString(hinstThis, IDS_UNKNOWNC, szVersion, sizeof(szVersion));
    assert(i != 0 && i < sizeof(szVersion) - 1);
#endif

    wsprintf(sz, szFmt, (LPCSTR)szVersion);
    assert(strlen(sz) < sizeof(sz));
    SetDlgItemText(hwndDlg, IDC_ABOUT_COMPILERMODEL, sz);

    /**************************************************************************
        tally up opcode dll's available and add each to the list box
    */

    hwndList = GetDlgItem(hwndDlg, IDC_ABOUT_LIBRARIES);
    for ( i = 0; pOpenOpTable[i] != 0; i++ )
    {
        if ( pOpenOpTable[i]->pszAbout != 0 && pOpenOpTable[i]->nFoundParmVer != 0 )
        {
            wsprintf(
                sz,
                "PICN%.2lu%.2u: %s",
                pOpenOpTable[i]->lOpcode / 1000,
                CURRENT_PARMVER,
                (LPSTR)pOpenOpTable[i]->pszAbout);
            assert(strlen(sz) < sizeof(sz));
            SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)(LPSTR)sz);
        }
    }
    for ( i = 0; pSaveOpTable[i] != 0; i++ )
    {
        if ( pSaveOpTable[i]->pszAbout != 0 && pSaveOpTable[i]->nFoundParmVer != 0 )
        {
            wsprintf(
                sz,
                "PICN%.2lu%.2u: %s",
                pSaveOpTable[i]->lOpcode / 1000,
                CURRENT_PARMVER,
                (LPSTR)pSaveOpTable[i]->pszAbout);
            assert(strlen(sz) < sizeof(sz));
            SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)(LPSTR)sz);
        }
    }
    for ( i = 0; pTransformOpTable[i] != 0; i++ )
    {
        if ( pTransformOpTable[i]->pszAbout != 0 && pTransformOpTable[i]->nFoundParmVer != 0 )
        {
            wsprintf(
                sz,
                "PICN%.2lu%.2u: %s",
                pTransformOpTable[i]->lOpcode / 1000,
                CURRENT_PARMVER,
                (LPSTR)pTransformOpTable[i]->pszAbout);
            assert(strlen(sz) < sizeof(sz));
            SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)(LPSTR)sz);
        }
    }
    for ( i = 0; pToolsOpTable[i] != 0; i++ )
    {
        if ( pToolsOpTable[i]->pszAbout != 0 && pToolsOpTable[i]->nFoundParmVer != 0 )
        {
            wsprintf(
                sz,
                "PICN%.2lu%.2u: %s",
                pToolsOpTable[i]->lOpcode / 1000,
                CURRENT_PARMVER,
                (LPSTR)pToolsOpTable[i]->pszAbout);
            assert(strlen(sz) < sizeof(sz));
            SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)(LPSTR)sz);
        }
    }

    /**************************************************************************
        compute list box height and dialog height with all present opcode dll's
        so that scrolling isn't necessary.  Clearly at some number of opcodes,
        this isn't practical but today it is
    */

    nHeight = (int)SendMessage(hwndList, LB_GETITEMHEIGHT, 0, 0);
    nCount =  (int)SendMessage(hwndList, LB_GETCOUNT, 0, 0);
    GetWindowRect(hwndList, &rectW);
    GetClientRect(hwndList, &rectC);
    incrHeight = nHeight * nCount - rectC.bottom;
    rectW.bottom += incrHeight;

    /* make the list box that much bigger */
    ptTlc.x = rectW.left;
    ptTlc.y = rectW.top;
    ScreenToClient(hwndDlg, &ptTlc);    /* movewindow of child window is in parent coordinates */
    MoveWindow(
        hwndList,
        ptTlc.x,
        ptTlc.y,
        rectW.right - rectW.left,
        rectW.bottom - rectW.top,
        FALSE);

    /* make the dialog box that much bigger */
    GetWindowRect(hwndDlg, &rectW);
    GetClientRect(hwndDlg, &rectC);
    rectW.bottom += incrHeight;
    MoveWindow(                         /* movewindow of popup is in screen coordinates */
        hwndDlg,
        rectW.left,
        rectW.top,
        rectW.right - rectW.left,
        rectW.bottom - rectW.top,
        FALSE);

    /* center dialog on Minerva's main window */
    DlgCenterInOwner(hwndDlg);
    return ( TRUE );
}
Ejemplo n.º 2
0
/******************************************************************************
 *  void OnNewWindow(HWND hwnd)
 * 
 *  Window/New Window menu item selected
 *
 *  parameters:
 *      hwnd - window handle of active child window or NULL if none active
 ******************************************************************************/
static void OnNewWindow(HWND hwnd)
{                
    char sz[_MAX_PATH + 1];
    MDICREATESTRUCT mcs;
    CHILDINSTANCEDATA PICFAR* pInstance = ChildGetInstanceData(hwnd);
    CHILDINSTANCEDATA PICFAR* pNew;

    if ( pInstance == 0 )
        return; /* Window/New Window should have been grayed */

    pNew = (CHILDINSTANCEDATA PICFAR*)MiscGlobalAllocPtr(
        sizeof(*pNew) + lstrlen(pInstance->pszFilename) + 1, IDS_NEWWINDOWOUTOFMEMORY);
        /* "There was not enough memory to create the new window." */
    if ( pNew == 0 )
        return;
        
    *pNew = *pInstance; /* this has the effect of duplicating the modified state
                            of the window as well as of duplicating the src picparm
                            Duplicating the src picparm this way works only because
                            we don't allocate comments, appfields, etc in the 
                            pegasusquery picparm, so it's self-contained */
    pNew->pszFilename  = (LPSTR)pNew + sizeof(*pNew);
    lstrcpy(pNew->pszFilename, pInstance->pszFilename);                            
    pNew->xWindowOrg   = 0;     /* not scrolled to start out */
    pNew->yWindowOrg   = 0;    
    pNew->bRButtonDown = FALSE;             /* should be FALSE anyway */
    assert(!pInstance->bRButtonDown);
    pNew->bLButtonDown = FALSE;             /* should be FALSE anyway */
    assert(!pInstance->bLButtonDown);
    pNew->bDisableSetScrollRanges = FALSE;  /* should be FALSE anyway */
    assert(!pInstance->bDisableSetScrollRanges);
    pNew->hPalette     = NULL;  /* this window will need its own hpalette */
    pNew->nWaitCursor  = 0;
    assert(pInstance->nWaitCursor == 0);

    /* duplicate the source image */
    pNew->pSrc = MiscGlobalAllocPtr(pNew->dwSrcLen, IDS_NEWWINDOWOUTOFMEMORY);
        /* "There was not enough memory to create the new window." */
    if ( pNew->pSrc == 0 )
        {
        MiscGlobalFreePtr(&pInstance);
        return;
        }
    hmemcpy(pNew->pSrc, pInstance->pSrc, pNew->dwSrcLen);

    /* duplicate the dib unless it's a pointer into the source image */
    if ( pInstance->pDib < pInstance->pSrc ||
         pInstance->pDib >= pInstance->pSrc + pInstance->dwSrcLen )
        {
        pNew->pDib = MiscGlobalAllocPtr(pNew->dwDibLen, IDS_NEWWINDOWOUTOFMEMORY);
            /* "There was not enough memory to create the new window." */
        if ( pNew->pDib == 0 )
            {
            MiscGlobalFreePtr(&pNew->pSrc);
            MiscGlobalFreePtr(&pInstance);
            return;
            }
        hmemcpy(pNew->pDib, pInstance->pDib, pNew->dwDibLen);
        }
    else
        pNew->pDib = pNew->pSrc + ( pInstance->pDib - pInstance->pSrc );

    /* duplicate the dib picparm - through the opcode because there may be comments
        or appfields or overtext or some such which need to be separately allocated,
        and which only the opcode knows enough to allocate
        if not implemented, then old is copied over new above when old instance is
        copied to new instance */
    if ( pNew->pOpenOp->pfnDupPicParm != 0 &&
         !(*pNew->pOpenOp->pfnDupPicParm)(&pInstance->DibPicParm, &pNew->DibPicParm) )
        {
        (*pNew->pOpenOp->pfnCleanup)(pNew->pDib, 0, 0);
        MiscGlobalFreePtr(&pNew->pSrc);
        MiscGlobalFreePtr(&pInstance);
        ErrorMessage(STYLE_ERROR, IDS_NEWWINDOWOUTOFMEMORY);
        /* "There was not enough memory to create the new window." */
        return;
        }

    /* duplicate image options settings */
    if ( !CtrlDataDup(
            (LPCTRLINITDATA)pInstance->pOpenData,
            (LPCTRLINITDATA PICFAR *)&pNew->pOpenData) )
        {
        (*pNew->pOpenOp->pfnCleanup)(pNew->pDib, &pInstance->DibPicParm, 0);
        MiscGlobalFreePtr(&pNew->pSrc);
        MiscGlobalFreePtr(&pInstance);
        ErrorMessage(STYLE_ERROR, IDS_NEWWINDOWOUTOFMEMORY);
        /* "There was not enough memory to create the new window." */
        return;
        }

    /* Create MDI child window */
    GetWindowText(hwnd, sz, sizeof(sz));
    mcs.szClass    = MDICHILD_CLASSNAME;
    mcs.szTitle    = pInstance->pszFilename;
    mcs.hOwner     = hinstThis;
    mcs.x          = CW_USEDEFAULT;
    mcs.y          = CW_USEDEFAULT;
    mcs.cx         = CW_USEDEFAULT;
    mcs.cy         = CW_USEDEFAULT;
    mcs.style      = WS_HSCROLL | WS_VSCROLL;
    mcs.lParam     = (LPARAM)pNew;
    if ( ChildGetActive() != NULL && IsZoomed(ChildGetActive()) )
        mcs.style |= WS_MAXIMIZE;
    // tell the MDI Client to create the child 
    LockWindowUpdate(hwndMDIClient);
    hwnd = FORWARD_WM_MDICREATE(hwndMDIClient, (LPMDICREATESTRUCT)&mcs, SendMessage);
    if ( hwnd == NULL )
        {
        LockWindowUpdate(NULL);
        (*pNew->pOpenOp->pfnCleanup)(pNew->pDib, &pInstance->DibPicParm, pNew->pOpenData);
        MiscGlobalFreePtr(&pNew->pSrc);
        MiscGlobalFreePtr(&pInstance);
        ErrorMessage(STYLE_ERROR, IDS_NEWWINDOWCREATE);
        /* "An unexpected error occurred creating the new window." */
        return;
        }
    ShowWindow(hwnd, SW_HIDE);
    LockWindowUpdate(NULL);
    UpdateWindow(hwndMDIClient);

    /* make sure the window isn't bigger than the image */
    ChildSetWindowSize(hwnd);
}