home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddfmek.zip / HELPDDF.C < prev    next >
Text File  |  1994-01-29  |  3KB  |  96 lines

  1. #include <stdlib.h>
  2. #include <malloc.h>
  3. #include "help.h"
  4.  
  5. /* MACROS */
  6. #define PFROMOFF(pBase, off) (PVOID)((PBYTE)(pBase) + (off))
  7.  
  8. /* PROTOTYPES */
  9. void ShowErrorInfo(HWND hwnd);
  10.  
  11.  
  12. /* Ddf(): called to process HM_QUERY_DDF_DATA message */
  13. /* returns ahandle to the Ddf instance (or NULLHANDLE) */
  14. HDDF Ddf(HWND hwndPage, LONG id)
  15. {
  16.    HWND hwndPageFrame, hwndCoverpage, hwndInstance;
  17.    HDDF hddf;
  18.    CHAR szDdf[300];
  19.    LONG i;
  20.    APIRET rc;
  21.    PERRINFO perri;
  22.  
  23.    hwndPageFrame = WinQueryWindow(hwndPage, QW_PARENT);  /* page frame */
  24.    hwndCoverpage = WinQueryWindow(hwndPageFrame, QW_PARENT);  /* coverpage */
  25.    hwndInstance = (HWND)WinSendMsg(hwndCoverpage, HM_QUERY,
  26.          MPFROM2SHORT(0, HMQW_INSTANCE), NULL);
  27.  
  28.    hddf = DdfInitialize(
  29.                    hwndInstance,  /* Handle of help instance */
  30.                    0L,            /* Default buffer size     */
  31.                    0L             /* Default increment       */
  32.                    );
  33.    if (hddf == NULLHANDLE)       /* Check return code       */
  34.        return hddf;
  35.  
  36.    /* initial text */
  37.    DdfPara(hddf);
  38.    sprintf(szDdf, "Ddf data was requested from the application.  "
  39.          "The ID is %ld", id);
  40.    DdfText(hddf, szDdf);
  41.  
  42.    /* test DdfInform */
  43.    DdfPara(hddf);                          
  44.    DdfText(hddf, "The following links are 'inform' links that should "
  45.          "cause the app to bring up a confirming message box.  The ID "
  46.          "in the confirmation dialog should match the link number:  ");
  47.    DdfInform(hddf, "Link 1", 1);
  48.    DdfText(hddf, ", ");
  49.    sprintf(szDdf, "Link %ld", id);
  50.    DdfInform(hddf, szDdf, id);
  51.    DdfText(hddf, ", ");
  52.    DdfInform(hddf, "Link 64000", 64000);
  53.  
  54.    /* test DdfHyperText */
  55.    DdfPara(hddf);
  56.    DdfText(hddf, "This [");
  57.    if (! DdfHyperText(hddf, "link", "12", REFERENCE_BY_RES))
  58.       ShowErrorInfo(hwndCoverpage);
  59.    DdfText(hddf, "] attempts to link to Panel 12 by resource id.  This [");
  60.    if (! DdfHyperText(hddf, "link", "TWELVE", REFERENCE_BY_ID))
  61.       ShowErrorInfo(hwndCoverpage);
  62.    DdfText(hddf, "] attempts to link to Panel 12 by name.");
  63.  
  64.    return hddf;
  65. }
  66.  
  67.  
  68. /* ShowErrorInfo(): displays error info for the current thread in */
  69. /* a PM message window. */
  70. void ShowErrorInfo(HWND hwnd)
  71. {
  72.    PERRINFO perri;
  73.    CHAR szMsg[256];
  74.    CHAR szAll[1024];
  75.    PULONG poffsz;
  76.    PSZ psz;
  77.    ULONG ul;
  78.  
  79.    perri = WinGetErrorInfo(hab);
  80.    if (perri == NULL) {
  81.       strcpy(szAll, "No Error Info Available");
  82.    } else {
  83.       sprintf(szAll, "Error %04X, Severity %d", ERRORIDERROR(perri->idError),
  84.             ERRORIDSEV(perri->idError));
  85.       poffsz = PFROMOFF(perri, perri->offaoffszMsg);
  86.       for (ul = 0; ul < perri->cDetailLevel; ul++) {
  87.          psz = PFROMOFF(perri, *(poffsz++));
  88.          sprintf(szMsg, ", (%d) %s", ul, psz);
  89.          strcat(szAll, szMsg);
  90.       } /* endfor */
  91.    } /* endif */
  92.    WinFreeErrorInfo(perri);
  93.    WinMessageBox(HWND_DESKTOP, hwnd, szAll, NULL, 0, MB_OK);
  94. }
  95.  
  96.