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

Delphi控件源码

开发平台:

Visual C++

  1. #include <windows.h>
  2. #include "appmain.h"
  3. #include "inspproc.h"
  4. HWND hWndInspStyle, hWndObject, hWndSelect,hWndPropList;
  5. long CALLBACK __export InspWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  6. {     
  7.   RECT rc;
  8.   MINMAXINFO FAR *lpmmi; 
  9.   PAINTSTRUCT ps;          
  10.   HPEN hPen;               
  11.   HDC hMemDC;
  12.   static HBITMAP hBmpDListUp,hBmpDListDn;   
  13.   static int BmpHeight =0;
  14.   BITMAP bmp;
  15.   
  16.   switch(message)
  17.   {
  18.     case WM_CREATE:                               
  19.       GetClientRect(hWnd,&rc);
  20.       hWndInspStyle = CreateWindow("WNDSTYLE", "",WS_CHILD|WS_VISIBLE,
  21.                      0, rc.bottom-19, rc.right, 19,
  22.                      hWnd, IDW_STYLE, hInst, NULL);        
  23.       if(hWndInspStyle ==NULL)              
  24.       {
  25.         ErrorMessage("Create WndInspStyle failed!");
  26.         return -1;                                                   
  27.       }                                                              
  28.       SendMessage(hWndInspStyle,WM_ADDITEM,IDW_STYLE,(LPARAM)(LPSTR)"特征");
  29.       SendMessage(hWndInspStyle,WM_ADDITEM,IDW_STYLE+1,(LPARAM)(LPSTR)"方法");
  30.       SendMessage(hWndInspStyle,WM_ADDITEM,IDW_STYLE+2,(LPARAM)(LPSTR)"事件");
  31.       hBmpDListUp =LoadBitmap(hInst, "BMP_DLISTUP");
  32.       hBmpDListDn =LoadBitmap(hInst, "BMP_DLISTDN");            
  33.       if(!hBmpDListUp |!hBmpDListDn)
  34.       {
  35.          ErrorMessage("Load BMP_DLIST Failed!");
  36.          return -1;
  37.       }
  38.       
  39.       GetObject(hBmpDListUp, sizeof(bmp),(LPSTR)&bmp);
  40.       
  41.       BmpHeight =bmp.bmHeight;
  42.       
  43.       hWndObject =CreateWindow("LISTBOX","",WS_CHILD |LBS_SORT |WS_VSCROLL,
  44.                   3,3+BmpHeight,rc.right-6,100,
  45.                   hWnd, IDW_OBJECT, hInst, NULL);    
  46.       if(hWndObject ==NULL)
  47.       {
  48.         ErrorMessage("Create Object List failed!");
  49.         return -1;          
  50.       }                
  51.       
  52.       hWndPropList = CreateWndPropList( hWnd, 0, 3+BmpHeight+4, rc.right+1, 
  53.                         rc.bottom-20-BmpHeight-STYLE_WND_HEIGHT );
  54.       if(hWndPropList ==NULL)              
  55.       {
  56.         ErrorMessage("Create WndPropList failed!");
  57.         return -1;                                                   
  58.       }                                                              
  59.     return 0L;
  60.     
  61.     case WM_ACTIVATEAPP:                               
  62.       if(wParam)
  63.         SetActiveWindow(hWnd);
  64.     break;
  65.     
  66.     case WM_SETFOCUS:
  67.     return 0L;
  68.     
  69.     case WM_GETMINMAXINFO:
  70.       lpmmi=(MINMAXINFO FAR *)lParam;
  71.       lpmmi->ptMinTrackSize.x=120;
  72.       lpmmi->ptMinTrackSize.y=200;
  73.     break;
  74.                                                        
  75.     case WM_SIZE:                                      
  76.       if(wParam == SIZE_MINIMIZED) break;
  77.       MoveWindow(hWndInspStyle, 0, HIWORD(lParam)-19,
  78.                       LOWORD(lParam),19,TRUE);     
  79.       MoveWindow(hWndPropList, 0, 3+BmpHeight+4, LOWORD(lParam)+1, 
  80.                         HIWORD(lParam)-20-BmpHeight-STYLE_WND_HEIGHT,TRUE );
  81.     return 0L;
  82.     case WM_PAINT:
  83.       BeginPaint(hWnd,&ps); 
  84.       GetClientRect(hWnd,&rc);        
  85.       SelectObject(ps.hdc, GetStockObject(WHITE_BRUSH));
  86.       SelectObject(ps.hdc, GetStockObject(BLACK_PEN));
  87.       Rectangle(ps.hdc, 3,3,rc.right-3,BmpHeight+3);
  88.       hPen =CreatePen(PS_SOLID,1,RGB(80,80,80));
  89.       SelectObject(ps.hdc,hPen);
  90.       MoveTo(ps.hdc,2,BmpHeight+2);
  91.       LineTo(ps.hdc,2,2); 
  92.       LineTo(ps.hdc,rc.right-3,2);
  93.       MoveTo(ps.hdc,0,BmpHeight+5);
  94.       LineTo(ps.hdc,rc.right,BmpHeight+5); 
  95.       SelectObject(ps.hdc,GetStockObject(WHITE_PEN));
  96.       DeleteObject(hPen);
  97.       MoveTo(ps.hdc, 3,BmpHeight+3);
  98.       LineTo(ps.hdc, rc.right-3,BmpHeight+3);
  99.       LineTo(ps.hdc, rc.right-3,2);
  100.       MoveTo(ps.hdc, 0,BmpHeight+6);
  101.       LineTo(ps.hdc, rc.right,BmpHeight+6);
  102.       hMemDC =CreateCompatibleDC(ps.hdc);
  103.       SelectObject(hMemDC, hBmpDListUp);    
  104.       GetObject(hBmpDListUp, sizeof(bmp),(LPSTR)&bmp);
  105.       BitBlt(ps.hdc, rc.right-3-bmp.bmWidth,3,bmp.bmWidth,bmp.bmHeight,
  106.                 hMemDC, 0,0,SRCCOPY);
  107.       DeleteObject(hMemDC);
  108.       EndPaint(hWnd,&ps);                   
  109.     break;
  110.       
  111.     case WM_SYSCOMMAND:
  112.       switch(wParam)
  113.       {
  114.         case SC_KEYMENU:
  115.           hWndPrev =hWnd;
  116.           SetFocus(hWndMain);
  117.           SendMessage(hWndMain,WM_SYSCOMMAND,wParam,lParam);
  118.         return 0L;
  119.         
  120.         case SC_PREVWINDOW:
  121.         break;
  122.       }  
  123.     break;
  124.     
  125.     case WM_CLOSE:
  126.       ShowWindow(hWnd,SW_HIDE);
  127.     return 0L;
  128.     
  129.     case WM_DESTROY:                             
  130.       if(hBmpDListUp) DeleteObject(hBmpDListUp);
  131.       if(hBmpDListDn) DeleteObject(hBmpDListDn);
  132.       hWndInsp =NULL; 
  133.     break;
  134.     
  135.     default:
  136.     break;
  137.   }  
  138.   return (DefWindowProc(hWnd, message, wParam, lParam));
  139. }
  140. HWND CreateWndPropList(HWND hWndParent,int left, int top, int width,int height)
  141. {
  142.   HWND hWnd;
  143.   WNDCLASS wc;
  144.   
  145.   wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  146.   wc.lpfnWndProc = PropListWndProc;
  147.   wc.cbClsExtra = 0;
  148.   wc.cbWndExtra = 0;
  149.   wc.hInstance = hInst;
  150.   wc.hIcon = LoadIcon(hInst, "ICON_YW");
  151.   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  152.   wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  153.   wc.lpszMenuName =  NULL;
  154.   wc.lpszClassName = "PROPLISTBOX";
  155.   if(!RegisterClass(&wc)) return NULL;
  156.     
  157.   hWnd = CreateWindow("PROPLISTBOX", "PropListBox",
  158.                WS_CHILD|WS_VISIBLE|LBS_NOTIFY|LBS_OWNERDRAWFIXED|LBS_NOINTEGRALHEIGHT
  159.                |WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_VSCROLL,
  160.                left,top,width,height,
  161.                hWndParent, IDW_STYLE, hInst, NULL);        
  162.   return hWnd;
  163. }
  164. long CALLBACK __export PropListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  165. {     
  166.   return (DefWindowProc(hWnd, message, wParam, lParam));
  167. }