home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 24 / CDACTUAL24.iso / SHARE / os2 / edm2 / common / snippets / notebooktabs.txt < prev    next >
Encoding:
Text File  |  1997-02-23  |  2.9 KB  |  88 lines

  1. Larry Salomon Jr.
  2.  
  3. Yet another month with no submissions from the readers, so I have pulled
  4. out another (after doing some searching this time...I'm running out of
  5. these) function that I have found quite useful in the past.
  6.  
  7. BOOL sizeMajorTabs(HWND hwndNb)
  8. //-------------------------------------------------------------------------
  9. // This function sizes the major tabs of a notebook according to the
  10. // largest text.
  11. //
  12. // Input:  hwndNb - handle of the notebook
  13. // Returns:  TRUE if successful, FALSE otherwise
  14. //-------------------------------------------------------------------------
  15. {
  16.    HPS hpsTemp;
  17.    SIZEL szlMax;
  18.    ULONG ulMajor;
  19.    ULONG ulPage;
  20.    CHAR achText[256];
  21.    BOOKTEXT btText;
  22.    POINTL aptlBox[TXTBOX_COUNT];
  23.    ULONG ulStyle;
  24.  
  25.    hpsTemp=WinGetPS(hwndNb);
  26.  
  27.    szlMax.cx=0;
  28.    szlMax.cy=0;
  29.  
  30.    ulMajor=LONGFROMMR(WinSendMsg(hwndNb,
  31.                                  BKM_QUERYPAGEID,
  32.                                  MPFROMLONG(0),
  33.                                  MPFROM2SHORT(BKA_FIRST,BKA_MAJOR)));
  34.    while (ulMajor!=0) {
  35.       ulPage=ulMajor;
  36.  
  37.       while (ulPage!=0) {
  38.          btText.pString=achText;
  39.          btText.textLen=sizeof(achText);
  40.  
  41.          WinSendMsg(hwndNb,
  42.                     BKM_QUERYTABTEXT,
  43.                     MPFROMLONG(ulPage),
  44.                     MPFROMP(&btText));
  45.  
  46.          GpiQueryTextBox(hpsTemp,
  47.                          strlen(btText.pString),
  48.                          btText.pString,
  49.                          TXTBOX_COUNT,
  50.                          aptlBox);
  51.  
  52.          aptlBox[TXTBOX_TOPRIGHT].x-=aptlBox[TXTBOX_BOTTOMLEFT].x;
  53.          aptlBox[TXTBOX_TOPRIGHT].y-=aptlBox[TXTBOX_BOTTOMLEFT].y;
  54.  
  55.          szlMax.cx=max(szlMax.cx,aptlBox[TXTBOX_TOPRIGHT].x);
  56.          szlMax.cy=max(szlMax.cy,aptlBox[TXTBOX_TOPRIGHT].y);
  57.  
  58.          ulPage=LONGFROMMR(WinSendMsg(hwndNb,
  59.                                       BKM_QUERYPAGEID,
  60.                                       MPFROMLONG(ulPage),
  61.                                       MPFROM2SHORT(BKA_NEXT,0)));
  62.          if (ulPage!=0) {
  63.             ulStyle=LONGFROMMR(WinSendMsg(hwndNb,
  64.                                           BKM_QUERYPAGESTYLE,
  65.                                           MPFROMLONG(ulPage),
  66.                                           0));
  67.             if ((ulStyle & BKA_MAJOR)!=0) {
  68.                ulPage=0;
  69.             } /* endif */
  70.          } /* endif */
  71.       } /* endwhile */
  72.  
  73.       ulMajor=LONGFROMMR(WinSendMsg(hwndNb,
  74.                                     BKM_QUERYPAGEID,
  75.                                     MPFROMLONG(ulMajor),
  76.                                     MPFROM2SHORT(BKA_NEXT,BKA_MAJOR)));
  77.    } /* endwhile */
  78.  
  79.    WinReleasePS(hpsTemp);
  80.  
  81.    WinSendMsg(hwndNb,
  82.               BKM_SETDIMENSIONS,
  83.               MPFROM2SHORT(szlMax.cx*4/3,szlMax.cy*3/2),
  84.               MPFROMSHORT(BKA_MAJORTAB));
  85.  
  86.    return TRUE;
  87. }
  88.