home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / ezbar32.zip / BARDEMO.C next >
C/C++ Source or Header  |  1995-09-24  |  29KB  |  1,037 lines

  1. // bardemo.c v2.0 32-bit for Windows 95
  2. // Copyright (c) 1995 Bokai Corporation
  3.  
  4. #include "windows.h"
  5. #include "commdlg.h"
  6. #include "stdlib.h"
  7. #include "string.h"
  8.  
  9. #include "resource.h"
  10. #include "easybar.h"
  11.  
  12. typedef struct tagLONGSTRING
  13. {
  14.     long    id;
  15.     char    *szName;
  16.  
  17. } LONGSTRING;
  18.  
  19. LONGSTRING g_styles[] =
  20. {
  21.     BDF_LEFT,"Left"
  22.     ,BDF_RIGHT, "Right"
  23.     ,BDF_TOP, "Top"
  24.     ,BDF_BOTTOM, "Bottom"
  25.     ,BDF_CENTER, "Center"
  26.     ,BDF_VCENTER, "VCenter"
  27.     ,BDF_HIDEMAINTEXT, "HideMainText"
  28.     ,BDF_HIDEADDONTEXT, "HideAddOnText"
  29.     ,BDF_ADDONTEXTATTOP, "AddOnTextAtTop"
  30.     ,BDF_ADDONTEXTATBOTTOM, "AddOnTextAtBottom"
  31.     ,BDF_MAINTEXTATTOP, "MainTextAtTop"
  32.     ,BDF_MAINTEXTATBOTTOM, "MainTextAtBottom"
  33.     ,BDF_NOUPCSMALLFONT, "NoUpcSmallFont"
  34.     ,BDF_NOSTRETCHTEXT, "NoStretchText"
  35.     ,BDF_UNIBARHEIGHT, "UniBarHeight"
  36.     ,BDF_RETAINASPECTRATIO, "RetainAspectRatio"
  37.     ,BDF_NOPIXELALIGN, "NoPixelAlign"
  38.     ,BDF_CALCSIZEONLY, "CalcSizeOnly"
  39.     ,BDF_SHOWCODE39STARTSTOP, "ShowCode39StartStop"
  40.     ,BDF_WYSIWYGEXCLCOLOR, "WysiwygExclColor"
  41. };
  42.  
  43. HBARCODE     g_hbar = 0;
  44. RECT        g_rcCanvas;
  45. RECT        g_rc;
  46. int            g_iOrient = 0;
  47. DWORD        g_style = 0;
  48. int            g_iType = 0;
  49. LOGFONT        g_logfont;
  50. char        g_tmp[100];
  51. COLORREF    g_clfFg;
  52. COLORREF    g_clfBg;
  53. int            g_iBkMode;
  54. HGLOBAL        g_hDevMode = 0;
  55. HGLOBAL        g_hDevNames = 0;
  56. HDC            g_hPrintDC = 0;
  57. BOOL        g_bUserAbort = FALSE;
  58. HWND        g_hPrintDlg = 0;
  59. BOOL        g_bInvalidData1 = FALSE;
  60. BOOL        g_bInvalidData2 = FALSE;
  61. unsigned int    g_uStyle = 0;
  62.  
  63. #define HT_INSIDE        1
  64. #define HT_LEFT            2
  65. #define HT_RIGHT        3
  66. #define HT_TOP            4
  67. #define HT_BOTTOM        5
  68. #define HT_LEFTTOP        6
  69. #define HT_RIGHTTOP        7
  70. #define HT_RIGHTBOTTOM    8
  71. #define HT_LEFTBOTTOM    9
  72.  
  73. LRESULT APIENTRY WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  74. BOOL APIENTRY AboutDlgProc(HWND hwnd, UINT msg, 
  75.                             WPARAM wParam, LPARAM lParam);
  76. BOOL APIENTRY AdvancedDlgProc(HWND hwnd, UINT msg, 
  77.                             WPARAM wParam, LPARAM lParam);
  78. BOOL APIENTRY AbortProc(HDC hdcPrint, short sCode);
  79. BOOL APIENTRY PrintDlgProc(HWND hDlg, UINT msg, 
  80.                             WPARAM wParam, LPARAM lParam);
  81. static void drawBarcode(HWND hwnd, HDC hdc, HDC hicTarget, 
  82.                 HBARCODE hBar, LPRECT lprc);
  83. static void printBarcode(HWND hwnd, HDC hdcPrint, 
  84.                 HBARCODE hBar, LPRECT lprc);
  85. static long cmdProc(HWND hwnd, WPARAM wParam, LPARAM lParam);
  86. static void XORDottedFrame (HDC hdc, LPRECT prc);
  87. static DWORD getStyle(HWND hwnd);
  88. static int hitTest(int x, int y, LPRECT lprc);
  89.  
  90. int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance, 
  91.                 LPSTR lpszCmdLine, int nCmdShow)
  92. {
  93.     static char szAppName[] = "Easybar";
  94.     HWND    hwnd;            
  95.     MSG        msg;                                    
  96.     
  97.     if (!hPrevInstance)
  98.     {
  99.         WNDCLASS    cs;
  100.         
  101.         cs.style = CS_HREDRAW | CS_VREDRAW;
  102.         cs.lpfnWndProc = WndProc;
  103.         cs.cbClsExtra = 0;
  104.         cs.cbWndExtra = DLGWINDOWEXTRA;
  105.         cs.hInstance = hInstance;
  106.         cs.hIcon = LoadIcon(hInstance, "BARDEMO");
  107.         cs.hCursor = NULL; //LoadCursor(hInstance, IDC_ARROW);
  108.         cs.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  109.         cs.lpszMenuName = NULL;
  110.         cs.lpszClassName = szAppName;
  111.  
  112.         RegisterClass(&cs);
  113.     }
  114.  
  115.     hwnd = CreateDialog(hInstance, szAppName, 0, NULL);
  116.     
  117.     ShowWindow(hwnd, nCmdShow);
  118.     UpdateWindow(hwnd);
  119.     
  120.     while(GetMessage(&msg, NULL, 0, 0))
  121.     {
  122.         if (!IsDialogMessage(hwnd, &msg))
  123.         {
  124.             TranslateMessage(&msg);
  125.             DispatchMessage(&msg);
  126.         }
  127.     }
  128.  
  129.     return msg.wParam;
  130. }
  131.  
  132. LRESULT APIENTRY WndProc(HWND hwnd, UINT msg, 
  133.                             WPARAM wParam, LPARAM lParam)
  134. {                        
  135.     HWND        hctl;                  
  136.     int            iType;          
  137.     int            i, ind;
  138.     LPSTR        lp;                             
  139.     PAINTSTRUCT    ps;
  140.     HDC            hdc;
  141.     HFONT        hFont, hFont0;
  142.     HBRUSH        hBrush;
  143.     static PRINTDLG        pd;
  144.     static        bInitialized = FALSE;
  145.     static        nDrag = 0;  
  146.     static POINT    pt;
  147.     static RECT        rcPrev;     
  148.     static TEXTMETRIC    tm;
  149.     
  150.     switch(msg) {                                   
  151.     case WM_CREATE:
  152.         memset(&pd, 0, sizeof(pd));
  153.         pd.lStructSize = sizeof(pd);
  154.         pd.hwndOwner = hwnd;
  155.         pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT;
  156.         if (PrintDlg(&pd)) 
  157.         {
  158.             g_hPrintDC = pd.hDC;
  159.             g_hDevMode = pd.hDevMode;
  160.             g_hDevNames = pd.hDevNames;
  161.         }
  162.         return 0;
  163.     case WM_MOVE:
  164.         if (bInitialized) break;
  165.         bInitialized = TRUE;
  166.         g_hbar = 0;
  167.         for (i = 0; (i = EnumBarcodeTypes(i, &iType, &lp)) != 0; )
  168.         {
  169.             ind = (int)SendDlgItemMessage(hwnd, IDC_BARCODE, CB_ADDSTRING, 
  170.                                         0, (LONG)lp);
  171.             SendDlgItemMessage(hwnd, IDC_BARCODE, CB_SETITEMDATA, 
  172.                                         ind, (LONG)iType);
  173.         }
  174.         SendDlgItemMessage(hwnd, IDC_BARCODE, CB_SETCURSEL, 0, 0);
  175.            iType = (int) SendDlgItemMessage(hwnd, IDC_BARCODE, 
  176.                         CB_GETITEMDATA, (WPARAM)0, (LPARAM)0);
  177.         g_hbar = BarCreate(iType, g_uStyle);
  178.         g_iType = iType;
  179.  
  180.         BarGetData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
  181.         SendDlgItemMessage(hwnd, IDC_DATA, WM_SETTEXT, 0, 
  182.                 (LONG)(LPSTR)g_tmp);
  183.  
  184.         BarGetAddOnData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
  185.         if (!g_tmp[0])
  186.         {
  187.             EnableWindow(GetDlgItem(hwnd, IDC_ADDONDATA), FALSE);
  188.             EnableWindow(GetDlgItem(hwnd, IDC_ADDONMESG), FALSE);
  189.         }
  190.         else
  191.         {
  192.             SendDlgItemMessage(hwnd, IDC_ADDONDATA, WM_SETTEXT, 0, 
  193.                 (LONG)(LPSTR)g_tmp);
  194.         }
  195.         
  196.         SendDlgItemMessage(hwnd, IDC_ORIENT, CB_ADDSTRING, 0, (LONG)(LPSTR)"0");
  197.         SendDlgItemMessage(hwnd, IDC_ORIENT, CB_ADDSTRING, 0, (LONG)(LPSTR)"90");
  198.         SendDlgItemMessage(hwnd, IDC_ORIENT, CB_ADDSTRING, 0, (LONG)(LPSTR)"180");
  199.         SendDlgItemMessage(hwnd, IDC_ORIENT, CB_ADDSTRING, 0, (LONG)(LPSTR)"270");
  200.         SendDlgItemMessage(hwnd, IDC_ORIENT, CB_SETCURSEL, 0, 0);
  201.         g_iOrient = 0;
  202.  
  203.         for (i = 0; i < sizeof(g_styles) / sizeof(g_styles[0]); i++)
  204.         {
  205.             ind = (int) SendDlgItemMessage(hwnd, IDC_STYLE, LB_ADDSTRING, 
  206.                     (WPARAM)0, (LONG)(LPSTR)(g_styles[i].szName));
  207.             SendDlgItemMessage(hwnd, IDC_STYLE, LB_SETITEMDATA,
  208.                     (WPARAM)ind, (LPARAM)g_styles[i].id);
  209.         }
  210.  
  211.         // init font
  212.         hdc = GetDC(hwnd);   
  213.         hFont0 = SelectObject(hdc, GetStockObject(DEVICE_DEFAULT_FONT));
  214.         GetObject(hFont0, sizeof(g_logfont), (LPSTR)&g_logfont);
  215.         strcpy(g_logfont.lfFaceName, "Arial");
  216.         g_logfont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
  217.         g_logfont.lfClipPrecision = CLIP_TT_ALWAYS;
  218.         g_logfont.lfWidth = 0;
  219.         hFont = CreateFontIndirect(&g_logfont);
  220.         SelectObject(hdc, hFont);
  221.         GetTextFace(hdc, LF_FACESIZE, g_logfont.lfFaceName);
  222.         GetTextMetrics(hdc, &tm);
  223.         if (tm.tmHeight < 0)
  224.             i = tm.tmHeight;
  225.         else
  226.             i = -(tm.tmHeight - tm.tmInternalLeading);
  227.         g_logfont.lfHeight = i;
  228.         wsprintf(g_tmp, "%d", MulDiv(-i, 72, GetDeviceCaps(hdc, LOGPIXELSY)));
  229.         SetWindowText(GetDlgItem(hwnd, IDC_POINT), g_tmp);
  230.         SetWindowText(GetDlgItem(hwnd, IDC_FONTNAME), g_logfont.lfFaceName);
  231.         SelectObject(hdc, hFont0);
  232.         DeleteObject(hFont);
  233.  
  234.         // init color
  235.         g_clfFg = GetTextColor(hdc);
  236.         g_clfBg = GetBkColor(hdc);
  237.         g_iBkMode = GetBkMode(hdc);
  238.         if (g_iBkMode == TRANSPARENT) 
  239.             SendDlgItemMessage(hwnd, IDC_TRANSPARENT, BM_SETCHECK, 1, 0);
  240.         else
  241.             SendDlgItemMessage(hwnd, IDC_TRANSPARENT, BM_SETCHECK, 0, 0);
  242.         
  243.         ReleaseDC(hwnd, hdc);
  244.  
  245.         hctl = GetDlgItem(hwnd, IDC_CANVAS);
  246.         GetWindowRect(hctl, &g_rcCanvas);
  247.         g_rcCanvas.right += 5;
  248.         g_rcCanvas.bottom += 5;
  249.         ScreenToClient(hwnd, (LPPOINT)&g_rcCanvas);
  250.         ScreenToClient(hwnd, ((LPPOINT)&g_rcCanvas) + 1);
  251.         MoveWindow(hctl, g_rcCanvas.left, g_rcCanvas.top,
  252.                 g_rcCanvas.right - g_rcCanvas.left,
  253.                 g_rcCanvas.bottom - g_rcCanvas.top, FALSE);
  254.         InflateRect(&g_rcCanvas, -1, -1);
  255.         CopyRect(&g_rc, &g_rcCanvas);
  256.         InflateRect(&g_rc, -(g_rcCanvas.right - g_rcCanvas.left) / 8,
  257.                     -(g_rcCanvas.bottom - g_rcCanvas.top) / 4);
  258.         InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  259.         SetFocus(GetDlgItem(hwnd, IDC_BARCODE));
  260.         return 0;
  261.     case WM_PAINT:
  262.         hdc = BeginPaint(hwnd, &ps);          
  263.         IntersectClipRect(hdc, g_rcCanvas.left, g_rcCanvas.top,
  264.                     g_rcCanvas.right, g_rcCanvas.bottom);
  265.         // draw bg
  266.         hBrush = SelectObject(hdc, 
  267.                     CreateSolidBrush(RGB(255, 255, 232)));
  268.         PatBlt(hdc, g_rcCanvas.left, g_rcCanvas.top, 
  269.                 g_rcCanvas.right - g_rcCanvas.left,
  270.                 g_rcCanvas.bottom - g_rcCanvas.top, PATCOPY);
  271.         DeleteObject(SelectObject(hdc, hBrush));
  272.  
  273.         if (g_bInvalidData1 || g_bInvalidData2)
  274.         {
  275.             DrawText(hdc, "Invalid Data!", -1, &g_rcCanvas,
  276.                     DT_SINGLELINE | DT_CENTER | DT_VCENTER);
  277.         }
  278.         else
  279.         {
  280.             if (SendDlgItemMessage(hwnd, IDC_WYSIWYG,
  281.                         BM_GETCHECK, 0, 0) == 0)
  282.                 drawBarcode(hwnd, hdc, 0, g_hbar, &g_rc);
  283.             else
  284.                 drawBarcode(hwnd, hdc, g_hPrintDC, g_hbar, &g_rc);
  285.         
  286.             XORDottedFrame (hdc, &g_rc);
  287.         }
  288.         EndPaint(hwnd, &ps);
  289.         return 0;                             
  290.     case WM_MOUSEMOVE:  
  291.         if (!nDrag)
  292.         {
  293.             pt.x = LOWORD(lParam);
  294.             pt.y = HIWORD(lParam);
  295.             if (!PtInRect(&g_rcCanvas, pt)) 
  296.             {
  297.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
  298.                 break;
  299.             }
  300.  
  301.             i = hitTest(LOWORD(lParam), HIWORD(lParam), &g_rc);
  302.             switch (i) {
  303.             case HT_LEFT:
  304.             case HT_RIGHT:
  305.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
  306.                 break;
  307.             case HT_TOP:
  308.             case HT_BOTTOM:
  309.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS)));
  310.                 break;
  311.             case HT_LEFTTOP:
  312.             case HT_RIGHTBOTTOM:
  313.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
  314.                 break;
  315.             case HT_LEFTBOTTOM:
  316.             case HT_RIGHTTOP:
  317.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENESW)));
  318.                 break;
  319.             case HT_INSIDE:
  320.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZE)));
  321.                 break;
  322.             default:
  323.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
  324.             }
  325.         }
  326.         else
  327.         {
  328.             hdc = GetDC(hwnd);       
  329.             XORDottedFrame(hdc, &rcPrev);
  330.             switch (nDrag) {
  331.             case HT_LEFT:
  332.                 rcPrev.left = g_rc.left + LOWORD(lParam) - pt.x;
  333.                 break;
  334.             case HT_RIGHT:
  335.                 rcPrev.right = g_rc.right + LOWORD(lParam) - pt.x;
  336.                 break;
  337.             case HT_TOP:
  338.                 rcPrev.top = g_rc.top + HIWORD(lParam) - pt.y;
  339.                 break;
  340.             case HT_BOTTOM:
  341.                 rcPrev.bottom = g_rc.bottom + HIWORD(lParam) - pt.y;
  342.                 break;
  343.             case HT_LEFTTOP:
  344.                 rcPrev.left = g_rc.left + LOWORD(lParam) - pt.x;
  345.                 rcPrev.top = g_rc.top + HIWORD(lParam) - pt.y;
  346.                 break;
  347.             case HT_RIGHTBOTTOM:
  348.                 rcPrev.right = g_rc.right + LOWORD(lParam) - pt.x;
  349.                 rcPrev.bottom = g_rc.bottom + HIWORD(lParam) - pt.y;
  350.                 break;
  351.             case HT_LEFTBOTTOM:
  352.                 rcPrev.left = g_rc.left + LOWORD(lParam) - pt.x;
  353.                 rcPrev.bottom = g_rc.bottom + HIWORD(lParam) - pt.y;
  354.                 break;
  355.             case HT_RIGHTTOP:
  356.                 rcPrev.right = g_rc.right + LOWORD(lParam) - pt.x;
  357.                 rcPrev.top = g_rc.top + HIWORD(lParam) - pt.y;
  358.                 break;
  359.             case HT_INSIDE:              
  360.                 CopyRect(&rcPrev, &g_rc);
  361.                 OffsetRect(&rcPrev, LOWORD(lParam) - pt.x,
  362.                             HIWORD(lParam) - pt.y);
  363.                 break;
  364.             default:
  365.                 ;
  366.             }
  367.             XORDottedFrame(hdc, &rcPrev);
  368.             ReleaseDC(hwnd, hdc);
  369.         }
  370.         return 0;
  371.     case WM_LBUTTONDOWN:
  372.         pt.x = LOWORD(lParam);
  373.         pt.y = HIWORD(lParam);
  374.         if (!PtInRect(&g_rcCanvas, pt)) break;
  375.         nDrag = hitTest(pt.x, pt.y, &g_rc);
  376.         if (nDrag)
  377.         {                 
  378.             SetCapture(hwnd);
  379.             CopyRect(&rcPrev, &g_rcCanvas);
  380.             ClientToScreen(hwnd, (LPPOINT)&rcPrev);
  381.             ClientToScreen(hwnd, ((LPPOINT)&rcPrev) + 1);
  382.             ClipCursor(&rcPrev);
  383.             CopyRect(&rcPrev, &g_rc);
  384.             hdc = GetDC(hwnd);       
  385.             XORDottedFrame(hdc, &rcPrev);
  386.             ReleaseDC(hwnd, hdc);
  387.         }
  388.         return 0;        
  389.     case WM_LBUTTONUP:                               
  390.         if (GetCapture() == hwnd)
  391.         {
  392.             if (rcPrev.left > rcPrev.right)
  393.             {
  394.                 i = rcPrev.left; rcPrev.left = rcPrev.right; rcPrev.right = i;
  395.             }
  396.             if (rcPrev.top > rcPrev.bottom)
  397.             {
  398.                 i = rcPrev.top; rcPrev.top = rcPrev.bottom; rcPrev.bottom = i;
  399.             }
  400.             nDrag = 0;
  401.             ClipCursor(NULL);
  402.             ReleaseCapture();
  403.             hdc = GetDC(hwnd);       
  404.             XORDottedFrame(hdc, &rcPrev);
  405.             ReleaseDC(hwnd, hdc);
  406.             if (!EqualRect(&rcPrev, &g_rc))
  407.             {
  408.                 CopyRect(&g_rc, &rcPrev);
  409.                 InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  410.             }
  411.             return 0;
  412.         }
  413.         break;               
  414.     case WM_SETFOCUS:
  415.         SetFocus(GetDlgItem(hwnd, IDC_BARCODE));
  416.         return 0;
  417.     case WM_COMMAND:
  418.         return cmdProc(hwnd, wParam, lParam);
  419.     case WM_CLOSE:
  420.         break;
  421.     case WM_DESTROY:           
  422.         if (g_hbar) BarDestroy(g_hbar);
  423.         if (g_hPrintDC) DeleteDC(g_hPrintDC);
  424.         if (g_hDevMode) GlobalFree(g_hDevMode);
  425.         if (g_hDevNames) GlobalFree(g_hDevNames);
  426.         PostQuitMessage(0);
  427.         return 0;
  428. /*
  429.     case WM_CTLCOLORSTATIC:
  430.         return (LRESULT) (HBRUSH) (COLOR_BTNFACE + 1);
  431. */
  432.     }
  433.     
  434.     return DefWindowProc(hwnd, msg, wParam, lParam);
  435. }
  436.  
  437. static int hitTest(int x, int y, LPRECT lprc)
  438. {                                    
  439.     int        d = 2;
  440.     int        n;
  441.  
  442.     if (x < lprc->left - d)
  443.         return 0;
  444.     else if (x <= lprc->left + d)
  445.         n = HT_LEFT;
  446.     else if (x < lprc->right - d)
  447.         n = HT_INSIDE;
  448.     else if (x <= lprc->right + d)
  449.         n = HT_RIGHT;
  450.     else
  451.         return 0;
  452.     
  453.     if (y < lprc->top - d)
  454.         return 0;
  455.     else if (y <= lprc->top + d)
  456.         switch (n) {
  457.         case HT_LEFT:
  458.             n = HT_LEFTTOP; break;
  459.         case HT_RIGHT:
  460.             n = HT_RIGHTTOP; break;
  461.         default:
  462.             n = HT_TOP;
  463.         }
  464.     else if (y < lprc->bottom - d)
  465.         ;
  466.     else if (y <= lprc->bottom + d)
  467.         switch (n) {
  468.         case HT_LEFT:
  469.             n = HT_LEFTBOTTOM; break;
  470.         case HT_RIGHT:
  471.             n = HT_RIGHTBOTTOM; break;
  472.         default:
  473.             n = HT_BOTTOM;
  474.         }
  475.     else
  476.         return 0;
  477.     
  478.     return n;
  479. }
  480.  
  481. static void XORDottedFrame (HDC hdc, LPRECT prc)
  482. {
  483.     HPEN    hp;
  484.     int        r2;
  485.     int        m;
  486.  
  487.     r2 = SetROP2(hdc, R2_NOTXORPEN);
  488.     hp = SelectObject(hdc, CreatePen (PS_DOT, 0, RGB (0, 0, 0)));
  489.        m = SetBkMode(hdc, TRANSPARENT);
  490.     MoveToEx(hdc, prc->left - 1, prc->top - 1, NULL);
  491.     LineTo(hdc, prc->right, prc->top - 1); 
  492.     LineTo(hdc, prc->right, prc->bottom);
  493.     LineTo(hdc, prc->left - 1, prc->bottom);
  494.     LineTo(hdc, prc->left - 1, prc->top - 1);
  495.     DeleteObject(SelectObject(hdc, hp));
  496.     SetROP2(hdc, r2);
  497.        SetBkMode(hdc, m);
  498. }
  499.  
  500. static long cmdProc(HWND hwnd, WPARAM wParam, LPARAM lParam)
  501. {                                
  502.     int            iType;
  503.     static char    buf[64];
  504.     static char    buf2[64];
  505.     DWORD        dwIndex;             
  506.     FARPROC        lpfnDlgProc;                              
  507.     HINSTANCE    hInst;
  508.     static CHOOSEFONT    cf;
  509.     static CHOOSECOLOR    cc;
  510.     static PRINTDLG        pd;
  511.     static DWORD        dwCustColors[16];
  512.     HWND        hCtl;
  513.     RECT        rc;
  514.     
  515.     switch (LOWORD(wParam)) {
  516.     case IDC_ABOUT:
  517.         hInst = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE);
  518.         lpfnDlgProc = MakeProcInstance((FARPROC)AboutDlgProc, hInst);
  519.         DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hwnd, lpfnDlgProc);
  520.         FreeProcInstance(lpfnDlgProc);
  521.         return 0;
  522.     case IDC_BTNFONT:
  523.         memset(&cf, 0, sizeof(cf));
  524.         cf.lStructSize = sizeof(CHOOSEFONT);
  525.         cf.hwndOwner = hwnd;
  526.         cf.lpLogFont = &g_logfont;
  527.         cf.iPointSize = 0;
  528.         cf.rgbColors = g_clfFg;
  529.         cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_EFFECTS;
  530.         if (g_hPrintDC) 
  531.         {
  532.             if (!g_hPrintDC) MessageBeep(0);
  533.             cf.hDC = g_hPrintDC;
  534.             cf.Flags |= CF_PRINTERFONTS;
  535.         }
  536.         if (ChooseFont(&cf))
  537.         {
  538.             SetWindowText(GetDlgItem(hwnd, IDC_FONTNAME), 
  539.                     g_logfont.lfFaceName);
  540.             wsprintf(buf, "%d", cf.iPointSize / 10);
  541.             if (cf.iPointSize % 10 > 0)
  542.                 wsprintf(buf + strlen(buf), ".%d", cf.iPointSize % 10);
  543.             SetWindowText(GetDlgItem(hwnd, IDC_POINT), buf);
  544.             g_clfFg = cf.rgbColors;
  545.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  546.         }
  547.         return 0;
  548.     case IDC_BG:
  549.         memset(&cc, 0, sizeof(cc));
  550.         cc.lStructSize = sizeof(CHOOSECOLOR);
  551.         cc.hwndOwner = hwnd;
  552.         cc.rgbResult = g_clfBg;
  553.         cc.Flags = CC_PREVENTFULLOPEN | CC_RGBINIT;
  554.         cc.lpCustColors = dwCustColors;
  555.         if (ChooseColor(&cc))
  556.         {
  557.             g_clfBg = cc.rgbResult;
  558.             SendDlgItemMessage(hwnd, IDC_TRANSPARENT, BM_SETCHECK, 0, 0);
  559.             g_iBkMode = OPAQUE;
  560.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  561.         }
  562.         return 0;
  563.     case IDC_PRINT:
  564.         memset(&pd, 0, sizeof(pd));
  565.         pd.lStructSize = sizeof(pd);
  566.         pd.hwndOwner = hwnd;
  567.         pd.nFromPage = pd.nToPage = 1;
  568.         pd.nMinPage = pd.nMaxPage = 1;
  569.         pd.Flags = PD_NOSELECTION | PD_ALLPAGES 
  570.                     | PD_RETURNDC | PD_USEDEVMODECOPIES;
  571.         pd.hDevMode = g_hDevMode;
  572.         pd.hDevNames = g_hDevNames;
  573.         if (PrintDlg(&pd)) 
  574.         {
  575.             if (g_hPrintDC) DeleteDC(g_hPrintDC);
  576.             g_hPrintDC = pd.hDC;
  577.             g_hDevMode = pd.hDevMode;
  578.             g_hDevNames = pd.hDevNames;
  579.             CopyRect(&rc, &g_rc);
  580.             OffsetRect(&rc, -g_rcCanvas.left, -g_rcCanvas.top);
  581.             printBarcode(hwnd, g_hPrintDC, g_hbar, &rc);
  582.             // TODO: if WYSIWYG, refresh
  583.         }
  584.         else
  585.         {
  586.             g_hDevMode = pd.hDevMode;
  587.             g_hDevNames = pd.hDevNames;
  588.         }
  589.         // printer config may have changed
  590.         InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  591.         return 0;
  592.     case IDC_TRANSPARENT:
  593.         if (HIWORD(wParam) == BN_CLICKED)
  594.         {
  595.             if (SendDlgItemMessage(hwnd, IDC_TRANSPARENT,
  596.                         BM_GETCHECK, 0, 0) == 0)
  597.                 g_iBkMode = OPAQUE;
  598.             else
  599.                 g_iBkMode = TRANSPARENT;
  600.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  601.             return 0;
  602.         }
  603.         break;
  604.     case IDC_WYSIWYG:
  605.         if (HIWORD(wParam) == BN_CLICKED)
  606.         {
  607.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  608.             return 0;
  609.         }
  610.         break;
  611.     case IDC_BARCODE:
  612.         if (HIWORD(wParam) == CBN_SELCHANGE)
  613.         {
  614.             dwIndex = SendDlgItemMessage(hwnd, IDC_BARCODE, CB_GETCURSEL, 0, 0);
  615.             iType = (int) SendDlgItemMessage(hwnd, IDC_BARCODE, 
  616.                         CB_GETITEMDATA, (WPARAM)dwIndex, (LPARAM)0);
  617.             if (g_hbar && g_iType == iType) return 0;
  618.             if (g_hbar) BarDestroy(g_hbar);
  619.             g_iType = iType;
  620.             g_hbar = BarCreate(iType, g_uStyle);
  621.             SetWindowText(GetDlgItem(hwnd, IDC_MESSAGE), "");
  622.             SetWindowText(GetDlgItem(hwnd, IDC_ADDONMESG), "");
  623.  
  624.             BarGetData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
  625.             SendDlgItemMessage(hwnd, IDC_DATA, WM_SETTEXT, 0, 
  626.                 (LONG)(LPSTR)g_tmp);
  627.  
  628.             BarGetAddOnData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
  629.             if (!g_tmp[0])
  630.             {
  631.                 EnableWindow(GetDlgItem(hwnd, IDC_ADDONDATA), FALSE);
  632.                 EnableWindow(GetDlgItem(hwnd, IDC_ADDONMESG), FALSE);
  633.             }
  634.             else
  635.             {
  636.                 EnableWindow(GetDlgItem(hwnd, IDC_ADDONDATA), TRUE);
  637.                 EnableWindow(GetDlgItem(hwnd, IDC_ADDONMESG), TRUE);
  638.             }
  639.             SendDlgItemMessage(hwnd, IDC_ADDONDATA, WM_SETTEXT, 0, 
  640.                 (LONG)(LPSTR)g_tmp);
  641.  
  642.             g_bInvalidData1 = g_bInvalidData2 = FALSE;
  643.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  644.             return 0;
  645.         }   
  646.         break;
  647.     case IDC_STYLE:
  648.         if (HIWORD(wParam) == LBN_SELCHANGE)
  649.         {
  650.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  651.             return 0;
  652.         }   
  653.         break;
  654.     case IDC_ORIENT:
  655.         if (HIWORD(wParam) == CBN_SELCHANGE)
  656.         {
  657.             int    n;
  658.             dwIndex = SendDlgItemMessage(hwnd, IDC_ORIENT, CB_GETCURSEL, 0, 0);
  659.             SendDlgItemMessage(hwnd, IDC_ORIENT, CB_GETLBTEXT, 
  660.                     (WPARAM)dwIndex, (LPARAM)(LPSTR)buf);
  661.             n = atoi(buf);
  662.             if ((g_iOrient - n) % 180 != 0)
  663.             {
  664.                 int tmp;
  665.                 tmp = g_rc.left; g_rc.left = g_rc.top; g_rc.top = tmp;
  666.                 tmp = g_rc.right; g_rc.right = g_rc.bottom; g_rc.bottom = tmp;
  667.                 OffsetRect(&g_rc, -(g_rc.left - g_rcCanvas.left - 5),
  668.                             -(g_rc.top - g_rcCanvas.top - 5));
  669.             }
  670.             g_iOrient = n;
  671.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  672.             return 0;
  673.         }   
  674.         break;
  675.     case IDC_DATA:
  676.     case IDC_MESSAGE:
  677.         if (HIWORD(wParam) == EN_KILLFOCUS)
  678.         {
  679.             SendDlgItemMessage(hwnd, IDC_DATA, WM_GETTEXT, 
  680.                 sizeof(buf), (LPARAM)(LPSTR)buf);
  681.             SendDlgItemMessage(hwnd, IDC_MESSAGE, WM_GETTEXT, 
  682.                 sizeof(buf2), (LPARAM)(LPSTR)buf2);
  683.             if (g_hbar)
  684.             {
  685.                 g_bInvalidData1 = FALSE;
  686.                 if (buf[0] == 0)
  687.                 {
  688.                     BarGetData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
  689.                     SendDlgItemMessage(hwnd, IDC_DATA, WM_SETTEXT, 0, 
  690.                             (LONG)(LPSTR)g_tmp);
  691.                 }
  692.                 else if (!BarSetData(g_hbar, buf, lstrlen(buf), 
  693.                             buf2, lstrlen(buf2)))
  694.                 {
  695.                     g_bInvalidData1 = TRUE;
  696.                 }
  697.             }
  698.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  699.             return 0;
  700.         }   
  701.         break;
  702.     case IDC_ADDONDATA:
  703.     case IDC_ADDONMESG:
  704.         if (HIWORD(wParam) == EN_KILLFOCUS)
  705.         {
  706.             SendDlgItemMessage(hwnd, IDC_ADDONDATA, WM_GETTEXT, 
  707.                 sizeof(buf), (LPARAM)(LPSTR)buf);
  708.             SendDlgItemMessage(hwnd, IDC_ADDONMESG, WM_GETTEXT, 
  709.                 sizeof(buf2), (LPARAM)(LPSTR)buf2);
  710.             if (g_hbar)
  711.             {
  712.                 g_bInvalidData2 = FALSE;
  713.                 if (buf[0] == 0)
  714.                 {
  715.                     BarGetAddOnData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
  716.                     SendDlgItemMessage(hwnd, IDC_ADDONDATA, WM_SETTEXT, 0, 
  717.                             (LONG)(LPSTR)g_tmp);
  718.                 }
  719.                 else if (!BarSetAddOnData(g_hbar, buf, lstrlen(buf), 
  720.                         buf2, lstrlen(buf2)))
  721.                 {
  722.                     g_bInvalidData2 = TRUE;
  723.                 }
  724.             }
  725.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  726.             return 0;
  727.         }   
  728.         break;
  729.     case IDOK:
  730.         hCtl = GetFocus();
  731.         if (hCtl && (hCtl = GetNextDlgTabItem(hwnd, hCtl, FALSE)))
  732.             SetFocus(hCtl);
  733.         return 0;
  734.     case IDC_BTNADVANCED:
  735.         hInst = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE);
  736.         lpfnDlgProc = MakeProcInstance((FARPROC)AdvancedDlgProc, hInst);
  737.         if (DialogBox(hInst, MAKEINTRESOURCE(IDD_ADVANCED), hwnd, lpfnDlgProc))
  738.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  739.         FreeProcInstance(lpfnDlgProc);
  740.         return 0;
  741.     default:
  742.         break;
  743.     }
  744.  
  745.     return DefWindowProc(hwnd, WM_COMMAND, wParam, lParam);
  746. }
  747.  
  748. static DWORD getStyle(HWND hwnd)
  749. {
  750.     static int        ai[50];   
  751.     int        i, c;
  752.     DWORD    dw;
  753.  
  754.     c = (int)SendDlgItemMessage(hwnd, IDC_STYLE, LB_GETSELITEMS, 
  755.             (WPARAM)50, (LPARAM)(LPINT)ai);
  756.     dw = 0;        
  757.     for (i = 0; i < c; i++)
  758.         dw |= SendDlgItemMessage(hwnd, IDC_STYLE, LB_GETITEMDATA, 
  759.                     (WPARAM)ai[i], (LPARAM)0);
  760.  
  761.     return dw;
  762. }
  763.  
  764. static void drawBarcode(HWND hwnd, HDC hdc, HDC hicTarget, 
  765.                 HBARCODE hBar, LPRECT lprc)
  766. {
  767.     HFONT    hf, hf2;
  768.     LOGFONT    lf;                       
  769.     RECT    rc;
  770.  
  771.     if (!g_hbar || !hdc) return;
  772.  
  773.     if (!hicTarget)
  774.     {
  775.         SetBkMode(hdc, g_iBkMode); 
  776.         SetBkColor(hdc, g_clfBg); 
  777.         SetTextColor(hdc, g_clfFg);
  778.  
  779.         hf2 = CreateFontIndirect(&g_logfont);
  780.         hf = SelectObject(hdc, hf2);
  781.  
  782.         BarDraw(g_hbar, hdc, NULL, lprc, g_iOrient, getStyle(hwnd));
  783.             
  784.         SelectObject(hdc, hf);
  785.         DeleteObject(hf2);
  786.     }
  787.     else
  788.     {
  789.         SetBkMode(hicTarget, g_iBkMode); 
  790.         SetBkColor(hicTarget, g_clfBg); 
  791.         SetTextColor(hicTarget, g_clfFg);
  792.  
  793.         SetMapMode(hdc, MM_ANISOTROPIC);
  794.         SetWindowExtEx(hdc, 1440, 1440, NULL);
  795.         SetViewportExtEx(hdc, GetDeviceCaps(hdc, LOGPIXELSX),
  796.                     -GetDeviceCaps(hdc, LOGPIXELSY), NULL);
  797.         SetMapMode(hicTarget, MM_TWIPS);
  798.  
  799.         CopyRect(&rc, lprc);
  800.         DPtoLP(hdc, (LPPOINT)&rc, 2);
  801.  
  802.         // physical coord to logical
  803.         memcpy(&lf, &g_logfont, sizeof(lf));
  804.         lf.lfHeight = MulDiv(lf.lfHeight, 1440, 
  805.                         GetDeviceCaps(hdc, LOGPIXELSY));
  806.         lf.lfWidth = 0;
  807.         hf2 = CreateFontIndirect(&lf);
  808.         hf = SelectObject(hicTarget, hf2);
  809.  
  810.         BarDraw(g_hbar, hdc, hicTarget, &rc, g_iOrient, getStyle(hwnd));
  811.             
  812.         SetMapMode(hdc, MM_TEXT);
  813.         SetMapMode(hicTarget, MM_TEXT);
  814.  
  815.         SelectObject(hicTarget, hf);
  816.         DeleteObject(hf2);
  817.     }
  818. }
  819.  
  820. static void printBarcode(HWND hwnd, HDC hdcPrint, HBARCODE hBar, LPRECT lprc)
  821. {
  822.     HFONT    hf, hf2;
  823.     LOGFONT    lf;                       
  824.     RECT    rc;
  825.     HDC        hdcWnd;
  826.     FARPROC    lpfnPrintDlgProc;
  827.     FARPROC    lpfnAbortProc;
  828.     HINSTANCE    hInst = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE);
  829.     
  830.     if (!g_hbar || !hdcPrint) return;
  831.  
  832.     lpfnPrintDlgProc = MakeProcInstance((FARPROC)PrintDlgProc, hInst);
  833.     g_hPrintDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PRINTABORT),
  834.                     hwnd, lpfnPrintDlgProc);
  835.     lpfnAbortProc = MakeProcInstance((FARPROC)AbortProc, hInst);
  836.     Escape(hdcPrint, SETABORTPROC, 0, (LPSTR)lpfnAbortProc, NULL);
  837.  
  838.     SetBkMode(hdcPrint, g_iBkMode); 
  839.     SetBkColor(hdcPrint, g_clfBg); 
  840.     SetTextColor(hdcPrint, g_clfFg);
  841.  
  842.     hdcWnd = GetDC(hwnd);
  843.     SetMapMode(hdcWnd, MM_ANISOTROPIC);
  844.     SetWindowExtEx(hdcWnd, 1440, 1440, NULL);
  845.     SetViewportExtEx(hdcWnd, GetDeviceCaps(hdcWnd, LOGPIXELSX),
  846.                     -GetDeviceCaps(hdcWnd, LOGPIXELSY), NULL);
  847.     SetMapMode(hdcPrint, MM_TWIPS);
  848.  
  849.     CopyRect(&rc, lprc);
  850.     DPtoLP(hdcWnd, (LPPOINT)&rc, 2);
  851.  
  852.     // physical coord to logical
  853.     memcpy(&lf, &g_logfont, sizeof(lf));
  854.     lf.lfHeight = MulDiv(lf.lfHeight, 1440, 
  855.                         GetDeviceCaps(hdcWnd, LOGPIXELSY));
  856.     lf.lfWidth = 0;
  857.     hf2 = CreateFontIndirect(&lf);
  858.     hf = SelectObject(hdcPrint, hf2);
  859.  
  860.     if (Escape(hdcPrint, STARTDOC, 7, "Barcode", NULL) > 0)
  861.     {
  862.         BarDraw(g_hbar, hdcPrint, NULL, &rc, g_iOrient, getStyle(hwnd));
  863.         if (Escape(hdcPrint, NEWFRAME, 0, NULL, NULL) > 0)
  864.             Escape(hdcPrint, ENDDOC, 0, NULL, NULL);
  865.     }
  866.             
  867.     SetMapMode(hdcWnd, MM_TEXT);
  868.     SetMapMode(hdcPrint, MM_TEXT);
  869.  
  870.     SelectObject(hdcPrint, hf);
  871.     DeleteObject(hf2);
  872.     
  873.     ReleaseDC(hwnd, hdcWnd);
  874.  
  875.     if (g_hPrintDlg)
  876.     {
  877.         EnableWindow(hwnd, TRUE);
  878.         DestroyWindow(g_hPrintDlg);
  879.         g_hPrintDlg = 0;
  880.     }
  881.  
  882.     FreeProcInstance(lpfnPrintDlgProc);
  883.     FreeProcInstance(lpfnAbortProc);
  884. }
  885.  
  886. BOOL APIENTRY AboutDlgProc(HWND hwnd, UINT msg, 
  887.                             WPARAM wParam, LPARAM lParam)
  888. {
  889.     switch(msg) {
  890.     case WM_INITDIALOG:
  891.         return TRUE;
  892.     case WM_COMMAND:
  893.         switch(wParam) {
  894.         case IDOK:
  895.         case IDCANCEL:
  896.             EndDialog(hwnd, 0);
  897.             return TRUE;
  898.         }
  899.         break;
  900.     }
  901.     return FALSE;
  902. }
  903.  
  904. BOOL APIENTRY PrintDlgProc(HWND hDlg, UINT msg, 
  905.                             WPARAM wParam, LPARAM lParam)
  906. {
  907.     switch(msg) {
  908.     case WM_INITDIALOG:      
  909.         g_bUserAbort = FALSE;
  910.         EnableWindow(GetParent(hDlg), FALSE);
  911.         return TRUE;
  912.     case WM_COMMAND:
  913.         g_bUserAbort = TRUE;
  914.         EnableWindow(GetParent(hDlg), TRUE);
  915.         DestroyWindow(hDlg);
  916.         return TRUE;
  917.     case WM_DESTROY:
  918.         g_hPrintDlg = 0;
  919.         return TRUE;
  920.     }
  921.     return FALSE;
  922. }
  923.  
  924. BOOL APIENTRY AbortProc(HDC hdcPrint, short sCode)
  925. {
  926.     MSG        msg;
  927.     
  928.     while (!g_bUserAbort && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  929.     {
  930.         if (!g_hPrintDlg || !IsDialogMessage(g_hPrintDlg, &msg))
  931.         {
  932.             TranslateMessage(&msg);
  933.             DispatchMessage(&msg);
  934.         }
  935.     }
  936.  
  937.     return !g_bUserAbort;
  938. }
  939.  
  940. BOOL APIENTRY AdvancedDlgProc(HWND hwnd, UINT msg, 
  941.                             WPARAM wParam, LPARAM lParam)
  942. {
  943.     int        i, n;
  944.     
  945.     switch(msg) {
  946.     case WM_INITDIALOG:
  947.         wsprintf(g_tmp, "%d", BarGetClearArea(g_hbar, BGCA_LEFT));
  948.         SetWindowText(GetDlgItem(hwnd, IDC_SPLEFT), g_tmp);
  949.         wsprintf(g_tmp, "%d", BarGetClearArea(g_hbar, BGCA_RIGHT));
  950.         SetWindowText(GetDlgItem(hwnd, IDC_SPRIGHT), g_tmp);
  951.         wsprintf(g_tmp, "%d", BarGetClearArea(g_hbar, BGCA_TOP));
  952.         SetWindowText(GetDlgItem(hwnd, IDC_SPTOP), g_tmp);
  953.         wsprintf(g_tmp, "%d", BarGetClearArea(g_hbar, BGCA_BOTTOM));
  954.         SetWindowText(GetDlgItem(hwnd, IDC_SPBOTTOM), g_tmp);
  955.  
  956.         wsprintf(g_tmp, "%d", BarGetClearArea(g_hbar, BGCA_MIDDLE));
  957.         if (g_tmp[0] == '0')
  958.             EnableWindow(GetDlgItem(hwnd, IDC_SPMIDDLE), FALSE);
  959.         else
  960.             SetWindowText(GetDlgItem(hwnd, IDC_SPMIDDLE), g_tmp);
  961.  
  962.         n = BarGetNumBarExts(g_hbar);
  963.         for (i = 0; i < n; i++)
  964.         {
  965.             wsprintf(g_tmp, "%d", BarGetBarExt(g_hbar, i));
  966.             SetWindowText(GetDlgItem(hwnd, IDC_BAR0 + i), g_tmp);
  967.         }
  968.         for (i = n; i < 4; i++) 
  969.             EnableWindow(GetDlgItem(hwnd, IDC_BAR0 + i), FALSE);
  970.             
  971.         n = BarGetNumSpaceExts(g_hbar);
  972.         for (i = 0; i < n; i++)
  973.         {
  974.             wsprintf(g_tmp, "%d", BarGetSpaceExt(g_hbar, i));
  975.             SetWindowText(GetDlgItem(hwnd, IDC_SPACE0 + i), g_tmp);
  976.         }
  977.         for (i = n; i < 4; i++) 
  978.             EnableWindow(GetDlgItem(hwnd, IDC_SPACE0 + i), FALSE);
  979.  
  980.         wsprintf(g_tmp, "%d", BarGetInterCharExt(g_hbar));
  981.         if (g_tmp[0] == '0')
  982.             EnableWindow(GetDlgItem(hwnd, IDC_INTERCHARGAP), FALSE);
  983.         else
  984.             SetWindowText(GetDlgItem(hwnd, IDC_INTERCHARGAP), g_tmp);
  985.  
  986.         return TRUE;
  987.     case WM_COMMAND:
  988.         switch(wParam) {
  989.         case IDOK:
  990.             SendDlgItemMessage(hwnd, IDC_SPLEFT, WM_GETTEXT, 
  991.                 sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  992.             BarSetClearArea(g_hbar, BGCA_LEFT, atoi(g_tmp));
  993.             SendDlgItemMessage(hwnd, IDC_SPRIGHT, WM_GETTEXT, 
  994.                 sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  995.             BarSetClearArea(g_hbar, BGCA_RIGHT, atoi(g_tmp));
  996.             SendDlgItemMessage(hwnd, IDC_SPMIDDLE, WM_GETTEXT, 
  997.                 sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  998.             BarSetClearArea(g_hbar, BGCA_MIDDLE, atoi(g_tmp));
  999.             SendDlgItemMessage(hwnd, IDC_SPTOP, WM_GETTEXT, 
  1000.                 sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  1001.             BarSetClearArea(g_hbar, BGCA_TOP, atoi(g_tmp));
  1002.             SendDlgItemMessage(hwnd, IDC_SPBOTTOM, WM_GETTEXT, 
  1003.                 sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  1004.             BarSetClearArea(g_hbar, BGCA_BOTTOM, atoi(g_tmp));
  1005.  
  1006.             n = BarGetNumBarExts(g_hbar);
  1007.             for (i = 0; i < n; i++)
  1008.             {
  1009.                 SendDlgItemMessage(hwnd, IDC_BAR0 + i, WM_GETTEXT, 
  1010.                     sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  1011.                 BarSetBarExt(g_hbar, i, atoi(g_tmp));
  1012.             }
  1013.             
  1014.             n = BarGetNumSpaceExts(g_hbar);
  1015.             for (i = 0; i < n; i++)
  1016.             {
  1017.                 SendDlgItemMessage(hwnd, IDC_SPACE0 + i, WM_GETTEXT, 
  1018.                     sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  1019.                 BarSetSpaceExt(g_hbar, i, atoi(g_tmp));
  1020.             }
  1021.  
  1022.             SendDlgItemMessage(hwnd, IDC_INTERCHARGAP, WM_GETTEXT, 
  1023.                     sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  1024.             BarSetInterCharExt(g_hbar, atoi(g_tmp));
  1025.  
  1026.             EndDialog(hwnd, TRUE);
  1027.             return TRUE;
  1028.         case IDCANCEL:
  1029.             EndDialog(hwnd, FALSE);
  1030.             return TRUE;
  1031.         }
  1032.         break;
  1033.     }
  1034.     return FALSE;
  1035. }
  1036.  
  1037.