home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dbcs.zip / DBCS.C < prev    next >
C/C++ Source or Header  |  1996-01-22  |  22KB  |  662 lines

  1. #pragma    title("DBCS Driver  --  Version 1  --  (DBCS.C)")
  2. #pragma    subtitle("   DBCS Support - Interface Definitions")
  3.  
  4. #define    INCL_DOS           /* Include OS/2 DOS Kernal        */
  5. #define    INCL_GPI           /* Include OS/2 PM GPI Interface    */
  6. #define    INCL_WIN           /* Include OS/2 PM Windows Interface    */
  7.  
  8. #pragma    info(noext)
  9.  
  10. #include <os2.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "appdefs.h"
  16. #include "prnsetup.h"
  17.  
  18. /* This    module contains    the routine to display selected    font metric    */
  19. /* information.                                */
  20.  
  21. /* Filename:   DBCS.C                            */
  22.  
  23. /*  Version:   1                            */
  24. /*  Created:   1996-01-19                        */
  25. /*  Revised:   1996-01-20                        */
  26.  
  27. /* Routines:   VOID SetCountryCode(ULONG ulCountry, ULONG ulCP);    */
  28. /*           LONG FindDBCSFont(CHAR *pszFacename, PLONG plPoints);    */
  29. /*           BOOL fQueryDBCS(VOID);                    */
  30. /*           ULONG ulQueryCharDBCS(const PSZ pszString, INT n);    */
  31. /*           PSZ  strrchrDBCS(const CHAR *p, INT c);            */
  32. /*           PSZ  strchrDBCS(const CHAR *p, INT c);            */
  33. /*           PSZ  struprDBCS(CHAR *p);                */
  34. /*           PSZ  strstrDBCS(const CHAR *str1, const CHAR *str2);    */
  35. /*           VOID CenterDlg(HWND hWnd);                */
  36.  
  37. /************************************************************************/
  38. /************************************************************************/
  39. /************************************************************************/
  40. /* DISCLAIMER OF WARRANTIES:                        */
  41. /* -------------------------                        */
  42. /* The following [enclosed] code is sample code    created    by IBM        */
  43. /* Corporation and Prominare Inc.  This    sample code is not part    of any    */
  44. /* standard IBM    product    and is provided    to you solely for the purpose    */
  45. /* of assisting    you in the development of your applications.  The code    */
  46. /* is provided "AS IS",    without    warranty of any    kind.  Neither IBM nor    */
  47. /* Prominare shall be liable for any damages arising out of your    */
  48. /* use of the sample code, even    if they    have been advised of the    */
  49. /* possibility of such damages.                        */
  50. /************************************************************************/
  51. /************************************************************************/
  52. /************************************************************************/
  53. /*               D I S C L A I M E R                */
  54. /* This    code is    provided on an as is basis with    no implied support.    */
  55. /* It should be    considered freeware that cannot    be rebundled as        */
  56. /* part    of a larger "*ware" offering without our consent.        */
  57. /************************************************************************/
  58. /************************************************************************/
  59. /************************************************************************/
  60.  
  61. /* Copyright ╕ International Business Machines Corp., 1996.        */
  62. /* Copyright ╕ 1996  Prominare Inc.  All Rights    Reserved.        */
  63.  
  64. /* --------------------------------------------------------------------    */
  65.  
  66. /* -- Standard Window Classes -----------------------------------------    */
  67.  
  68. #define    WINCLASS_FRAME           0x00000001L
  69. #define    WINCLASS_COMBOBOX       0x00000002L
  70. #define    WINCLASS_BUTTON           0x00000003L
  71. #define    WINCLASS_MENU           0x00000004L
  72. #define    WINCLASS_STATIC           0x00000005L
  73. #define    WINCLASS_ENTRYFIELD       0x00000006L
  74. #define    WINCLASS_LISTBOX       0x00000007L
  75. #define    WINCLASS_SCROLLBAR       0x00000008L
  76. #define    WINCLASS_TITLEBAR       0x00000009L
  77. #define    WINCLASS_MLE           0x0000000AL
  78. /* 000B    to 000F    reserved */
  79. #define    WINCLASS_APPSTAT       0x00000010L
  80. #define    WINCLASS_KBDSTAT       0x00000011L
  81. #define    WINCLASS_PECIC           0x00000012L
  82. #define    WINCLASS_DBE_KKPOPUP       0x00000013L
  83. /* 0014    to 001F    reserved */
  84. #define    WINCLASS_SPINBUTTON       0x00000020L
  85. /* 0021    to 0024    reserved */
  86. #define    WINCLASS_CONTAINER       0x00000025L
  87. #define    WINCLASS_SLIDER           0x00000026L
  88. #define    WINCLASS_VALUESET       0x00000027L
  89. #define    WINCLASS_NOTEBOOK       0x00000028L
  90. #define    WINCLASS_HWXENTRY       0x00000029L
  91. #define    WINCLASS_SKETCH           0x0000002aL
  92. /* 002b    to 0030    reserved */
  93. /* 0030    to 003F    reserved */
  94. #define    WINCLASS_GRAPHICBUTTON       0x00000040L
  95. #define    WINCLASS_CIRCULARSLIDER       0x00000041L
  96.  
  97. #define    PMCLASS_FRAME          "#1"
  98. #define    PMCLASS_COMBOBOX      "#2"
  99. #define    PMCLASS_BUTTON          "#3"
  100. #define    PMCLASS_MENU          "#4"
  101. #define    PMCLASS_STATIC          "#5"
  102. #define    PMCLASS_ENTRYFIELD      "#6"
  103. #define    PMCLASS_LISTBOX          "#7"
  104. #define    PMCLASS_SCROLLBAR      "#8"
  105. #define    PMCLASS_TITLEBAR      "#9"
  106. #define    PMCLASS_MLE          "#10"
  107. /* 000B    to 000F    reserved */
  108. #define    PMCLASS_APPSTAT          "#16"
  109. #define    PMCLASS_KBDSTAT          "#17"
  110. #define    PMCLASS_PECIC          "#18"
  111. #define    PMCLASS_DBE_KKPOPUP      "#19"
  112. /* 0014    to 001F    reserved */
  113. #define    PMCLASS_SPINBUTTON      "#32"
  114. /* 0021    to 0024    reserved */
  115. #define    PMCLASS_CONTAINER      "#37"
  116. #define    PMCLASS_SLIDER          "#38"
  117. #define    PMCLASS_VALUESET      "#39"
  118. #define    PMCLASS_NOTEBOOK      "#40"
  119. #define    PMCLASS_HWXENTRY      "#41"
  120. #define    PMCLASS_SKETCH          "#42"
  121. /* 002b    to 0030    reserved */
  122. /* 0030    to 003F    reserved */
  123. #define    PMCLASS_GRAPHICBUTTON      "#64"
  124. #define    PMCLASS_CIRCULARSLIDER      "#65"
  125.  
  126. #define    PMCLASS_LEN_FRAME          3
  127. #define    PMCLASS_LEN_COMBOBOX          3
  128. #define    PMCLASS_LEN_BUTTON          3
  129. #define    PMCLASS_LEN_MENU          3
  130. #define    PMCLASS_LEN_STATIC          3
  131. #define    PMCLASS_LEN_ENTRYFIELD          3
  132. #define    PMCLASS_LEN_LISTBOX          3
  133. #define    PMCLASS_LEN_SCROLLBAR          3
  134. #define    PMCLASS_LEN_TITLEBAR          3
  135. #define    PMCLASS_LEN_MLE              4
  136. /* 000B    to 000F    reserved */
  137. #define    PMCLASS_LEN_APPSTAT          4
  138. #define    PMCLASS_LEN_KBDSTAT          4
  139. #define    PMCLASS_LEN_PECIC          4
  140. #define    PMCLASS_LEN_DBE_KKPOPUP          4
  141. /* 0014    to 001F    reserved */
  142. #define    PMCLASS_LEN_SPINBUTTON          4
  143. /* 0021    to 0024    reserved */
  144. #define    PMCLASS_LEN_CONTAINER          4
  145. #define    PMCLASS_LEN_SLIDER          4
  146. #define    PMCLASS_LEN_VALUESET          4
  147. #define    PMCLASS_LEN_NOTEBOOK          4
  148. #define    PMCLASS_LEN_HWXENTRY          4
  149. #define    PMCLASS_LEN_SKETCH          4
  150. /* 002b    to 0030    reserved */
  151. /* 0030    to 003F    reserved */
  152. #define    PMCLASS_LEN_GRAPHICBUTTON     4
  153. #define    PMCLASS_LEN_CIRCULARSLIDER    4
  154.  
  155.  
  156. #define    TYPE_SBCS         0x0000UL
  157. #define    TYPE_DBCS_1ST         0x0001UL
  158. #define    TYPE_DBCS_2ND         0x0002UL
  159.  
  160. #define    MAX_LEADBYTE    256
  161.  
  162. #pragma    pack(1)
  163.  
  164. typedef    struct _DBCSVECTOR
  165.    {
  166.    BYTE    bLow;
  167.    BYTE    bHigh;
  168.    } DBCSVECTOR;
  169.  
  170. #pragma    pack( )
  171.  
  172. /* --- DBCS Support ---------------------------------------------------    */
  173.  
  174. BOOL        afLeadByte[MAX_LEADBYTE];  /* Lead bytes Array        */
  175. BOOL        fDBCS = FALSE;       /* Double Byte System        */
  176. COUNTRYCODE cc = { 0, 0    };       /* Country Code            */
  177. DBCSVECTOR  aDBCSVector[8];       /* DBCS Vector            */
  178.  
  179. CHAR        szFontNameSize[FACESIZE * 2];
  180. ULONG        cFontNameSize;
  181.  
  182. /* --- Module Prototype    Definitions -----------------------------------    */
  183.  
  184. BOOL fDBCSChar(UCHAR uch);
  185. ULONG ulQueryCharDBCS(const CHAR *pszString, INT n);
  186.  
  187. #pragma    subtitle("   DBCS Support - Country Code Set Function")
  188. #pragma    page( )
  189.  
  190. /* --- SetCountryCode ---------------------------------- [ Public ] ---    */
  191. /*                                    */
  192. /*     This function is    used to    set the    country    code and code page for    */
  193. /*     DBCS activities.                            */
  194. /*                                    */
  195. /*     Upon Entry:                            */
  196. /*                                    */
  197. /*     ULONG ulCountry;    = Country Code                    */
  198. /*     ULONG ulCP;    = Code Page                    */
  199. /*                                    */
  200. /*     Upon Exit:                            */
  201. /*                                    */
  202. /*     Nothing                                */
  203. /*                                    */
  204. /* --------------------------------------------------------------------    */
  205.  
  206. VOID SetCountryCode(ULONG ulCountry, ULONG ulCP)
  207.  
  208. {
  209.  
  210. cc.country  = ulCountry;
  211. cc.codepage = ulCP;
  212.  
  213. }
  214. #pragma    subtitle("   DBCS Support - DBCS Font Selection Function")
  215. #pragma    page( )
  216.  
  217. /* --- FindDBCSFont ------------------------------------ [ Public ] ---    */
  218. /*                                    */
  219. /*     This function is    used to    find a DBCS raster font    for a given    */
  220. /*     point size.                            */
  221. /*                                    */
  222. /*     Upon Entry:                            */
  223. /*                                    */
  224. /*     CHAR  *pszFacename; = Font Face Name                */
  225. /*     PLONG plPoints;       = Points Size Requested Pointer        */
  226. /*                                    */
  227. /*     Upon Exit:                            */
  228. /*                                    */
  229. /*     FindDBCSFont = lMatch Number for    Requested Font            */
  230. /*                                    */
  231. /* --------------------------------------------------------------------    */
  232.  
  233. LONG FindDBCSFont(CHAR *pszFacename, PLONG plPoints)
  234.  
  235. {
  236. HDC         hDC;           /* Display Device Context Handle    */
  237. HPS         hPS;           /* Presentation Space Handle        */
  238. LONG         cDBCSFonts;       /* DBCS Font    Count            */
  239. LONG         cFonts;           /* Fonts Count            */
  240. LONG         lFontsTotal = 0L;       /* Fonts Total Count            */
  241. LONG         lMatch = 0L;       /* Font Match Number            */
  242. LONG         lPoints;           /* Point Size            */
  243. LONG         lXDeviceRes;       /* x    Device Resolution        */
  244. LONG         lYDeviceRes;       /* y    Device Resolution        */
  245. PFONTMETRICS pfm;           /* Font Metrics Pointer        */
  246. PFONTMETRICS pfmDBCS;           /* Font Metrics Pointer        */
  247. register INT i,    n;           /* Loop Counter            */
  248.  
  249.                /* Get the height of the    screen in pels        */
  250.  
  251. if ( (hPS = WinGetScreenPS(HWND_DESKTOP)) != (HPS)NULL )
  252.    if (    (hDC = GpiQueryDevice(hPS)) != (HDC)NULL )
  253.        {
  254.        DevQueryCaps(hDC, CAPS_HORIZONTAL_FONT_RES, 1L, &lXDeviceRes);
  255.        DevQueryCaps(hDC, CAPS_VERTICAL_FONT_RES,   1L, &lYDeviceRes);
  256.  
  257.                /* Get the number of fonts for the face name    */
  258.                /* provided                    */
  259.  
  260.        cFonts =    GpiQueryFonts(hPS, QF_PUBLIC, (PSZ)NULL, &lFontsTotal, sizeof(FONTMETRICS), (PFONTMETRICS)NULL);
  261.  
  262.                /* Make a pointer for the memory    allocated for    */
  263.                /* the font metrics and get the font metrics for    */
  264.                /* the number of    fonts for the face name        */
  265.                /* provided                    */
  266.  
  267.        DosAllocMem((PPVOID)(PVOID)&pfm,    (ULONG)(sizeof(FONTMETRICS) * cFonts), PAG_READ    | PAG_WRITE | PAG_COMMIT);
  268.        GpiQueryFonts(hPS, QF_PUBLIC, (PSZ)NULL,    &cFonts, sizeof(FONTMETRICS), pfm);
  269.  
  270.                /* Release the presentation space acquired to    */
  271.                /* determine the    screen height and to get the    */
  272.                /* font metrics                    */
  273.        WinReleasePS(hPS);
  274.                /* Loop through the font    metrics    returned to    */
  275.                /* locate the desired font by matching the x and    */
  276.                /* y device resolution of the font and the point    */
  277.                /* size                        */
  278.  
  279.        for ( i = 0, cDBCSFonts = 0L; i < (INT)cFonts; i++ )
  280.        if (    (pfm[i].sXDeviceRes == (SHORT)lXDeviceRes) && (pfm[i].sYDeviceRes == (SHORT)lYDeviceRes) &&
  281.         (pfm[i].fsType & FM_TYPE_MBCS) && !(pfm[i].fsType & FM_TYPE_FIXED) )
  282.            ++cDBCSFonts;
  283.  
  284.        DosAllocMem((PPVOID)(PVOID)&pfmDBCS, (ULONG)(sizeof(FONTMETRICS)    * cDBCSFonts), PAG_READ    | PAG_WRITE | PAG_COMMIT);
  285.  
  286.                /* Loop through the font    metrics    returned to    */
  287.                /* locate the desired font by matching the x and    */
  288.                /* y device resolution of the font and the point    */
  289.                /* size                        */
  290.  
  291.        for ( i = n = 0;    i < (INT)cFonts; i++ )
  292.        if (    (pfm[i].sXDeviceRes == (SHORT)lXDeviceRes) && (pfm[i].sYDeviceRes == (SHORT)lYDeviceRes) &&
  293.         (pfm[i].fsType & FM_TYPE_MBCS) && !(pfm[i].fsType & FM_TYPE_FIXED) )
  294.            pfmDBCS[n++] = pfm[i];
  295.  
  296.                /* Adjust the point size    to correspond to the    */
  297.                /* the nominal point size that is contained    */
  298.                /* within the font metrics structure        */
  299.  
  300.        lPoints = *plPoints * 10L;
  301.  
  302.                /* Loop through the font    metrics    returned to    */
  303.                /* locate the desired font by matching the x and    */
  304.                /* y device resolution of the font and the point    */
  305.                /* size                        */
  306.  
  307.        for ( i = 0; i <    (INT)cDBCSFonts; i++ )
  308.        if (    pfmDBCS[i].sNominalPointSize ==    lPoints    )
  309.            {
  310.                /* Font found, get the match value to allow the    */
  311.                /* exact    font to    be selected by the calling    */
  312.                /* application                    */
  313.  
  314.            strcpy(pszFacename, pfmDBCS[i].szFacename);
  315.            lMatch =    pfmDBCS[i].lMatch;
  316.            }
  317.                /* Font of specified size not found, check to    */
  318.                /* see if any DBCS fonts    defined    in which case    */
  319.                /* select the first font                */
  320.        if ( cDBCSFonts )
  321.        {
  322.        strcpy(pszFacename, pfmDBCS[0].szFacename);
  323.        *plPoints = pfmDBCS[0].sNominalPointSize / 10L;
  324.        lMatch = pfmDBCS[0].lMatch;
  325.        }
  326.        else
  327.                /* No DBCS fonts    defined, select    the first    */
  328.                /* raster font to use                */
  329.        {
  330.        strcpy(pszFacename, pfm[0].szFacename);
  331.        *plPoints = pfm[0].sNominalPointSize    / 10L;
  332.        lMatch = pfm[0].lMatch;
  333.        }
  334.        }
  335.  
  336. DosFreeMem((PVOID)pfm);
  337. DosFreeMem((PVOID)pfmDBCS);
  338.  
  339. return(lMatch);
  340. }
  341. #pragma    subtitle("   DBCS Support - DBCS Active Query Function")
  342. #pragma    page( )
  343.  
  344. /* --- fQueryDBCS -------------------------------------- [ Public ] ---    */
  345. /*                                    */
  346. /*     This function is    used to    query the DBCS vector and determine    */
  347. /*     if DBCS is active.                        */
  348. /*                                    */
  349. /*     Upon Entry:                            */
  350. /*                                    */
  351. /*     Nothing                                */
  352. /*                                    */
  353. /*     Upon Exit:                            */
  354. /*                                    */
  355. /*     QueryDBCS =  TRUE : Double Byte System                */
  356. /*         = FALSE : single Byte System                */
  357. /*                                    */
  358. /* --------------------------------------------------------------------    */
  359.  
  360. BOOL fQueryDBCS(VOID)
  361.  
  362. {
  363. CHAR szFacename[FACESIZE];       /* Font Facename Size        */
  364. LONG lPts = 8L;               /* Font Point Size            */
  365. register INT i,    n;           /* Loop Counters            */
  366.  
  367. if ( DosQueryDBCSEnv(8UL * sizeof(DBCSVECTOR), &cc, (PCHAR)aDBCSVector)    )
  368.    return(fDBCS    = FALSE);
  369. else
  370.    {
  371.    for ( i = 0;    i < 8; i++ )
  372.        if ( aDBCSVector[i].bLow    && aDBCSVector[i].bHigh    )
  373.        {
  374.        for ( n = (INT)aDBCSVector[i].bLow; n <= (INT)aDBCSVector[i].bHigh; n++ )
  375.            afLeadByte[n] = TRUE;
  376.        fDBCS = TRUE;
  377.        }
  378.        else
  379.        break;
  380.  
  381.    FindDBCSFont(szFacename, &lPts);
  382.    cFontNameSize = strlen(strcat(strcat(_ltoa(lPts, szFontNameSize, 10), "."), szFacename)) + 1;
  383.    return(fDBCS);
  384.    }
  385. }
  386. #pragma    subtitle("   DBCS Support - DBCS Lead Byte Query Function")
  387. #pragma    page( )
  388.  
  389. /* --- ulQueryCharDBCS --------------------------------- [ Public ] ---    */
  390. /*                                    */
  391. /*     This function is    used to    determine the nth byte type within a    */
  392. /*     DBCS string.                            */
  393. /*                                    */
  394. /*     Upon Entry:                            */
  395. /*                                    */
  396. /*     PSZ pszString; =    String to Scan                    */
  397. /*     INT n;          =    Character Index                    */
  398. /*                                    */
  399. /*     Upon Exit:                            */
  400. /*                                    */
  401. /*     ulQueryCharDBCS = TYPE_SBCS     : Single    Byte Character        */
  402. /*               = TYPE_DBCS_1ST : Double    Byte Lead Character    */
  403. /*               = TYPE_DBCS_2ND : Double    Byte Trail Character    */
  404. /*                                    */
  405. /* --------------------------------------------------------------------    */
  406.  
  407. ULONG ulQueryCharDBCS(const CHAR *pszString, INT n)
  408.  
  409. {
  410. ULONG ulDBCSType = TYPE_SBCS;       /* DBCS Type                */
  411. register INT i;               /* Loop Counter            */
  412.  
  413. for ( i    = 0; i <= n; i++ )
  414.    switch ( ulDBCSType )
  415.        {
  416.        case TYPE_SBCS :
  417.        case TYPE_DBCS_2ND :
  418.        ulDBCSType =    afLeadByte[pszString[i]];
  419.        break;
  420.  
  421.        case TYPE_DBCS_1ST :
  422.        ulDBCSType =    TYPE_DBCS_2ND;
  423.        break;
  424.        }
  425.  
  426. return(ulDBCSType);
  427. }
  428. #pragma    subtitle("   DBCS Support - DBCS strrchr Function")
  429. #pragma    page( )
  430.  
  431. /* --- strrchrDBCS ------------------------------------- [ Public ] ---    */
  432. /*                                    */
  433. /*     This function is    used to    replace    the strrchr( ) C function to    */
  434. /*     allow for DBCS character    string searches.            */
  435. /*                                    */
  436. /*     Upon Entry:                            */
  437. /*                                    */
  438. /*     const CHAR *p; =    String String Scan                */
  439. /*     INT       c; =    Character to Search For                */
  440. /*                                    */
  441. /*     Upon Exit:                            */
  442. /*                                    */
  443. /*     strrchrDBCS =  NULL : Character Not Found            */
  444. /*           =       : Address Where Character Located        */
  445. /*                                    */
  446. /* --------------------------------------------------------------------    */
  447.  
  448. PSZ strrchrDBCS(const CHAR *p, INT c)
  449.  
  450. {
  451. CHAR *pch;               /* Character    String Pointer        */
  452. ULONG ulDBCS;               /* DBCS Type    Holder            */
  453.  
  454. if ( !fDBCS )
  455.    return(strrchr(p, c));
  456. else
  457.    {
  458.    for ( pch = (CHAR *)(p + strlen(p));    pch != p; pch--    )
  459.        if ( *pch == (CHAR)c )
  460.        if (    (ulDBCS    = ulQueryCharDBCS(p, (INT)(pch - (CHAR *)p))) == TYPE_SBCS )
  461.            return(pch);
  462.        else
  463.            if ( ulDBCS == TYPE_DBCS_2ND )
  464.            --pch;
  465.  
  466.    return(NULL);
  467.    }
  468. }
  469. #pragma    subtitle("   DBCS Support - DBCS strchr Function")
  470. #pragma    page( )
  471.  
  472. /* --- strchrDBCS -----    -------------------------------- [ Public ] ---    */
  473. /*                                    */
  474. /*     This function is    used to    replace    the strchr( ) C    function to    */
  475. /*     allow for DBCS character    string searches.            */
  476. /*                                    */
  477. /*     Upon Entry:                            */
  478. /*                                    */
  479. /*     const CHAR *p; =    String String Scan                */
  480. /*     INT       c; =    Character to Search For                */
  481. /*                                    */
  482. /*     Upon Exit:                            */
  483. /*                                    */
  484. /*     strchrDBCS =  NULL : Character Not Found                */
  485. /*          =      : Address Where Character Located        */
  486. /*                                    */
  487. /* --------------------------------------------------------------------    */
  488.  
  489. PSZ strchrDBCS(const CHAR *p, INT c)
  490.  
  491. {
  492. CHAR  *pch;               /* Character    String Pointer        */
  493. ULONG ulDBCS;               /* DBCS Type    Holder            */
  494.  
  495. if ( !fDBCS )
  496.    return(strchr(p, c));
  497. else
  498.    {
  499.    for ( pch = (CHAR *)p; *pch;    pch++ )
  500.        if ( *pch == (CHAR)c )
  501.        if (    (ulDBCS    = ulQueryCharDBCS(p, (INT)(pch - (CHAR *)p))) == TYPE_SBCS )
  502.            return(pch);
  503.        else
  504.            if ( ulDBCS == TYPE_DBCS_1ST )
  505.            ++pch;
  506.  
  507.    return(NULL);
  508.    }
  509. }
  510. #pragma    subtitle("   DBCS Support - DBCS strchr Function")
  511. #pragma    page( )
  512.  
  513. /* --- struprDBCS -----    -------------------------------- [ Public ] ---    */
  514. /*                                    */
  515. /*     This function is    used to    replace    the strupr( ) C    function to    */
  516. /*     allow for DBCS character    string searches.            */
  517. /*                                    */
  518. /*     Upon Entry:                            */
  519. /*                                    */
  520. /*     CHAR *p;    = String To convert to Upper Case            */
  521. /*                                    */
  522. /*     Upon Exit:                            */
  523. /*                                    */
  524. /*     struprDBCS = String Address                    */
  525. /*                                    */
  526. /* --------------------------------------------------------------------    */
  527.  
  528. PSZ struprDBCS(CHAR *p)
  529.  
  530. {
  531.  
  532. if ( !fDBCS )
  533.    return(strupr(p));
  534. else
  535.    {
  536.    DosMapCase((ULONG)strlen(p),    &cc, p);
  537.    return(p);
  538.    }
  539. }
  540. #pragma    subtitle("   DBCS Support - DBCS strchr Function")
  541. #pragma    page( )
  542.  
  543. /* --- strchrDBCS -------------------------------------- [ Public ] ---    */
  544. /*                                    */
  545. /*     This function is    used to    replace    the strstr( ) C    function to    */
  546. /*     allow for DBCS character    string searches.            */
  547. /*                                    */
  548. /*     Upon Entry:                            */
  549. /*                                    */
  550. /*     CHAR *str1; = String To Search                    */
  551. /*     CHAR *str2; = String to Search For                */
  552. /*                                    */
  553. /*     Upon Exit:                            */
  554. /*                                    */
  555. /*     strstrDBCS =  NULL : String Address                */
  556. /*                                    */
  557. /* --------------------------------------------------------------------    */
  558.  
  559. PSZ strstrDBCS(const CHAR *str1, const CHAR *str2)
  560.  
  561. {
  562. INT   len1;               /* String 1 Length            */
  563. INT   len2;               /* String 2 Length            */
  564. ULONG ulDBCS;               /* DBCS Type    Holder            */
  565. register INT i,    j, k;           /* Index/Loop Counters        */
  566.  
  567. if ( !fDBCS )
  568.    return(strstr(str1, str2));
  569. else
  570.    {
  571.    if (    !(len2 = strlen(str2)) )
  572.        return((char *)str1);    /* return str1 if str2 empty */
  573.    if (    !(len1 = strlen(str1)) )
  574.        return(0);        /* return NULL if str1 empty */
  575.    i = 0;
  576.    for(    ; ; )
  577.        {
  578.        while ( (i < len1) && (str1[i] != str2[0]) )
  579.        if (    (ulDBCS    = ulQueryCharDBCS(str1,    i)) == TYPE_SBCS )
  580.            ++i;
  581.        else
  582.            if ( ulDBCS == TYPE_DBCS_1ST )
  583.            i +=    2;
  584.        if ( i >= len1 )
  585.        return(0);
  586.        j = 0;
  587.        k = i;
  588.        while ( (i < len1) && (j    < len2)    && (str1[i] == str2[j])    )
  589.        {
  590.        if (    (ulDBCS    = ulQueryCharDBCS(str1,    i)) == TYPE_SBCS )
  591.            ++i;
  592.        else
  593.            if ( ulDBCS == TYPE_DBCS_1ST )
  594.            i +=    2;
  595.  
  596.        if (    (ulDBCS    = ulQueryCharDBCS(str2,    j)) == TYPE_SBCS )
  597.            ++j;
  598.        else
  599.            if ( ulDBCS == TYPE_DBCS_1ST )
  600.            j +=    2;
  601.        }
  602.        if ( j == len2 )
  603.        return((PSZ)(str1 + k));
  604.        if ( i == len1 )
  605.        return(0);
  606.        }
  607.    }
  608. }
  609. #pragma    subtitle("   Support - Center Dialog Box Function")
  610. #pragma    page( )
  611.  
  612. /* --- CenterDlg --------------------------------------- [ Public ] ---    */
  613. /*                                    */
  614. /*     This function is    used to    centre a dialogue box about to be    */
  615. /*     displayed and select a particular entry field or    MLE.        */
  616. /*                                    */
  617. /*     Upon Entry:                            */
  618. /*                                    */
  619. /*     HWND hWnd;     =    Dialogue Window    Handle                */
  620. /*                                    */
  621. /*     Upon Exit:                            */
  622. /*                                    */
  623. /*     Nothing                                */
  624. /*                                    */
  625. /* --------------------------------------------------------------------    */
  626.  
  627. VOID CenterDlg(HWND hWnd)
  628.  
  629. {
  630. CHAR   szClass[64];           /* Class Name Holder            */
  631. HWND   hwndChild = hWnd;       /* Child Window Handle        */
  632. SWP    swp;               /* Screen Window Position Holder    */
  633. register LONG sCmd = QW_TOP;       /* Query Window Command        */
  634.  
  635. if ( fDBCS )
  636.    {
  637.    while ( (hwndChild =    WinQueryWindow(hwndChild, sCmd)) != (HWND)NULL )
  638.        {
  639.        WinQueryClassName(hwndChild, 64L, szClass);
  640.  
  641.                /* Check    to see if the class of the control is a    */
  642.                /* spin button in which case, the search    much    */
  643.                /* broaden to the childen of the    spin button,    */
  644.                /* namely the entry field            */
  645.  
  646.        if ( !memcmp(szClass, PMCLASS_SPINBUTTON, PMCLASS_LEN_SPINBUTTON) ||
  647.         !memcmp(szClass, PMCLASS_MLE,     PMCLASS_LEN_MLE)     ||
  648.         !memcmp(szClass, PMCLASS_COMBOBOX,     PMCLASS_LEN_COMBOBOX)     ||
  649.         !memcmp(szClass, PMCLASS_ENTRYFIELD, PMCLASS_LEN_ENTRYFIELD) ||
  650.         !memcmp(szClass, PMCLASS_LISTBOX,     PMCLASS_LEN_LISTBOX) )
  651.        WinSetPresParam(hwndChild, PP_FONTNAMESIZE, cFontNameSize, (PVOID)szFontNameSize);
  652.  
  653.        sCmd = QW_NEXT;
  654.        }
  655.    }
  656.  
  657. WinQueryWindowPos(hWnd,    (PSWP)&swp);
  658. WinSetWindowPos(hWnd, HWND_TOP,    (WinQuerySysValue(HWND_DESKTOP,    SV_CXSCREEN) - swp.cx) / 2L,
  659.         (WinQuerySysValue(HWND_DESKTOP,    SV_CYSCREEN) - swp.cy) / 2L, 0L, 0L, SWP_MOVE);
  660. }
  661.  
  662.