APPMAIN.C
上传用户:needlamp
上传日期:2007-01-07
资源大小:78k
文件大小:45k
源码类别:

Delphi控件源码

开发平台:

Visual C++

  1. //8,3,2,20,7,6,4,5,22
  2. #include <windows.h> 
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "lg3d.h"
  6. #include "appmain.h"
  7. HINSTANCE hInst;
  8. HWND hWndMain,hWndPrj,hWndStyle,hWndCtl,hWndInsp,hWndCode;
  9. HWND hWndPrev =NULL;
  10. HBRUSH  hBrushPat =NULL;
  11. int slipPos =180;
  12. typedef struct tag_PrjBtnInfo
  13. {
  14.   int BmpNO;
  15.   UINT ID;
  16.   int left,top;
  17. }PrjBtnInfo;
  18. PrjBtnInfo PrjBtn[PRJ_BTN_COUNT]=
  19. {
  20.   {0,IDM_OPENPRJ,5,5},
  21.   {1,IDM_SAVEPRJ,5+PRJ_BTN_WIDTH+1,5},
  22.   {2,IDM_ADDFILE,5+(PRJ_BTN_WIDTH+1)*2,5},
  23.   {3,IDM_VIEW_CODE,10+(PRJ_BTN_WIDTH+1)*3,5},
  24.   {4,IDM_VIEW_FORM,10+(PRJ_BTN_WIDTH+1)*4,5},
  25.   {5,IDM_NEWFILE,5,5+PRJ_BTN_HEIGHT+1},
  26.   {6,IDM_SAVEFILE,5+PRJ_BTN_WIDTH+1,5+PRJ_BTN_HEIGHT+1},
  27.   {7,IDM_RMVFILE,5+(PRJ_BTN_WIDTH+1)*2,5+PRJ_BTN_HEIGHT+1},
  28.   {8,IDM_VIEW_TOG,10+(PRJ_BTN_WIDTH+1)*3,5+PRJ_BTN_HEIGHT+1},
  29.   {9,IDM_NEWFRM,10+(PRJ_BTN_WIDTH+1)*4,5+PRJ_BTN_HEIGHT+1}
  30. };
  31. typedef struct tag_StyleBtnInfo
  32. {
  33.   UINT ID;
  34.   char Caption[20];
  35.   int left,right;
  36. }StyleBtnInfo;
  37. typedef StyleBtnInfo FAR *LPSTYLEBTN;
  38. void DrawStyleBtn(HDC,HWND,int, int, BOOL,LPSTYLEBTN);
  39. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  40. {
  41.     MSG msg;
  42.     if (!hPrevInstance)
  43.     if (!InitApplication(hInstance))
  44.         return (FALSE);
  45.     if (!InitInstance(hInstance, nCmdShow))
  46.         return (FALSE);
  47.     
  48.     LgDlg3D(TRUE,NULL);  //must using in c, not in cpp
  49.     
  50.     while (GetMessage(&msg,
  51.         NULL,
  52.         NULL,
  53.         NULL))
  54.     {                           
  55.       {
  56.         TranslateMessage(&msg);
  57.         DispatchMessage(&msg);
  58.       }  
  59.     }
  60.     ExitProg();
  61.     return (msg.wParam);
  62. }
  63. void ExitProg(void)
  64. {
  65.   if(hBrushPat) DeleteObject(hBrushPat);
  66.   hBrushPat = NULL;
  67.   LgDlg3D(FALSE,NULL);  //must use in c , not in cpp
  68. }
  69. BOOL InitApplication(HINSTANCE hInstance)
  70. {
  71.     WNDCLASS  wc;
  72.     wc.style = CS_DBLCLKS;
  73.     wc.lpfnWndProc = MainWndProc;
  74.     wc.cbClsExtra = 0;
  75.     wc.cbWndExtra = 0;
  76.     wc.hInstance = hInstance;
  77.     wc.hIcon = LoadIcon(hInstance, "ICON_YW");
  78.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  79.     wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  80.     wc.lpszMenuName =  "CBuilder";
  81.     wc.lpszClassName = "CBuilder";
  82.     return (RegisterClass(&wc));
  83. }
  84. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  85. {
  86.     HWND            hWnd;
  87.     hInst = hInstance;
  88.     hWnd = CreateWindow(
  89.         "CBuilder",
  90.         "CBuilder",
  91.         WS_OVERLAPPEDWINDOW,
  92.         0,0,638,MAIN_WINDOW_HEIGHT,
  93.         NULL,
  94.         NULL,
  95.         hInstance,
  96.         NULL
  97.     );
  98.     if (!hWnd)
  99.         return (FALSE);
  100.     hWndMain = hWnd;
  101.     if(!CreateMainChild(hWnd))
  102.     {
  103.       DestroyWindow(hWnd);
  104.       return FALSE;
  105.     }  
  106.                           
  107.     if(!RegLGFORM())
  108.     {
  109.       DestroyWindow(hWnd);
  110.       return FALSE;
  111.     }
  112.                           
  113.     if((hWndInsp =CreateInspWnd()) ==NULL)
  114.     {
  115.       DestroyWindow(hWnd);
  116.       return FALSE;
  117.     }
  118.     
  119.     if(!CreateRecSizeWnd())
  120.     {
  121.       ErrorMessage("CreateRecSizeWnd failed!");    
  122.       DestroyWindow(hWnd);
  123.       return FALSE;
  124.     }
  125.    
  126.     ShowWindow(hWnd, nCmdShow);
  127.     UpdateWindow(hWnd);
  128.     return (TRUE);
  129. }
  130. HWND CreateChild(HWND hWndParent,LPSTR ClassName,WNDPROC WndProc,int left,int top,int width,int height,UINT ID,int WndExtra)
  131. {
  132.     WNDCLASS  wc;
  133.     HWND hWnd;
  134.     
  135.     wc.style = CS_HREDRAW | CS_DBLCLKS;
  136.     wc.lpfnWndProc = WndProc;
  137.     wc.cbClsExtra = 0;
  138.     wc.cbWndExtra = WndExtra;
  139.     wc.hInstance = hInst;
  140.     wc.hIcon = LoadIcon(hInst, "ICON_YW");
  141.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  142.     wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  143.     wc.lpszMenuName =  NULL;
  144.     wc.lpszClassName = ClassName;
  145.     if(!RegisterClass(&wc)) return NULL;
  146.     
  147.     hWnd = CreateWindow( ClassName,ClassName,WS_CHILD,
  148.                          left,top,width,height,
  149.                          hWndParent,ID, hInst,  NULL
  150.                        );
  151.     if (!hWnd)
  152.       return NULL;
  153.     
  154.     ShowWindow(hWnd, SW_SHOW);
  155.     UpdateWindow(hWnd);
  156.     return hWnd;
  157. }
  158. BOOL CreateMainChild(HWND hWnd)
  159. {     
  160.   RECT rc;                                
  161.   HBITMAP hBmpPat; 
  162.   static char tmp[30];                                
  163.   int i;
  164.   
  165.    hBmpPat = LoadBitmap(hInst,"BMP_PAT");
  166.    if(hBmpPat)
  167.      hBrushPat = CreatePatternBrush(hBmpPat);
  168.    DeleteObject(hBmpPat);
  169.    GetClientRect(hWnd,&rc);
  170.    
  171.    if((hWndPrj = CreateChild(hWnd,(LPSTR)"WNDPRJ",(WNDPROC)PrjWndProc,
  172.              0,0,slipPos,rc.bottom,NULL,0)) == NULL)
  173.    {
  174.      ErrorMessage("CreateMainChild WNDPRJ failed!");
  175.      return FALSE;                                                 
  176.    }  
  177.    
  178.    if((hWndCtl = CreateChild(hWnd,(LPSTR)"WNDCTL",(WNDPROC)CtlWndProc,
  179.                 slipPos+3,0,rc.right-slipPos-3,rc.bottom-19,NULL,0)) == NULL)
  180.    {
  181.      ErrorMessage("CreateMainChild WNDCTL failed!");
  182.      return FALSE;
  183.    }
  184.    
  185.    if((hWndStyle = CreateChild(hWnd,(LPSTR)"WNDSTYLE",(WNDPROC)StyleWndProc,
  186.                      slipPos+3,rc.bottom-19,rc.right-slipPos-3,19,IDW_STYLE,
  187.                      5*sizeof(WORD))) == NULL)
  188.    {
  189.      ErrorMessage("CreateMainChild WNDSTYLE failed!");
  190.      return FALSE;                                                   
  191.    }  
  192.    
  193.    i=0;                                           
  194.    while(LoadString(hInst,IDW_STYLE+i,(LPSTR)tmp,sizeof(tmp)))
  195.    {
  196.      SendMessage(hWndStyle,WM_ADDITEM,IDW_STYLE+i,(LPARAM)(LPSTR)tmp);
  197.      i++;
  198.    }  
  199.    return TRUE;
  200. }   
  201. BOOL RegLGFORM(void)
  202. {
  203.     WNDCLASS  wc;
  204.     
  205.     wc.style = CS_HREDRAW | CS_DBLCLKS;
  206.     wc.lpfnWndProc = FormWndProc;
  207.     wc.cbClsExtra = 0;
  208.     wc.cbWndExtra = 2*sizeof(WORD);
  209.     wc.hInstance = hInst;
  210.     wc.hIcon = LoadIcon(hInst, "ICON_YW");
  211.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  212.     wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  213.     wc.lpszMenuName =  NULL;
  214.     wc.lpszClassName = "LGFORM";
  215.     if(!RegisterClass(&wc)) return FALSE;
  216.     wc.style =0;
  217.     wc.lpfnWndProc = RecSizeWndProc;
  218.     wc.cbClsExtra = 0;
  219.     wc.cbWndExtra = sizeof(WORD);
  220.     wc.hInstance = hInst;
  221.     wc.hIcon = NULL;
  222.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  223.     wc.hbrBackground = GetStockObject(BLACK_BRUSH);
  224.     wc.lpszMenuName =  NULL;
  225.     wc.lpszClassName = "RECSIZE";
  226.     
  227.     return (RegisterClass(&wc));
  228. }
  229. HWND hWndRecSize[8];
  230. BOOL CreateRecSizeWnd(void)
  231. {                   
  232.   int i;
  233.   for(i=0;i<8;i++)
  234.   {
  235.     hWndRecSize[i]=CreateWindow("RECSIZE","",WS_CHILD,0,0,5,5,
  236.                       hWndMain,0,hInst,NULL);
  237.     if(hWndRecSize[i]==NULL) return FALSE;
  238.     SetWindowWord(hWndRecSize[i],0,i);                  
  239.   }                
  240.   return TRUE;
  241. }
  242. HWND CreateInspWnd(void)
  243. {
  244.     HWND hWnd;
  245.     WNDCLASS  wc;
  246.     
  247.     wc.style = CS_HREDRAW | CS_DBLCLKS;
  248.     wc.lpfnWndProc = InspWndProc;
  249.     wc.cbClsExtra = 0;
  250.     wc.cbWndExtra = sizeof(WORD);
  251.     wc.hInstance = hInst;
  252.     wc.hIcon = LoadIcon(hInst, "ICON_YW");
  253.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  254.     wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  255.     wc.lpszMenuName =  NULL;
  256.     wc.lpszClassName = "LGINSP";
  257.     if(!RegisterClass(&wc)) return NULL;
  258.     
  259.     hWnd =CreateWindow("LGINSP","对象流览器",
  260.                    WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX
  261.                    |WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_THICKFRAME,
  262.                    0,120,200,280,
  263.                    NULL, NULL, hInst, NULL);
  264.     if (!hWnd)
  265.       return NULL;
  266.     
  267.     ShowWindow(hWnd, SW_SHOW);
  268.     UpdateWindow(hWnd);
  269.     SetWindowPos(hWnd,hWndMain,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
  270.     return hWnd;
  271. }
  272. HCURSOR hCurSplit = NULL;
  273. BOOL isInSlip = FALSE;
  274. BOOL isMouseDown=FALSE; 
  275. BOOL gSlipped =FALSE;  
  276. int FormNum =0;             
  277. HFONT hStyleFont=NULL;
  278. HBITMAP hBmpStyleUp,hBmpStyleDn,hBmpStyleDs;
  279. long CALLBACK __export MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  280. {     
  281.   RECT rc;
  282.   MINMAXINFO FAR *lpmmi;
  283.   POINT pt;
  284.   PAINTSTRUCT ps;
  285.   HPEN hPen;
  286.   DLGPROC lpProcAbout;
  287.   HDC hDC;
  288.   BOOL fInSlip = FALSE;      
  289.   HWND hwnd;
  290.   LOGFONT lf;
  291.   
  292.   switch (message)
  293.   {                      
  294.     case WM_CREATE:
  295.       hCurSplit = LoadCursor(hInst,"CUR_SPLIT");
  296.   
  297.       hBmpStyleUp =LoadBitmap(hInst,"BMP_STYLEUP");
  298.       hBmpStyleDn =LoadBitmap(hInst,"BMP_STYLEDN");
  299.       hBmpStyleDs =LoadBitmap(hInst,"BMP_STYLEDS"); 
  300.       
  301.       memset(&lf,0,sizeof(lf));
  302.       lf.lfHeight =         13;
  303.       lf.lfWeight =         FW_NORMAL;
  304.       lf.lfCharSet =        DEFAULT_CHARSET ;
  305.       lf.lfOutPrecision =   OUT_DEFAULT_PRECIS ;
  306.       lf.lfClipPrecision =  CLIP_DEFAULT_PRECIS ;
  307.       lf.lfQuality =        DEFAULT_QUALITY ;
  308.       lf.lfPitchAndFamily = DEFAULT_PITCH;
  309.       strcpy(lf.lfFaceName , "宋体");
  310.       hStyleFont = CreateFontIndirect( &lf ) ;   
  311.       if(hStyleFont == NULL)
  312.       {                
  313.         ErrorMessage("Create StyleFont Failed");
  314.         return -1;
  315.       }
  316.     break;
  317.     
  318.     case WM_GETMINMAXINFO:
  319.       lpmmi=(MINMAXINFO FAR *)lParam;
  320.       lpmmi->ptMaxSize.y=100;
  321.       lpmmi->ptMinTrackSize.x=500;
  322.       lpmmi->ptMinTrackSize.y=100;
  323.       lpmmi->ptMaxTrackSize.y=100;
  324.     break;
  325.                                                        
  326.     case WM_SIZE:                                      
  327.       if(wParam == SIZE_MINIMIZED) break;
  328.       GetClientRect(hWndPrj,&rc);                  
  329.       MoveWindow(hWndStyle, rc.right+3, rc.bottom-19,
  330.                       LOWORD(lParam)-rc.right-3,19,TRUE);     
  331.       MoveWindow(hWndCtl, rc.right+3,0,
  332.                    LOWORD(lParam)-rc.right-3,rc.bottom-19,TRUE);                
  333.     return 0L;
  334.     case WM_SETCURSOR:
  335.       if(isInSlip ==TRUE)
  336.         return TRUE;
  337.     break;
  338.                 
  339.     case WM_CANCELMODE:
  340.     break;  
  341.     
  342.     case WM_LBUTTONDOWN:
  343.       if(isInSlip)
  344.       {
  345.         GetClientRect(hWnd,&rc);
  346.         hDC = GetDC(hWnd);  
  347.         SetROP2(hDC,R2_NOT);
  348.         MoveTo(hDC,slipPos+1,0);
  349.         LineTo(hDC,slipPos+1,rc.bottom);
  350.         ReleaseDC(hWnd,hDC);  
  351.         SetCapture(hWnd);  
  352.         isMouseDown = TRUE;
  353.       }
  354.     return 0L;                     
  355.     
  356.     case WM_ACTIVATEAPP:                               
  357.       if(wParam) SetActiveWindow(hWnd);
  358.     break;
  359.     
  360.     case WM_MOUSEMOVE: 
  361.       if(!isMouseDown)
  362.       {
  363.         fInSlip = isInSlip;
  364.         pt = MAKEPOINT(lParam);
  365.         if(pt.x>slipPos-1 && pt.x<slipPos+3 && pt.y>0)
  366.           isInSlip = TRUE;
  367.         else
  368.           isInSlip=FALSE; 
  369.         if(fInSlip !=isInSlip)
  370.         {                                         
  371.           if(isInSlip)
  372.             SetCursor(hCurSplit);
  373.           else SetCursor(LoadCursor(NULL,IDC_ARROW));
  374.         }
  375.         return 0L;
  376.       }
  377.       if(!isInSlip) return 0L;
  378.       GetClientRect(hWnd,&rc);     
  379.       hDC=GetDC(hWnd);
  380.       SetROP2(hDC,R2_NOT);
  381.       MoveTo(hDC,slipPos+1,0);
  382.       LineTo(hDC,slipPos+1,rc.bottom);
  383.       pt=MAKEPOINT(lParam);
  384.       slipPos=pt.x;
  385.       MoveTo(hDC,slipPos+1,0);      
  386.       LineTo(hDC,slipPos+1,rc.bottom);
  387.       ReleaseDC(hWnd,hDC);
  388.     return 0L;
  389.              
  390.     case WM_LBUTTONUP: 
  391.       if(!isInSlip || !isMouseDown) break;     
  392.       isMouseDown = FALSE;              
  393.       isInSlip = FALSE;
  394.       ReleaseCapture();
  395.       GetClientRect(hWnd,&rc);     
  396.       hDC=GetDC(hWnd);
  397.       pt=MAKEPOINT(lParam);
  398.       slipPos=pt.x;
  399.       SetROP2(hDC,R2_NOT);
  400.       MoveTo(hDC,slipPos+1,0);
  401.       LineTo(hDC,slipPos+1,rc.bottom);
  402.       ReleaseDC(hWnd,hDC);               
  403.       SetCursor(LoadCursor(NULL,IDC_ARROW));  
  404.       
  405.       gSlipped =TRUE;
  406.       MoveWindow(hWndPrj, 0,0,slipPos,rc.bottom,TRUE);
  407.       MoveWindow(hWndCtl, slipPos+3,0,
  408.                    rc.right-slipPos-3,rc.bottom-19,TRUE);  
  409.       MoveWindow(hWndStyle, slipPos+3, rc.bottom-19,
  410.                       rc.right-slipPos-3,19,TRUE);     
  411.       gSlipped =FALSE;                
  412.     return 0L;
  413.              
  414.     case WM_MENUSELECT:
  415.       if(wParam ==0 && hWndPrev !=NULL) 
  416.       {
  417.         SetFocus(hWndPrev);
  418.         hWndPrev =NULL;
  419.         return 0L;
  420.       }  
  421.     break;
  422.     
  423.     case WM_COMMAND:
  424.       switch(wParam)
  425.       {                       
  426.         case IDW_STYLE:
  427.           SendMessage(hWndCtl, WM_STYLECHANGED, (WPARAM)lParam,0L);
  428.         return 0L;
  429.         
  430.         case IDM_VIEW_OBJINSP:
  431.           ShowWindow(hWndInsp,SW_SHOW); 
  432.           SetFocus(hWndInsp);
  433.         return 0L;
  434.         
  435.         case IDM_NEWFRM:
  436.           hwnd =CreateNewForm();
  437.         break;
  438.         
  439.         case IDM_EXIT:
  440.           PostMessage(hWnd,WM_CLOSE,0,0L);
  441.         break;
  442.         
  443.         case IDM_ABOUT:               
  444.           lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About,hInst);
  445.           DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
  446.           FreeProcInstance((FARPROC)lpProcAbout);
  447.         break;
  448.         
  449.         default:
  450.         break;  
  451.       }
  452.     return 0L;      
  453.     
  454.     case WM_PAINT:
  455.       GetClientRect(hWndPrj,&rc);
  456.       
  457.       BeginPaint(hWnd,&ps);
  458.       hPen = CreatePen(PS_SOLID,1,RGB(80,80,80));  
  459.       SelectObject(ps.hdc,hPen);
  460.       MoveTo(ps.hdc,rc.right+2,0);
  461.       LineTo(ps.hdc,rc.right+2,rc.bottom);
  462.       SelectObject(ps.hdc,GetStockObject(WHITE_PEN));
  463.       DeleteObject(hPen);
  464.       MoveTo(ps.hdc,rc.right,0);
  465.       LineTo(ps.hdc,rc.right,rc.bottom);                   
  466.       EndPaint(hWnd,&ps);
  467.     break;
  468.                 
  469.     case WM_CLOSE:
  470.       if(MessageBox(NULL,"您 是 否 确 定 退 出nn"
  471.                          "    CBuilder 系 统?",
  472.                     "CBuilder",MB_ICONQUESTION|MB_TASKMODAL|MB_YESNO)
  473.          ==IDYES)                              
  474.       {
  475.         for(hwnd =FindWindow("LGFORM",NULL); 
  476.             GetWindowWord(hwnd,GWW_HINSTANCE)==hInst; 
  477.             hwnd =FindWindow("LGFORM",NULL))
  478.           DestroyWindow(hwnd);
  479.         UnregisterClass("LGFORM",hInst);    
  480.         if(hWndInsp) DestroyWindow(hWndInsp);
  481.         UnregisterClass("LGINSP",hInst);    
  482.         DestroyWindow(hWnd);
  483.       } 
  484.     return 0L;
  485.                 
  486.     case WM_DESTROY:
  487.       if(hCurSplit) DeleteObject(hCurSplit);
  488.       if(hStyleFont) DeleteObject(hStyleFont);         
  489.       if(hBmpStyleUp) DeleteObject(hBmpStyleUp);
  490.       if(hBmpStyleDn) DeleteObject(hBmpStyleDn);
  491.       if(hBmpStyleDs) DeleteObject(hBmpStyleDs);
  492.       PostQuitMessage(0);
  493.     break;
  494.     default:
  495.     break;
  496.   }
  497.   return (DefWindowProc(hWnd, message, wParam, lParam));
  498. }
  499. long CALLBACK __export PrjWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  500. {             
  501.   HPEN hPen;
  502.   RECT rc;
  503.   POINT pt;                   
  504.   HDC hDC;
  505.   int i;
  506.   static HBITMAP hBmpPrjUp=NULL,hBmpPrjDn=NULL,hBmpPrjDs=NULL;
  507.   static int CurSelBtn=-1;
  508.   static WORD gState=0;
  509.   HBITMAP hBmp;
  510.   HDC hMemDC; 
  511.   LONG ltmp;               
  512.   WORD wState;
  513.   PAINTSTRUCT ps;
  514.   
  515.   switch(message)
  516.   {
  517.     case WM_CREATE:   
  518.       hBmpPrjUp = LoadBitmap(hInst,"BMP_PRJUP");
  519.       if(hBmpPrjUp == NULL){
  520.         ErrorMessage("error load resource BMP_PRJUP");
  521.         DestroyWindow(hWnd);        
  522.         return -1;
  523.       }                                                          
  524.       
  525.       hBmpPrjDn = LoadBitmap(hInst,"BMP_PRJDN");
  526.       if(hBmpPrjDn == NULL){
  527.         ErrorMessage("error load resource BMP_PRJDN");
  528.         DestroyWindow(hWnd);        
  529.         return -1;
  530.       }  
  531.       hBmpPrjDs = LoadBitmap(hInst,"BMP_PRJDS");
  532.       if(hBmpPrjDs == NULL){
  533.         ErrorMessage("error load resource BMP_PRJDS");
  534.         DestroyWindow(hWnd);        
  535.         return -1;
  536.       }  
  537.     break;
  538.     
  539.     case WM_DRAWBUTTON:
  540.       hBmp = NULL;
  541.       if(CurSelBtn<0)
  542.       {             
  543.         if( hBmpPrjUp == NULL) return 0L;
  544.         hMemDC = CreateCompatibleDC ((HDC)wParam) ;
  545.         SelectObject (hMemDC, hBmpPrjUp) ;
  546.         for(i=0;i<PRJ_BTN_COUNT;i++)
  547.         {
  548.           BitBlt ((HDC)wParam, PrjBtn[i].left, PrjBtn[i].top, 
  549.                     PRJ_BTN_WIDTH, PRJ_BTN_HEIGHT,
  550.                     hMemDC,1+i*(PRJ_BTN_WIDTH+1) , 1, SRCCOPY) ;
  551.         }
  552.         DeleteDC (hMemDC) ;           
  553.         return 0L;
  554.       }
  555.       else
  556.       {
  557.         if(CurSelBtn>=PRJ_BTN_COUNT) return 0L;
  558.         switch(lParam)
  559.         {                                      
  560.           case 0L:
  561.             hBmp=hBmpPrjUp;
  562.           break;
  563.           case 1L:         
  564.             hBmp=hBmpPrjDn;
  565.           break;
  566.           case 2L:         
  567.             hBmp=hBmpPrjDs;
  568.           break;
  569.         }
  570.         if(hBmp==NULL) return 0L;
  571.         hDC=GetDC(hWnd);
  572.         hMemDC = CreateCompatibleDC (hDC) ;
  573.         SelectObject (hMemDC, hBmp) ;
  574.         BitBlt (hDC, PrjBtn[CurSelBtn].left, PrjBtn[CurSelBtn].top, 
  575.                     PRJ_BTN_WIDTH, PRJ_BTN_HEIGHT,
  576.                     hMemDC,1+CurSelBtn*(PRJ_BTN_WIDTH+1) , 1, SRCCOPY) ;
  577.         DeleteDC (hMemDC) ;           
  578.         ReleaseDC(hWnd,hDC);
  579.       }
  580.     return 0;              
  581.     
  582.     case WM_SETCURSOR:
  583.       SetCursor(LoadCursor(NULL,IDC_ARROW));
  584.       isInSlip = FALSE;
  585.     return TRUE;
  586.     
  587.     case WM_LBUTTONDBLCLK:
  588.     case WM_LBUTTONDOWN:
  589.       pt=MAKEPOINT(lParam);
  590.       for(i=0;i<PRJ_BTN_COUNT;i++)
  591.       {
  592.         SetRect(&rc,PrjBtn[i].left,PrjBtn[i].top,
  593.               PrjBtn[i].left+PRJ_BTN_WIDTH,PrjBtn[i].top+PRJ_BTN_HEIGHT);
  594.         if (PtInRect(&rc, pt))
  595.           break;
  596.       }         
  597.       if(i==PRJ_BTN_COUNT) CurSelBtn=-1;
  598.       else
  599.       {          
  600.         CurSelBtn=i;
  601.         SetCapture(hWnd);
  602.         StateSet(gState,STATE_MOUSEDOWN);  
  603.         SendMessage(hWnd,WM_DRAWBUTTON,0,1L);              
  604.       }
  605.     return 0L;
  606.                                                 
  607.     case WM_MOUSEMOVE: 
  608.       if(CurSelBtn==-1) break;        
  609.       if(!StateTest(gState,STATE_MOUSEDOWN)) break;
  610.       pt=MAKEPOINT(lParam); 
  611.       SetRect(&rc,PrjBtn[CurSelBtn].left,PrjBtn[CurSelBtn].top,
  612.         PrjBtn[CurSelBtn].left+PRJ_BTN_WIDTH,PrjBtn[CurSelBtn].top+PRJ_BTN_HEIGHT);
  613.       wState=gState;
  614.       if(PtInRect(&rc,pt))
  615.         StateClear(gState, STATE_MOUSEOUT);
  616.   else
  617.     StateSet(gState, STATE_MOUSEOUT);
  618.   if (wState!=gState)
  619.   {
  620.     if(StateTest(gState,STATE_MOUSEOUT)) ltmp=0L;
  621.     else ltmp=1L;
  622.     SendMessage(hWnd,WM_DRAWBUTTON,0,ltmp);
  623.   }  
  624.     return 0L;
  625.     
  626.     case WM_LBUTTONUP:                 
  627.       if(CurSelBtn==-1) return 0L;
  628.       if(!StateTest(gState,STATE_MOUSEDOWN)) return 0L;
  629.       ReleaseCapture();
  630.       if (StateTest(gState, STATE_MOUSEDOWN))
  631.       {
  632.         StateClear(gState, STATE_MOUSEDOWN);
  633.         if(!StateTest(gState,STATE_MOUSEOUT))
  634.         {
  635.           SendMessage(hWnd,WM_DRAWBUTTON,0,0L);
  636.           SendMessage(hWndMain,WM_COMMAND,PrjBtn[CurSelBtn].ID,0L);
  637.         }   
  638.         else StateClear(gState,STATE_MOUSEOUT);
  639.       }                          
  640.       CurSelBtn=-1;                
  641.     return 0L;
  642.     
  643.     case WM_PAINT:       
  644.       BeginPaint(hWnd,&ps); 
  645.       SelectObject(ps.hdc,GetStockObject(NULL_BRUSH));     
  646.       hPen=CreatePen(PS_SOLID,1,RGB(80,80,80));
  647.       SelectObject(ps.hdc,hPen);
  648.       GetClientRect(hWnd,&rc);
  649.       Rectangle(ps.hdc,0,0,rc.right,rc.bottom);
  650.       SelectObject(ps.hdc,GetStockObject(WHITE_PEN));
  651.       DeleteObject(hPen);
  652.       MoveTo(ps.hdc,0,rc.bottom-1);
  653.       LineTo(ps.hdc,0,0);
  654.       LineTo(ps.hdc,rc.right-1,0);                          
  655.       SelectObject(ps.hdc,GetStockObject(BLACK_PEN));
  656.       for(i=0;i<PRJ_BTN_COUNT;i++)
  657.         Rectangle(ps.hdc,PrjBtn[i].left-1,PrjBtn[i].top-1,
  658.                 PrjBtn[i].left+PRJ_BTN_WIDTH+1,PrjBtn[i].top+PRJ_BTN_HEIGHT+1);
  659.       SendMessage(hWnd,WM_DRAWBUTTON,(WPARAM)(HDC)ps.hdc,0L);          
  660.       EndPaint(hWnd,&ps);
  661.     break; 
  662.     
  663.     case WM_DESTROY:
  664.       if(hBmpPrjUp) DeleteObject(hBmpPrjUp);
  665.       if(hBmpPrjDn) DeleteObject(hBmpPrjDn);
  666.       if(hBmpPrjDs) DeleteObject(hBmpPrjDs);
  667.     break;
  668.     
  669.     default:
  670.     break;
  671.   }
  672.   return (DefWindowProc(hWnd, message, wParam, lParam));
  673. }
  674. long CALLBACK __export StyleWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  675. {                             
  676.   RECT rc;
  677.   HDC hDC,hMemDC;                                                   
  678.   int i;                        
  679.   HPEN hPen;
  680.   DWORD dwExtent;
  681.   POINT pt;
  682.   PAINTSTRUCT ps;           
  683.   int gMouseStart=0L;
  684.   BOOL isStyleMouseDown=FALSE,isStyleMouseOut=FALSE,isLeft =FALSE;
  685.   BOOL fStyleMouseOut =FALSE;                           
  686.   BITMAP bmp;
  687.   int StyleBtnCount =0;
  688.   int CurSelStyle =1000;
  689.   static int OldSelStyle =0;
  690.   int CurBtnStart =0,CurBtnEnd =0;
  691.   HLOCAL hStyleBtns;
  692.   LPSTYLEBTN lpStyleBtns;
  693.   
  694.   switch(message)
  695.   {               
  696.     case WM_CREATE:    
  697.       if(hBrushPat)              
  698.         SetClassWord(hWnd,GCW_HBRBACKGROUND,(WORD)(HBRUSH)hBrushPat);
  699.       SetWindowWord(hWnd,STYLE_COUNT, 0);
  700.       SetWindowWord(hWnd,STYLE_START, 0);
  701.       SetWindowWord(hWnd,STYLE_END,   0);
  702.       SetWindowWord(hWnd,STYLE_SELECT,0);
  703.       SetWindowWord(hWnd,MOUSE_STATE, 0);
  704.       hStyleBtns =LocalAlloc(sizeof(StyleBtnInfo),LMEM_MOVEABLE);
  705.       SetProp(hWnd,"StyleBtns",hStyleBtns);
  706.     break;
  707.     
  708.     case WM_ADDITEM:        
  709.       i=(int)GetWindowWord(hWnd,STYLE_COUNT);  
  710.       hStyleBtns =GetProp(hWnd,"StyleBtns");
  711.       hStyleBtns =LocalReAlloc(hStyleBtns,(i+1)*sizeof(StyleBtnInfo),LMEM_MOVEABLE);
  712.       SetProp(hWnd,"StyleBtns",hStyleBtns);
  713.       lpStyleBtns =(LPSTYLEBTN)LocalLock(hStyleBtns);
  714.       lpStyleBtns[i].ID =wParam;
  715.       lstrcpy(lpStyleBtns[i].Caption,(LPSTR)lParam);
  716.       hDC =GetDC(hWnd);
  717.       SelectObject(hDC, hStyleFont);
  718.       dwExtent =GetTextExtent(hDC,lpStyleBtns[i].Caption,strlen(lpStyleBtns[i].Caption));    
  719.       ReleaseDC(hWnd,hDC);
  720.       if(i==0)
  721.         lpStyleBtns[i].left = 10;
  722.       else
  723.         lpStyleBtns[i].left = lpStyleBtns[i-1].right+5;
  724.       lpStyleBtns[i].right = lpStyleBtns[i].left+LOWORD(dwExtent)+2;
  725.       SetProp(hWnd,"StyleBtns",hStyleBtns);
  726.       SetWindowWord(hWnd,STYLE_COUNT,i+1);
  727.       
  728.       GetClientRect(hWnd,&rc);
  729.       CurBtnEnd =GetWindowWord(hWnd, STYLE_END);
  730.       if(lpStyleBtns[i].right+20 < rc.right) 
  731.       {
  732.         SetWindowWord(hWnd, STYLE_END, i); //CurBtnEnd
  733.         InvalidateRect(hWnd,NULL,TRUE);
  734.       }
  735.       LocalUnlock(hStyleBtns);
  736.     return 0L;
  737.              
  738.     case WM_SIZE:                             
  739.       StyleBtnCount =GetWindowWord(hWnd,STYLE_COUNT);
  740.       CurBtnStart =GetWindowWord(hWnd,STYLE_START);
  741.       CurBtnEnd =GetWindowWord(hWnd,STYLE_END);
  742.       hStyleBtns =GetProp(hWnd,"StyleBtns");
  743.       lpStyleBtns =(LPSTYLEBTN)LocalLock(hStyleBtns);
  744.       for(i=CurBtnStart;i<StyleBtnCount;i++)
  745.       {
  746.         if(lpStyleBtns[i].right+20 >=(int)LOWORD(lParam))
  747.         {
  748.           //CurBtnEnd = i-1; 
  749.           SetWindowWord(hWnd, STYLE_END, i-1);
  750.           break;
  751.         }
  752.       }                        
  753.       if(i == StyleBtnCount) SetWindowWord(hWnd, STYLE_END, i-1);
  754.       InvalidateRect(hWnd,NULL,TRUE);               
  755.       LocalUnlock(hStyleBtns);
  756.     return 0L;
  757.     
  758.     case WM_DRAWBUTTON:
  759.       StyleBtnCount =GetWindowWord(hWnd,STYLE_COUNT);
  760.       CurBtnStart =GetWindowWord(hWnd,STYLE_START);
  761.       CurBtnEnd =GetWindowWord(hWnd,STYLE_END);
  762.       CurSelStyle =GetWindowWord(hWnd,STYLE_SELECT);  
  763.       hStyleBtns =GetProp(hWnd,"StyleBtns");
  764.       lpStyleBtns =(LPSTYLEBTN)LocalLock(hStyleBtns);
  765.       if(wParam!=0 && lParam!=0L)
  766.       {             
  767.         SetTextColor((HDC)wParam,RGB(0,0,0));
  768.         SetBkMode((HDC)wParam,TRANSPARENT);      
  769.         SelectObject((HDC)wParam,hStyleFont);      
  770.         SelectObject((HDC)wParam,GetStockObject(WHITE_BRUSH));
  771.         SelectObject((HDC)wParam,GetStockObject(BLACK_PEN));
  772.         for(i=CurBtnEnd;i>=CurBtnStart;i--)
  773.         {                        
  774.           if(i == CurSelStyle) DrawStyleBtn((HDC)wParam,hWnd,i,1,FALSE,lpStyleBtns);
  775.           else DrawStyleBtn((HDC)wParam,hWnd,i,0,FALSE,lpStyleBtns);
  776.         }
  777.         if(CurBtnStart>0 || CurBtnEnd <StyleBtnCount-1)
  778.         {
  779.           hMemDC=CreateCompatibleDC((HDC)wParam);              
  780.           GetObject(hBmpStyleUp,sizeof(bmp),(LPSTR)&bmp);
  781.           if(CurBtnStart>0)
  782.             SelectObject(hMemDC, hBmpStyleUp);
  783.           else SelectObject(hMemDC,hBmpStyleDs);
  784.           BitBlt((HDC)wParam,(int)lParam-bmp.bmWidth-1,4,bmp.bmWidth/2+1,
  785.                      bmp.bmHeight,hMemDC,0,0,SRCCOPY);
  786.           if(CurBtnEnd <StyleBtnCount-1)
  787.             SelectObject(hMemDC, hBmpStyleUp);
  788.           else SelectObject(hMemDC,hBmpStyleDs);
  789.           BitBlt((HDC)wParam,(int)lParam-bmp.bmWidth/2-1,4,bmp.bmWidth/2,
  790.                      bmp.bmHeight,hMemDC,bmp.bmWidth/2+1,0,SRCCOPY);   
  791.           DeleteDC(hMemDC);           
  792.         }
  793.       }
  794.       else if(wParam ==0)
  795.       {
  796.         if(lParam >0L)
  797.         {            
  798.           switch(lParam)                  
  799.           {
  800.             case 1L: //left up
  801.             break;
  802.             case 2L: //left dn
  803.             break;
  804.             case 3L: //left ds
  805.             break;
  806.             case 4L: //right up
  807.             break;
  808.             case 5L: //right dn
  809.             break;
  810.             case 6L: //right ds
  811.             break;
  812.             default:                                 
  813.               LocalUnlock(hStyleBtns);
  814.             return 0L;
  815.           }
  816.         }
  817.         else if(CurSelStyle >=CurBtnStart && CurSelStyle <=CurBtnEnd)
  818.         {
  819.           if(CurSelStyle == OldSelStyle) return 0L;
  820.           hDC = GetDC(hWnd);
  821.           SelectObject(hDC,GetStockObject(WHITE_BRUSH));
  822.           SelectObject(hDC,GetStockObject(BLACK_PEN));
  823.           SetBkMode(hDC,TRANSPARENT);
  824.           SelectObject(hDC,hStyleFont);
  825.           DrawStyleBtn(hDC, hWnd, OldSelStyle,0,TRUE,lpStyleBtns);
  826.           if(CurSelStyle != OldSelStyle-1)
  827.             DrawStyleBtn(hDC, hWnd,OldSelStyle-1,2,FALSE,lpStyleBtns);
  828.           DrawStyleBtn(hDC, hWnd, CurSelStyle,1,FALSE,lpStyleBtns); 
  829.           ReleaseDC(hWnd,hDC);
  830.         }                             
  831.         LocalUnlock(hStyleBtns);
  832.       } 
  833.     return 0;              
  834.     
  835.     case WM_LBUTTONDBLCLK:
  836.     case WM_LBUTTONDOWN:        
  837.       CurBtnStart =GetWindowWord(hWnd, STYLE_START);
  838.       CurBtnEnd =GetWindowWord(hWnd, STYLE_END);
  839.       OldSelStyle =GetWindowWord(hWnd, STYLE_SELECT);
  840.       hStyleBtns =GetProp(hWnd, "StyleBtns");
  841.       lpStyleBtns =(LPSTYLEBTN)LocalLock(hStyleBtns);
  842.       pt=MAKEPOINT(lParam);
  843.       for(i=CurBtnStart;i<=CurBtnEnd;i++)
  844.       {
  845.         SetRect(&rc,lpStyleBtns[i].left,0,
  846.               lpStyleBtns[i].right+5,STYLE_BTN_HEIGHT);
  847.         if (PtInRect(&rc, pt))
  848.           break;
  849.       }         
  850.       LocalUnlock(hStyleBtns);
  851.       if(i == CurBtnEnd+1) SetWindowWord(hWnd,STYLE_SELECT,1000);
  852.       else
  853.       {          
  854.         SetWindowWord(hWnd,STYLE_SELECT ,i);
  855.         SendMessage(hWnd,WM_DRAWBUTTON,0,0L);              
  856.         SendMessage(GetParent(hWnd),WM_COMMAND,IDW_STYLE,(LONG)i);
  857.       }
  858.     return 0L;       
  859.     
  860.     case WM_SETCURSOR:
  861.       SetCursor(LoadCursor(NULL,IDC_ARROW));
  862.       isInSlip = FALSE;
  863.     return TRUE;
  864.                                                 
  865.     case WM_PAINT:       
  866.       GetClientRect(hWnd,&rc);
  867.       BeginPaint(hWnd,&ps);   
  868.       SelectObject(ps.hdc,hStyleFont);
  869.       hPen = CreatePen(PS_SOLID,1,RGB(80,80,80));
  870.       SelectObject(ps.hdc,hPen);
  871.       MoveTo(ps.hdc,0,0);         
  872.       LineTo(ps.hdc,rc.right,0);
  873.       SelectObject(ps.hdc,GetStockObject(BLACK_PEN));
  874.       DeleteObject(hPen);
  875.       MoveTo(ps.hdc,0,1);
  876.       LineTo(ps.hdc,rc.right,1);      
  877.       SendMessage(hWnd,WM_DRAWBUTTON,(WPARAM)(HDC)ps.hdc,(LONG)rc.right);
  878.       EndPaint(hWnd,&ps);
  879.     return 0L;
  880.                        
  881.     case WM_DESTROY:                       
  882.       hStyleBtns =GetProp(hWnd,"StyleBtns");
  883.       LocalFree(hStyleBtns);
  884.       RemoveProp(hWnd,"StyleBtns");
  885.     break;
  886.                        
  887.     default:
  888.     break;
  889.   }
  890.   return (DefWindowProc(hWnd, message, wParam, lParam));
  891. }
  892. /*
  893. long CALLBACK __export CtlWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  894. {             
  895.   RECT rc;        
  896.   static int CurSelCtl =-1;
  897.   static int CurStyle =0;
  898.   PAINTSTRUCT ps;           
  899.   HPEN hPen;  
  900.   HBITMAP hBmp;
  901.   static HBITMAP hBmpUpCtl[STYLE_MAX_COUNT],hBmpDnCtl[STYLE_MAX_COUNT],hBmpDsCtl[STYLE_MAX_COUNT];
  902.   static HBITMAP hBmpUpLeft,hBmpDnLeft,hBmpDsLeft,
  903.                  hBmpUpRight,hBmpDnRight,hBmpDsRight,
  904.                  hBmpArrow;  
  905.   static int CurCtlStart[STYLE_MAX_COUNT],CurCtlEnd[STYLE_MAX_COUNT],CurCtlCount[STYLE_MAX_COUNT];
  906.   static int ctlWidth =0;
  907.   static int ctlXStart =0;
  908.   static BOOL isCtlMouseDown =0,isCtlMouseOut =FALSE,isLeft =0; 
  909.   static BOOL fCtlMouseOut =0;
  910.   int xStart =0;
  911.   HDC hMemDC,hDC;                       
  912.   POINT pt;                                            
  913.   BITMAP bmp;                
  914.   int i,j;
  915.   char stmp[100];
  916.   
  917.   switch(message)            
  918.   {                          
  919.     case WM_CREATE:
  920.       hBmpUpLeft = LoadBitmap(hInst,"BMP_UPLEFT");
  921.       hBmpDnLeft = LoadBitmap(hInst,"BMP_DNLEFT");
  922.       hBmpDsLeft = LoadBitmap(hInst,"BMP_DSLEFT");
  923.       hBmpUpRight = LoadBitmap(hInst,"BMP_UPRIGHT");
  924.       hBmpDnRight = LoadBitmap(hInst,"BMP_DNRIGHT");
  925.       hBmpDsRight = LoadBitmap(hInst,"BMP_DSRIGHT");
  926.       hBmpArrow = LoadBitmap(hInst,"BMP_ARROW");                   
  927.       if(!hBmpUpLeft || !hBmpUpRight || !hBmpArrow
  928.          || !hBmpDnLeft || !hBmpDsLeft || !hBmpDnRight || !hBmpDsRight)
  929.       {
  930.         ErrorMessage("Error Load Ctl Bitmap");
  931.         return -1;    
  932.       }  
  933.       
  934.       //// /////
  935.       for(i=0;i<2;i++)
  936.       {        
  937.         wsprintf(stmp,"BMP_UPSTYLE%d",i);
  938.         hBmpUpCtl[i] = LoadBitmap(hInst, stmp); 
  939.         wsprintf(stmp,"BMP_DNSTYLE%d",i);
  940.         hBmpDnCtl[i] = LoadBitmap(hInst, stmp); 
  941.         if(!hBmpUpCtl[i] || !hBmpDnCtl[i])
  942.         {
  943.           ErrorMessage("Error Load Ctl Bitmap");
  944.           return -1;    
  945.         }  
  946.       }
  947.       xStart =0;
  948.       GetObject(hBmpArrow,sizeof(bmp),(LPSTR)&bmp);
  949.       ctlWidth = bmp.bmHeight-1;
  950.       xStart = bmp.bmWidth+5;                       
  951.       GetObject(hBmpUpLeft,sizeof(bmp),(LPSTR)&bmp);
  952.       xStart += bmp.bmWidth*2+10;
  953.       ctlXStart =xStart-bmp.bmWidth;
  954.       GetClientRect(hWnd,&rc);
  955.       for(i=0;i<2;i++)
  956.       {
  957.         GetObject(hBmpUpCtl[i],sizeof(bmp),(LPSTR)&bmp);
  958.         CurCtlStart[i] =0;
  959.         CurCtlCount[i] =bmp.bmWidth/(bmp.bmHeight-1);
  960.         CurCtlEnd[i] =(rc.right-xStart-3)/(bmp.bmHeight-1);  
  961.         if(CurCtlEnd[i]>CurCtlCount[i]) CurCtlEnd[i] =CurCtlCount[i];
  962.       }
  963.     break;
  964.     
  965.     case WM_SIZE: 
  966.       xStart =0;
  967.       GetObject(hBmpArrow,sizeof(bmp),(LPSTR)&bmp);
  968.       xStart = bmp.bmWidth+5;
  969.       GetObject(hBmpUpLeft,sizeof(bmp),(LPSTR)&bmp);
  970.       xStart += bmp.bmWidth*2+10;
  971.       for(i=0;i<2;i++)
  972.       {
  973.         GetObject(hBmpUpCtl[i],sizeof(bmp),(LPSTR)&bmp);
  974.         if(gSlipped)
  975.         {
  976.           if(i==CurStyle)
  977.             j =CurCtlStart[i]; 
  978.           CurCtlStart[i] =CurCtlEnd[i]-(LOWORD(lParam)-xStart-3)/(bmp.bmHeight-1);
  979.           if(CurCtlStart[i]<0) CurCtlStart[i] =0;
  980.           if(xStart+3+(CurCtlEnd[i]-CurCtlStart[i])*ctlWidth<(int)LOWORD(lParam))
  981.           {
  982.             CurCtlEnd[i] +=(LOWORD(lParam)
  983.                   -(xStart+3+(CurCtlEnd[i]-CurCtlStart[i])*ctlWidth))/ctlWidth;
  984.             if(CurCtlEnd[i]>CurCtlCount[i]) CurCtlEnd[i] =CurCtlCount[i];
  985.           }
  986.           if(i==CurStyle)
  987.           {
  988.             j =CurCtlStart[i]-j;
  989.             if(CurSelCtl >=0)
  990.               CurSelCtl -=j;
  991.           }    
  992.         }
  993.         else
  994.         {
  995.           if(xStart+3+(CurCtlEnd[i]-CurCtlStart[i])*ctlWidth<(int)LOWORD(lParam))
  996.           {
  997.             if(i==CurStyle)
  998.               j =CurCtlStart[i]; 
  999.             CurCtlStart[i] -=(LOWORD(lParam)
  1000.                   -(xStart+3+(CurCtlEnd[i]-CurCtlStart[i])*ctlWidth))/ctlWidth;
  1001.             if(CurCtlStart[i]<0) CurCtlStart[i] =0;
  1002.             if(i==CurStyle)
  1003.             {
  1004.               j =CurCtlStart[i]-j;
  1005.               if(CurSelCtl >=0)
  1006.                 CurSelCtl -=j;
  1007.             }    
  1008.           }
  1009.           CurCtlEnd[i] =(LOWORD(lParam)-xStart-3)/(bmp.bmHeight-1)+CurCtlStart[i];
  1010.           if(CurCtlEnd[i]>CurCtlCount[i]) CurCtlEnd[i]=CurCtlCount[i];
  1011.         }  
  1012.       }
  1013.       InvalidateRect(hWnd,NULL,TRUE);
  1014.     return 0L;
  1015.     
  1016.     case WM_STYLECHANGED:
  1017.       if(CurStyle ==(int)wParam) break;
  1018.       CurSelCtl =-1;
  1019.       CurStyle =(int)wParam;
  1020.       //if(CurStyle>1) return 0L;                          
  1021.       InvalidateRect(hWnd,NULL,TRUE);
  1022.     return 0L;
  1023.     
  1024.     case WM_DRAWBUTTON:
  1025.       if(wParam!=0)
  1026.       {
  1027.         //draw all the button: CurStyle -- BtnStart to BtnEnd
  1028.         hDC = (HDC)wParam;
  1029.         hMemDC = CreateCompatibleDC (hDC) ;   
  1030.         xStart =0;
  1031.         //if(hBmpArrow)
  1032.         {
  1033.           SelectObject(hMemDC,hBmpArrow);
  1034.           GetObject(hBmpArrow,sizeof(bmp),(LPSTR)&bmp);
  1035.           xStart =5;
  1036.           BitBlt (hDC, xStart,5,
  1037.                   bmp.bmWidth,bmp.bmHeight,hMemDC,0,0,SRCCOPY) ;
  1038.           xStart =xStart+bmp.bmWidth+10;        
  1039.         } 
  1040.         //if(hBmpCtlLeft)
  1041.         {
  1042.           if(CurCtlStart[CurStyle]>0)
  1043.             SelectObject(hMemDC,hBmpUpLeft);
  1044.           else SelectObject(hMemDC,hBmpDsLeft);  
  1045.           GetObject(hBmpUpLeft,sizeof(bmp),(LPSTR)&bmp);
  1046.           BitBlt (hDC, xStart,5,
  1047.                   bmp.bmWidth,bmp.bmHeight,hMemDC,0,0,SRCCOPY) ;
  1048.           xStart +=bmp.bmWidth;
  1049.         }
  1050.         //if(hBmpCtl[CurStyle])
  1051.         {         
  1052.           SelectObject (hMemDC, hBmpUpCtl[CurStyle]) ;    
  1053.           GetObject(hBmpUpCtl[CurStyle],sizeof(bmp),(LPSTR)&bmp);
  1054.           BitBlt (hDC, xStart,5,
  1055.                   (CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])*(bmp.bmHeight-1),
  1056.                   bmp.bmHeight,hMemDC,
  1057.                   CurCtlStart[CurStyle]*(bmp.bmHeight-1),0,SRCCOPY) ;
  1058.           if(CurSelCtl>=0
  1059.              && CurSelCtl<CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])
  1060.           {
  1061.             SelectObject(hMemDC,hBmpDnCtl[CurStyle]);
  1062.             BitBlt (hDC, ctlXStart+CurSelCtl*ctlWidth,5,
  1063.                   ctlWidth,ctlWidth+1,hMemDC,
  1064.                   (CurSelCtl+CurCtlStart[CurStyle])*ctlWidth,0,SRCCOPY) ;
  1065.           }            
  1066.           else CurSelCtl =-1;
  1067.           xStart += (CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])*(bmp.bmHeight-1);
  1068.         }
  1069.         //if(hBmpCtlRight)
  1070.         {                                      
  1071.           if(CurCtlEnd[CurStyle]<CurCtlCount[CurStyle])
  1072.             SelectObject(hMemDC,hBmpUpRight);
  1073.           else SelectObject(hMemDC,hBmpDsRight);  
  1074.           GetObject(hBmpUpRight,sizeof(bmp),(LPSTR)&bmp);
  1075.           BitBlt (hDC, xStart,5,
  1076.                   bmp.bmWidth,bmp.bmHeight,hMemDC,0,0,SRCCOPY) ;
  1077.         }                       
  1078.         DeleteDC (hMemDC) ;           
  1079.       }                      
  1080.       else if(wParam ==0)
  1081.       {          
  1082.         if(CurSelCtl <0
  1083.            || CurSelCtl >=(CurCtlEnd[CurStyle]-CurCtlStart[CurStyle]))
  1084.         {
  1085.           CurSelCtl =-1;
  1086.           return 0L;    
  1087.         }  
  1088.         switch(lParam)
  1089.         {
  1090.           case 0L://hbmp=up
  1091.             hBmp =hBmpUpCtl[CurStyle];
  1092.           break;
  1093.           case 1L://hbmp=down  
  1094.             hBmp =hBmpDnCtl[CurStyle];
  1095.           break;
  1096.           case 2L: //hbmp=disable
  1097.           break;
  1098.           case 3L: //left up
  1099.           break;
  1100.           case 4L: //left down
  1101.           break;
  1102.           case 5L: //left disable
  1103.           break;
  1104.           case 6L: //right up
  1105.           break;
  1106.           case 7L: //right down
  1107.           break;
  1108.           case 8L: //right disable
  1109.           break;
  1110.           default:
  1111.           return 0L;
  1112.         }                               
  1113.         //draw the button           
  1114.         hDC=GetDC(hWnd);
  1115.         hMemDC =CreateCompatibleDC(hDC);
  1116.         SelectObject(hMemDC,hBmp);
  1117.         if(lParam <3L)
  1118.           BitBlt (hDC, ctlXStart+CurSelCtl*ctlWidth,5,
  1119.                   ctlWidth,ctlWidth+1,hMemDC,
  1120.                   (CurSelCtl+CurCtlStart[CurStyle])*ctlWidth,0,SRCCOPY) ;
  1121.         DeleteDC(hMemDC);
  1122.         ReleaseDC(hWnd,hDC);
  1123.       }
  1124.     return 0L;           
  1125.     
  1126.     case WM_SETCURSOR:
  1127.       //Set Cursor or Show Hint if in a button or Hide Hint if out a button;
  1128.       SetCursor(LoadCursor(NULL,IDC_ARROW)); 
  1129.       isInSlip = FALSE;
  1130.     return TRUE;                                    
  1131.     
  1132.     case WM_LBUTTONDOWN:
  1133.       pt=MAKEPOINT(lParam);                     
  1134.       if(CurCtlStart[CurStyle]>0)
  1135.       {
  1136.         SetRect(&rc,ctlXStart-ctlWidth/2,5,ctlXStart,5+ctlWidth+1);
  1137.         if(PtInRect(&rc,pt))
  1138.         {                                      
  1139.           isLeft =TRUE;
  1140.           SendMessage(hWnd,WM_DRAWBUTTON,0,4L);
  1141.           SetCapture(hWnd);
  1142.           isCtlMouseDown =TRUE;
  1143.           return 0L;
  1144.         }
  1145.       }  
  1146.       if(CurCtlEnd[CurStyle]<CurCtlCount[CurStyle])
  1147.       {
  1148.         SetRect(&rc,ctlXStart+(CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])*ctlWidth,5,
  1149.                     ctlXStart+(CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])*ctlWidth+ctlWidth/2,
  1150.                     5+ctlWidth+1);
  1151.         if(PtInRect(&rc,pt))
  1152.         {                                      
  1153.           isLeft =FALSE;
  1154.           SendMessage(hWnd,WM_DRAWBUTTON,0,7L);
  1155.           SetCapture(hWnd);
  1156.           isCtlMouseDown =TRUE;
  1157.           return 0L;
  1158.         }
  1159.       }  
  1160.       for(i=0;i<CurCtlEnd[CurStyle]-CurCtlStart[CurStyle];i++)
  1161.       {
  1162.         SetRect(&rc,ctlXStart+i*ctlWidth,5,
  1163.               ctlXStart+(i+1)*ctlWidth,5+ctlWidth+1);
  1164.         if (PtInRect(&rc, pt))
  1165.           break;
  1166.       }         
  1167.       if(i+CurCtlStart[CurStyle] ==CurCtlEnd[CurStyle]) return 0L;
  1168.       else
  1169.       {          
  1170.         SendMessage(hWnd,WM_DRAWBUTTON,0,0L);
  1171.         CurSelCtl=i;//+CurCtlStart[CurStyle];
  1172.         SendMessage(hWnd,WM_DRAWBUTTON,0,1L);              
  1173.         //LoadString(hInst, 11000+CurStyle*100+i,(LPSTR)Cur_Ctl_Style, sizeof(Cur_Ctl_Style));
  1174.       }
  1175.     return 0L;
  1176.     
  1177.     case WM_MOUSEMOVE:   
  1178.       if(!isCtlMouseDown) break;
  1179.       pt=MAKEPOINT(lParam);                     
  1180.       if(isLeft)
  1181.         SetRect(&rc,ctlXStart-ctlWidth/2,5,ctlXStart,5+ctlWidth/2+1);
  1182.       else
  1183.         SetRect(&rc,ctlXStart+(CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])*ctlWidth,5,
  1184.                     ctlXStart+(CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])*ctlWidth+ctlWidth/2,
  1185.                     5+ctlWidth+1);
  1186.       fCtlMouseOut = isCtlMouseOut;
  1187.       if(PtInRect(&rc,pt))
  1188.         isCtlMouseOut =FALSE;
  1189.       else isCtlMouseOut =TRUE;
  1190.       if(fCtlMouseOut !=isCtlMouseOut)
  1191.       {
  1192.         if(isCtlMouseOut)
  1193.         {
  1194.           if(isLeft)
  1195.             SendMessage(hWnd,WM_DRAWBUTTON, 0,3L);
  1196.           else SendMessage(hWnd,WM_DRAWBUTTON,0,6L);
  1197.         }
  1198.         else
  1199.         {
  1200.           if(isLeft)
  1201.             SendMessage(hWnd,WM_DRAWBUTTON,0,4L);
  1202.           else SendMessage(hWnd,WM_DRAWBUTTON,0,7L);
  1203.         }  
  1204.       }  
  1205.     return 0L;
  1206.     
  1207.     case WM_LBUTTONUP:
  1208.       if(!isCtlMouseDown) break;
  1209.       ReleaseCapture();
  1210.       isCtlMouseDown =FALSE;
  1211.       if(!isCtlMouseOut)        
  1212.       {                      
  1213.         if(isLeft)
  1214.         {
  1215.           CurCtlStart[CurStyle]--;
  1216.           CurCtlEnd[CurStyle]--;
  1217.           if(CurSelCtl >=0)
  1218.             CurSelCtl++;          /////
  1219.         }
  1220.         else
  1221.         {
  1222.           CurCtlStart[CurStyle]++;
  1223.           CurCtlEnd[CurStyle]++;
  1224.           if(CurSelCtl >=0)
  1225.             CurSelCtl--;    /////
  1226.         }
  1227.         InvalidateRect(hWnd,NULL,TRUE);
  1228.       }
  1229.       else isCtlMouseOut =FALSE;
  1230.     return 0L;
  1231.     
  1232.     case WM_PAINT:
  1233.       GetClientRect(hWnd,&rc);
  1234.       BeginPaint(hWnd,&ps); 
  1235.       hPen = CreatePen(PS_SOLID,1,RGB(80,80,80));
  1236.       SelectObject(ps.hdc,hPen);
  1237.       //MoveTo(ps.hdc,0,rc.bottom-1);         
  1238.       MoveTo(ps.hdc,rc.right-1,rc.bottom-1); 
  1239.       LineTo(ps.hdc,rc.right-1,0);
  1240.       SelectObject(ps.hdc,GetStockObject(WHITE_PEN));
  1241.       DeleteObject(hPen);
  1242.       //MoveTo(ps.hdc,0,1);
  1243.       LineTo(ps.hdc,0,0); 
  1244.       LineTo(ps.hdc,0,rc.bottom-1);    
  1245.       SendMessage(hWnd,WM_DRAWBUTTON,(WPARAM)(HDC)ps.hdc,(LONG)MAKELONG(20,rc.bottom));
  1246.       EndPaint(hWnd,&ps);
  1247.     break;
  1248.              
  1249.     case WM_DESTROY:                               
  1250.       for(i=0;i<2;i++)
  1251.       {
  1252.         if(hBmpUpCtl[i]) DeleteObject(hBmpUpCtl[i]);
  1253.         if(hBmpDnCtl[i]) DeleteObject(hBmpDnCtl[i]);
  1254.         if(hBmpDsCtl[i]) DeleteObject(hBmpDsCtl[i]);
  1255.       }
  1256.       if(hBmpUpLeft) DeleteObject(hBmpUpLeft);
  1257.       if(hBmpUpRight) DeleteObject(hBmpUpRight);
  1258.       if(hBmpDnLeft) DeleteObject(hBmpDnLeft);
  1259.       if(hBmpDnRight) DeleteObject(hBmpDnRight);
  1260.       if(hBmpDsLeft) DeleteObject(hBmpDsLeft);
  1261.       if(hBmpDsRight) DeleteObject(hBmpDsRight);
  1262.       if(hBmpArrow) DeleteObject(hBmpArrow);  
  1263.     break;
  1264.              
  1265.     default:
  1266.     break;
  1267.   }
  1268.   
  1269.   return (DefWindowProc(hWnd, message, wParam, lParam));
  1270. }
  1271. */
  1272. BOOL __export CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1273. {
  1274.     switch (message)
  1275.     {
  1276.         case WM_INITDIALOG:
  1277.             return (TRUE);
  1278.         case WM_COMMAND:
  1279.             if (wParam == IDOK
  1280.                 || wParam == IDCANCEL)
  1281.             {
  1282.                 EndDialog(hDlg, TRUE);
  1283.                 return (TRUE);
  1284.             }
  1285.             break;
  1286.     }
  1287.     return (FALSE);
  1288. }                  
  1289. void DrawStyleBtn(HDC hDC,HWND hWnd,int BtnNo, int Style,BOOL fDrawGray,LPSTYLEBTN StyleBtn)
  1290. {
  1291.   POINT aPoints[5];
  1292.   HPEN hPen; 
  1293.   int CurBtnStart,CurBtnEnd;
  1294.   //HLOCAL hStyleBtns;
  1295.   //LPSTYLEBTN lpStyleBtns;
  1296.   CurBtnStart =GetWindowWord(hWnd, STYLE_START);
  1297.   CurBtnEnd =GetWindowWord(hWnd, STYLE_END);
  1298.   if(BtnNo <CurBtnStart || BtnNo >CurBtnEnd) return;
  1299.   
  1300.   //hStyleBtns =GetProp(hWnd,"STYLEBTNS");
  1301.   //lpStyleBtns =(LPSTYLEBTN)LocalLock(hStyleBtns);
  1302.   if(BtnNo == CurBtnStart)
  1303.     aPoints[0].x = 5;
  1304.   else
  1305.   {
  1306.     if(Style !=2)
  1307.       aPoints[0].x = StyleBtn[BtnNo].left-5; 
  1308.     else if(Style ==2)
  1309.       aPoints[0].x = StyleBtn[BtnNo-1].right+5;
  1310.   }  
  1311.             
  1312.   aPoints[0].y = 1;        
  1313.   
  1314.   switch(Style)
  1315.   {
  1316.     case 0:
  1317.     case 1:
  1318.       aPoints[1].x = StyleBtn[BtnNo].left;
  1319.       aPoints[1].y = STYLE_BTN_HEIGHT;
  1320.       aPoints[2].x = StyleBtn[BtnNo].right;
  1321.       aPoints[2].y = STYLE_BTN_HEIGHT;
  1322.       aPoints[3].x = StyleBtn[BtnNo].right+5;
  1323.       aPoints[3].y = 1;
  1324.           
  1325.       if(Style == 1)
  1326.         SelectObject(hDC,GetStockObject(LTGRAY_BRUSH));
  1327.           
  1328.       Polygon(hDC,aPoints,4);
  1329.       if(Style == 1)
  1330.       {                                              
  1331.         hPen = CreatePen(PS_SOLID,2,RGB(180,180,180));
  1332.         SelectObject(hDC,hPen);
  1333.         MoveTo(hDC,aPoints[0].x+2,aPoints[0].y);
  1334.         LineTo(hDC,aPoints[3].x-2,aPoints[3].y);
  1335.         SelectObject(hDC,GetStockObject(WHITE_PEN));
  1336.         DeleteObject(hPen);
  1337.         MoveTo(hDC,aPoints[0].x+1,aPoints[0].y);
  1338.         LineTo(hDC,aPoints[1].x+1,aPoints[1].y-1);
  1339.         hPen = CreatePen(PS_SOLID,1,RGB(80,80,80));
  1340.         SelectObject(hDC,hPen);
  1341.         LineTo(hDC,aPoints[2].x-1,aPoints[2].y-1);
  1342.         LineTo(hDC,aPoints[3].x-1,aPoints[3].y);
  1343.         SelectObject(hDC,GetStockObject(BLACK_PEN));
  1344.         DeleteObject(hPen);
  1345.         SelectObject(hDC,GetStockObject(WHITE_BRUSH));
  1346.         SetTextColor(hDC,RGB(0,0,255));
  1347.       }                                              
  1348.       else if(fDrawGray)
  1349.       {
  1350.         hPen = CreatePen(PS_SOLID,1,RGB(80,80,80));
  1351.         SelectObject(hDC,hPen);
  1352.         MoveTo(hDC,aPoints[0].x,0);
  1353.         LineTo(hDC,aPoints[3].x,0);
  1354.         SelectObject(hDC,GetStockObject(BLACK_PEN));
  1355.         DeleteObject(hPen);
  1356.       }
  1357.     break;
  1358.     
  1359.     case 2:                        
  1360.       aPoints[1].x = StyleBtn[BtnNo].left-3;
  1361.       aPoints[1].y = STYLE_BTN_HEIGHT/2;
  1362.       aPoints[2].x = StyleBtn[BtnNo].left;
  1363.       aPoints[2].y = STYLE_BTN_HEIGHT;
  1364.       aPoints[3].x = StyleBtn[BtnNo].right;
  1365.       aPoints[3].y = STYLE_BTN_HEIGHT;
  1366.       aPoints[4].x = StyleBtn[BtnNo].right+5;
  1367.       aPoints[4].y = 1;
  1368.       Polygon(hDC,aPoints,5);
  1369.     break;  
  1370.     
  1371.     default:               
  1372.       //LocalUnlock(hStyleBtns);
  1373.     return;      
  1374.   }
  1375.   TextOut(hDC,StyleBtn[BtnNo].left+1,3,(LPSTR)StyleBtn[BtnNo].Caption,
  1376.                  strlen(StyleBtn[BtnNo].Caption));    
  1377.   if(Style ==1) SetTextColor(hDC,RGB(0,0,0));               
  1378.   //LocalUnlock(hStyleBtns);
  1379. }
  1380. HWND CreateNewForm(void)
  1381. {
  1382.     static int FormNum =0;
  1383.     char tmp[40];
  1384.     HWND hWnd;
  1385.     FormNum++;
  1386.     wsprintf((LPSTR)tmp,"Form%d",FormNum);
  1387.     hWnd = CreateWindow( "LGFORM",tmp,
  1388.                    WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX
  1389.                    |WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_THICKFRAME,
  1390.                    130,100,500,300,
  1391.                    NULL, NULL, hInst, NULL
  1392.             );
  1393.     if (!hWnd)
  1394.       return NULL;
  1395.     
  1396.     ShowWindow(hWnd, SW_SHOW);
  1397.     UpdateWindow(hWnd);
  1398.     return hWnd;
  1399. }
  1400. void ErrorMessage(LPSTR lpszMsg)
  1401. {
  1402.   MessageBox(NULL,lpszMsg,"CBuilder",MB_TASKMODAL |MB_ICONSTOP |MB_OK);
  1403. }
  1404. BOOL isWndClass(HWND hWnd,LPSTR ClassName)
  1405. {                                            
  1406.   static char tmp[40];
  1407.   if(!GetClassName(hWnd, (LPSTR)tmp, sizeof(tmp))) return FALSE;
  1408.   return (lstrcmpi((LPSTR)tmp, (LPSTR)ClassName)==0); 
  1409. }