home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lstbx1.zip / DRIVER.C < prev    next >
C/C++ Source or Header  |  1994-01-05  |  12KB  |  379 lines

  1. #pragma    title("Prominare Designer  --  Version 2.10 -- (Colours.C)")
  2. #pragma    subtitle("   Prominare Designer - 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. #define    INCL_WINSTDSPIN           /* Include OS/2 PM Spin Buttons    */
  8. #define    INCL_NLS           /* Include OS/2 PM NLS        */
  9. #define    INCL_SW               /* Include OS/2 MultiMedia Support    */
  10.  
  11. #pragma    info(nopar)
  12.  
  13. static char *MODID = "@(#)driver.c:1.07";
  14.  
  15. #include <os2.h>
  16. #include <string.h>
  17. #include <stdio.h>
  18.  
  19. #include "listbox.h"
  20.  
  21. /* The application is created using the    following options in Prominare    */
  22. /* Builder:                                */
  23. /*                                    */
  24. /* Option           Value                        */
  25. /* ------           -----                        */
  26. /* Memory Model           Small                        */
  27. /* Op Sys           OS/2 2.x    PM Normal                */
  28. /* Optimization           Maximize                        */
  29. /* Compile Type           Compile Only                    */
  30. /*               Error Trap                    */
  31. /*               ExePack                        */
  32. /*               Link                        */
  33. /* CPU               80386                        */
  34. /* Warning Level       3                        */    
  35. /*                                    */
  36. /* Equivalent command line invocation of each module using the        */
  37. /* IBM C Set/2 Compiler    Version    1.0 is:                    */
  38. /*                                    */
  39. /*     Icc -G3s- -O+ -Sm -C -W3    -Fofilename filename.C            */
  40.  
  41. /* Filename:   Driver.C                            */
  42.  
  43. /*  Version:   2.10                            */
  44. /*  Created:   1990-12-29                        */
  45. /*  Revised:   1994-01-05                        */
  46.  
  47.  
  48. /* --------------------------------------------------------------------    */
  49.  
  50. /* --- Module Definitions ---------------------------------------------    */
  51.  
  52. #define    USER_RESERVED       8       /* Control Reserved Memory Size    */
  53.  
  54. PSZ pszDriverClassName = "ListBox.Desktop";
  55.  
  56. HPOINTER hptrWait;
  57. HPOINTER hptrArrow;
  58. HWND     hwndDriver;           /* Program Window Handle        */
  59. HWND     hwndDriverFrame;       /* Program Frame Handle        */
  60. HAB     hAB;               /* Program Anchor Block Handle    */
  61. HMQ     hmqDriver;           /* Program Message Queue Handle    */
  62.  
  63. HWND     hwndList1;
  64. HWND     hwndList2;
  65.  
  66. HWND     hwndListA;
  67. HWND     hwndListB;
  68.  
  69. #define    RGBCLR_DIALOGBACKGROUND    0x00ccccccL
  70.  
  71. INT main(INT, CHAR *[ ]);
  72. MRESULT    EXPENTRY ListBoxWndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  73. MRESULT    EXPENTRY DriverWndProc(HWND hWnd, ULONG    msg, MPARAM mp1, MPARAM    mp2);
  74.  
  75.  
  76. #pragma    subtitle("   Client Window - Client Window Procedure")
  77. #pragma    page( )
  78.  
  79. /* --- DriverWndProc --------------------------------------------------    */
  80. /*                                    */
  81. /*     This function is    used to    process    the messages for the main    */
  82. /*     Client Window.                            */
  83. /*                                    */
  84. /*     Upon Entry:                            */
  85. /*                                    */
  86. /*     HWND   hWnd; = Window Handle                    */
  87. /*     ULONG  msg;  = PM Message                    */
  88. /*     MPARAM mp1;  = Message Parameter    1                */
  89. /*     MPARAM mp2;  = Message Parameter    2                */
  90. /*                                    */
  91. /*     Upon Exit:                            */
  92. /*                                    */
  93. /*     DriverWndProc = Message Handling    Result                */
  94. /*                                    */
  95. /* --------------------------------------------------------------------    */
  96.  
  97. MRESULT    EXPENTRY DriverWndProc(HWND hWnd, ULONG    msg, MPARAM mp1, MPARAM    mp2)
  98.  
  99. {
  100. CHAR         szFile[CCHMAXPATH];   /* File HOlder            */
  101. FILEFINDBUF3 findbuf;           /* File Find    Buffer            */
  102. FONTMETRICS  fm;           /* Font Metrics Structure        */
  103. HDIR         hDir = (HDIR)HDIR_CREATE; /* Directory Handle        */
  104. HPS         hPS;           /* Presentation Space Handle        */
  105. HWND         hwndListBox;       /* List Box Window Handle        */
  106. LISTBOXCDATA lbwcd;           /* List Box Window Control Data    */
  107. POWNERITEM   poi;           /* Owner Item            */
  108. RECTL         rcl;           /* Client Window Rectangle        */
  109. ULONG         ulFileCnt = 1UL;       /* File Counter Holder        */
  110. register INT i;               /* Loop Counter            */
  111.  
  112. switch ( msg )
  113.    {
  114.                /* Perform window initialization            */
  115.    case    WM_CREATE :
  116.        hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW,    FALSE);
  117.        WinSetPointer(HWND_DESKTOP, hptrWait = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE));
  118.        memset(&lbwcd, 0, sizeof(LISTBOXCDATA));
  119.        lbwcd.cb    = sizeof(LISTBOXCDATA);
  120.  
  121.        hwndList1 = WinCreateWindow(hWnd, "ListBoxWindow", "", LS_OWNERDRAW | LS_HORZSCROLL | LS_EXTENDEDSEL | WS_VISIBLE,
  122.                    10L,    10L, 100L, 175L, hWnd,
  123.                    HWND_TOP, 1024UL, (PVOID)&lbwcd, (PVOID)NULL);
  124.  
  125.        hwndList2 = WinCreateWindow(hWnd, "ListBoxWindow", "", WS_VISIBLE, 10L, 190L, 250L, 200L, hWnd,
  126.                    HWND_TOP, 1025UL, (PVOID)&lbwcd, (PVOID)NULL);
  127.  
  128.        hwndListA = WinCreateWindow(hWnd, WC_LISTBOX, "", LS_OWNERDRAW |    LS_HORZSCROLL |    LS_MULTIPLESEL | WS_VISIBLE,
  129.                    275L, 10L, 100L, 175L, hWnd,
  130.                    HWND_TOP, 1026UL, (PVOID)NULL, (PVOID)NULL);
  131.  
  132.                /* Sub-class the    default    window procedure with    */
  133.                /* new one which    will handle specific messages    */
  134.                /* allowing better control over the sizing frame    */
  135.  
  136.        hwndListB = WinCreateWindow(hWnd, WC_LISTBOX, "", WS_VISIBLE | LS_EXTENDEDSEL, 275L, 190L, 250L,    200L, hWnd,
  137.                    HWND_TOP, 1027UL, (PVOID)NULL, (PVOID)NULL);
  138.  
  139.        if ( !DosFindFirst("*.*", &hDir,    FILE_NORMAL,
  140.               (PVOID)&findbuf, sizeof(FILEFINDBUF3),
  141.               &ulFileCnt, FIL_STANDARD) )
  142.        {
  143.        do
  144.            {
  145.            WinSendMsg(hwndList2, LM_INSERTITEM,
  146.               MPFROMLONG(LIT_SORTDESCENDING),
  147.               MPFROMP(findbuf.achName));
  148.            WinSendMsg(hwndList1, LM_INSERTITEM,
  149.               MPFROMLONG(LIT_SORTASCENDING),
  150.               MPFROMP(findbuf.achName));
  151.            WinSendMsg(hwndListB, LM_INSERTITEM,
  152.               MPFROMLONG(LIT_SORTDESCENDING),
  153.               MPFROMP(findbuf.achName));
  154.            WinSendMsg(hwndListA, LM_INSERTITEM,
  155.               MPFROMLONG(LIT_SORTASCENDING),
  156.               MPFROMP(findbuf.achName));
  157.            }
  158.            while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) );
  159.        DosFindClose(hDir);
  160.        }
  161.        break;
  162.  
  163.    case    WM_BUTTON1DOWN :
  164.        WinEnableWindowUpdate(hwndListA,    FALSE);
  165.        WinEnableWindowUpdate(hwndList1,    FALSE);
  166.  
  167.        WinSendMsg(hwndListA, LM_DELETEALL, 0L, 0L);
  168.        WinSendMsg(hwndList1, LM_DELETEALL, 0L, 0L);
  169.        i = 0;
  170.        if ( !DosFindFirst("*.*", &hDir,    FILE_NORMAL,
  171.               (PVOID)&findbuf, sizeof(FILEFINDBUF3),
  172.               &ulFileCnt, FIL_STANDARD) )
  173.        {
  174.        do
  175.            {
  176.            WinSendMsg(hwndListA, LM_INSERTITEM,
  177.               MPFROMLONG(LIT_SORTASCENDING),
  178.               MPFROMP(findbuf.achName));
  179.            WinSendMsg(hwndList1, LM_INSERTITEM,
  180.               MPFROMLONG(LIT_SORTASCENDING),
  181.               MPFROMP(findbuf.achName));
  182.            ++i;
  183.            }
  184.            while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) );
  185.        DosFindClose(hDir);
  186.        }
  187.        WinShowWindow(hwndListA,    TRUE);
  188.        WinShowWindow(hwndList1,    TRUE);
  189.  
  190.        while ( i )
  191.        {
  192.        if (    i % 2 )
  193.            {
  194.            WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(TRUE));
  195.            WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(TRUE));
  196.            }
  197.        --i;
  198.        }
  199.        break;
  200.  
  201.    case    WM_MEASUREITEM :
  202.        GpiQueryFontMetrics(hPS = WinGetPS(hWnd), sizeof(FONTMETRICS), &fm);
  203.        WinReleasePS(hPS);
  204.        return(MRFROMLONG(fm.lMaxBaselineExt));
  205.  
  206.                /* Draw a list box item                */
  207.    case    WM_DRAWITEM :
  208.  
  209.        if ( SHORT1FROMMP(mp1) == 1024 )
  210.        hwndListBox = hwndList1;
  211.        else
  212.        if (    SHORT1FROMMP(mp1) == 1026 )
  213.            hwndListBox = hwndListA;
  214.  
  215.                /* Point    to Owner Item information        */
  216.  
  217.        poi = (POWNERITEM)mp2;
  218.        GpiCreateLogColorTable(poi->hps,    0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL);
  219.  
  220.        i = (INT)LONGFROMMR(WinSendMsg(hwndListBox, LM_QUERYITEMTEXTLENGTH,
  221.                       MPFROMLONG(poi->idItem), 0L));
  222.  
  223.        i = (INT)LONGFROMMR(WinSendMsg(hwndListBox, LM_QUERYITEMTEXT,
  224.                       MPFROM2SHORT(poi->idItem,    CCHMAXPATH),
  225.                       MPFROMP(szFile)));
  226.  
  227.                /* Check    to see if item to be drawn or        */
  228.                /* highlighted                    */
  229.  
  230.        if ( poi->fsState != poi->fsStateOld )
  231.        {
  232.        WinFillRect(poi->hps, &poi->rclItem,    RGBCLR_DIALOGBACKGROUND);
  233.  
  234.        if (    poi->fsState )
  235.            WinDrawText(poi->hps, -1L, szFile, &poi->rclItem,
  236.                RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER |
  237.                DT_ERASERECT);
  238.  
  239.                /* Set item highlighting    by inverting the items    */
  240.                /* rectangle colour                */
  241.  
  242.        WinInvertRect(poi->hps, &poi->rclItem);
  243.  
  244.        if (    !poi->fsState )
  245.            WinDrawText(poi->hps, -1L, szFile, &poi->rclItem,
  246.                RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER |
  247.                DT_ERASERECT);
  248.        poi->fsState    = poi->fsStateOld = 0;
  249.        }
  250.        else
  251.        {
  252.                /* Item needs to    be drawn, get item rectangle    */
  253.                /* item position                    */
  254.  
  255.        WinFillRect(poi->hps, &poi->rclItem,    RGBCLR_DIALOGBACKGROUND);
  256.  
  257.        WinDrawText(poi->hps, -1L, szFile, &poi->rclItem,
  258.                RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER    |
  259.                DT_ERASERECT);
  260.        }
  261.        return(MRFROMLONG(TRUE));
  262.  
  263.    case    WM_BUTTON1DBLCLK :
  264.        i = 0;
  265.        if ( !DosFindFirst("*.*", &hDir,    FILE_NORMAL,
  266.               (PVOID)&findbuf, sizeof(FILEFINDBUF3),
  267.               &ulFileCnt, FIL_STANDARD) )
  268.        {
  269.        do
  270.            {
  271.            ++i;
  272.            }
  273.            while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) );
  274.        DosFindClose(hDir);
  275.        }
  276.  
  277.        while ( i )
  278.        {
  279.        if (    i % 2 )
  280.            {
  281.            WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(FALSE));
  282.            WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(FALSE));
  283.            }
  284.        --i;
  285.        }
  286.        break;
  287.  
  288.    case    WM_BUTTON2DOWN :
  289.        WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(LIT_NONE), MPFROMLONG(TRUE));
  290.  
  291.        i = LIT_FIRST;
  292.        while ( (i = (INT)LONGFROMMR(WinSendMsg(hwndList1, LM_QUERYSELECTION, MPFROMLONG(i), 0L))) != LIT_NONE )
  293.        WinSendMsg(hwndList1, LM_SELECTITEM,    MPFROMLONG(i), MPFROMLONG(FALSE));
  294.        break;
  295.                /* Erase    background                */
  296.  
  297.    case    WM_ERASEBACKGROUND :
  298.        WinQueryWindowRect(hWnd,    &rcl);
  299.        WinFillRect((HPS)mp1, &rcl, SYSCLR_DIALOGBACKGROUND);
  300.        break;
  301.                /* Paint    the main client    window            */
  302.    case    WM_PAINT :
  303.        WinSetPointer(HWND_DESKTOP, hptrWait);
  304.  
  305.        WinFillRect(hPS = WinBeginPaint(hWnd, (HPS)NULL,    &rcl), &rcl, SYSCLR_DIALOGBACKGROUND);
  306.  
  307.        WinEndPaint(hPS);
  308.        WinSetPointer(HWND_DESKTOP, hptrArrow);
  309.        break;
  310.                /* Close    Down                    */
  311.    case    WM_CLOSE :
  312.  
  313.        WinPostMsg(hWnd,    WM_QUIT, 0L, 0L);
  314.        break;
  315.  
  316.    case    WM_DESTROY :
  317.        WinDestroyPointer(hptrArrow);
  318.        WinDestroyPointer(hptrWait);
  319.        break;
  320.                /* Default message processing            */
  321.    default:
  322.        return(WinDefWindowProc(hWnd, msg, mp1, mp2));
  323.    }
  324. return(0L);
  325. }
  326. #pragma    subtitle("   Program Controller")
  327. #pragma    page( )
  328.  
  329. /* --- Main Program Controller ----------------------------------------    */
  330.  
  331. INT main(INT argc, CHAR    *argv[ ])
  332.  
  333. {
  334. QMSG       qmsg;           /* PM Message Queue Holder        */
  335. ULONG       flCreateFlags;       /* Window Creation Flags        */
  336.  
  337.  
  338.                /* Initialize the program for PM    and create the    */
  339.                /* message queue                    */
  340.  
  341. WinSetCp(hmqDriver = WinCreateMsgQueue(hAB = WinInitialize(0), 0), 850);
  342.  
  343.                /* Register the main program window class    */
  344.  
  345. if ( !WinRegisterClass(hAB, pszDriverClassName,    (PFNWP)DriverWndProc,
  346.                CS_CLIPCHILDREN | CS_SYNCPAINT |    CS_SIZEREDRAW, 0) )
  347.    return(1);
  348.                /* Register the main program window class    */
  349.  
  350. if ( !fRegisterListBox(hAB) )
  351.    return(1);
  352.                /* Create the main program window but do    not    */
  353.                /* show it yet                    */
  354.  
  355. flCreateFlags =    FCF_TITLEBAR | FCF_NOBYTEALIGN | FCF_SYSMENU | FCF_SIZEBORDER |    FCF_SHELLPOSITION;
  356. if ( !(hwndDriverFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE,
  357.                           &flCreateFlags,
  358.                           pszDriverClassName, NULL,    0L,
  359.                          (HMODULE)0L, 0L,
  360.                           &hwndDriver)) )
  361.    {
  362.    return(1);
  363.    }
  364.                /* Retrieve and then dispatch messages        */
  365.  
  366. while (    WinGetMsg(hAB, &qmsg, (HWND)NULL, 0, 0)    )
  367.    WinDispatchMsg(hAB, &qmsg);
  368.  
  369. WinDestroyWindow(hwndDriverFrame);
  370.  
  371. WinDestroyMsgQueue(hmqDriver);
  372.  
  373.                /* Notify PM that main program thread not needed    */
  374.                /* any longer                    */
  375. WinTerminate(hAB);
  376.  
  377. return(0);
  378. }
  379.