一个显示地图数据,并实现简单浏览查询程序源码(SDK编写)

一个显示地图数据,并实现简单浏览查询程序源码(SDK编写)

//--------------------
// written by zhengv
//--------------------
#include
#include
#include
#include
#include
#include "resource.h"
#pragma warning(disable : 4244)
typedef struct
{
 float x;
 float y;
}FPOINT;
typedef struct
{
 float bottom;
 float right;
 float left;
 float top;
}FRECT;
typedef struct

 unsigned long id;
 unsigned long type;
 unsigned long pt_num;
 BOOL isflash;
 FPOINT* ppoints;
}CELL, *PCELL;
enum Opt{OPT_NONE, OPT_MOVE, OPT_MOVE1, OPT_IN, OPT_IN1, OPT_OUT, OPT_OUT1, OPT_OUT2};
BOOL ReadData(const char *, PCELL*, int*); //从.usr文件读取数据放到pc里
BOOL FreeData(); //释放数据
LRESULT CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM); //主对话框消息处理函数
LRESULT CALLBACK SearchByIDDlgProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK SearchByTypeDlgProc(HWND, UINT, WPARAM, LPARAM);
BOOL DrawData(HWND, PCELL, long, long, long); //画数据
BOOL GetColorAndWidth(unsigned long, COLORREF *, COLORREF *, int *); //取不同类型对象的颜色和线条宽度
BOOL Reset(); //显示复位
BOOL GetMaxRect(); //得到地图数据区域
BOOL FlashData(HWND, PCELL, long, long, long, COLORREF); //闪烁
BOOL UnFlashData(HWND, PCELL, long, long, long); //取消闪烁
PCELL pc = NULL; //数据
unsigned int cel_num; //
long s,c,d; //s 放大倍数 c x坐标位移 d y坐标位移
HWND hWnd; //主窗口
FRECT MaxRect; //地图数据区域
enum Opt copt; //当前操作
POINT fp,sp,cp; //
HINSTANCE hInst;
unsigned long types[9] = {0};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
     LPSTR lpCmdLine, int nShowCmd)
{
 return DialogBox(hInstance,MAKEINTRESOURCE(DLG_MAIN),NULL,MainDlgProc);
}
BOOL ReadData(const char * FileName, PCELL *pCell, int* cel_num)

 FILE * fp;
 CELL newCell;
 unsigned int i,j,m,n;
 *cel_num = 0;
 j = 0;
 *pCell = NULL;
 fp = fopen(FileName,"r");
 if(fp==NULL)
  return FALSE;
 n = 0;
 do
 {
  newCell.ppoints = NULL;
  fscanf(fp,"%lu,0",&newCell.id); //id
  if(newCell.id == -999999)
  {
   break;
  }
  fscanf(fp,"%lu,0",&newCell.type); //type
  
  //points
  m = 0;
  i = 0;
  do
  {
   i += sizeof(FPOINT);
   newCell.ppoints = (FPOINT*)realloc(newCell.ppoints,i);
   
   fscanf(fp, "%f,%f",
          &newCell.ppoints[i/sizeof(FPOINT)-1].x,
          &newCell.ppoints[i/sizeof(FPOINT)-1].y);
   m++;
  }
  while(newCell.ppoints[i/sizeof(FPOINT)-1].x != -666666.0);
  newCell.pt_num = m-1;
                //add to pCELL
  j += sizeof(CELL);
  *pCell = (PCELL)realloc(*pCell,j);
  (*pCell)[j/sizeof(CELL)-1] = newCell;
  n++;
 }
 while(TRUE);
 *cel_num = n;
 GetMaxRect();
 //复位
 Reset();
 return TRUE;
}
LRESULT CALLBACK MainDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
        PAINTSTRUCT ps;
        HDC hdc;
        HWND hwnd;
 RECT r;
 WIN32_FIND_DATA FindFileData;
 HANDLE hFind;
 char strFile[MAX_PATH] = {0};
 static OPENFILENAME ofn;
 static TCHAR szFilter[] = TEXT ("Usr Files (*.usr)/0*.usr/0")  /
      TEXT ("All Files (*.*)/0*.*/0/0") ;
 char buf[2*MAX_PATH+100] = {0};
 int oldOpt;
 int mul;
 static COLORREF col;
 unsigned int i,j;
 ofn.lpstrFile = strFile;
 hWnd = hDlg;
 
 switch (msg)
 {
  
                case WM_CREATE:
   hInst = ((LPCREATESTRUCT) lParam)->hInstance ;
                        break;
  case WM_SIZE:
   if(IsIconic(hDlg))
    break;
   GetClientRect(hDlg,&r);
   MoveWindow(GetDlgItem(hDlg,IDC_RECT),0,0,r.right,r.bottom,FALSE);
   InvalidateRect(hDlg,&r,FALSE);
   UpdateWindow(hDlg);
   break;
  case WM_LBUTTONDOWN:
   fp.x = LOWORD(lParam);
   fp.y = HIWORD(lParam);
   sp.x = fp.x;
   sp.y = fp.y;
   cp.x = fp.x;
   cp.y = fp.y;
   if(copt == OPT_MOVE) //移动
   {
    copt = OPT_MOVE1;
   }
   else if(copt == OPT_OUT) //缩小
   {
    s *= 0.8;
    c = cp.x - 0.8*cp.x + 0.8*c;
    d = cp.y - 0.8*cp.y + 0.8*d;
    GetClientRect(hDlg,&r);
    InvalidateRect(hDlg,&r,FALSE);
    UpdateWindow(hDlg);
   }
   else if(copt == OPT_IN) //放大
   {
    copt = OPT_IN1;
   }
   break;
  case WM_MOUSEMOVE:
   cp.x = LOWORD(lParam);
   cp.y = HIWORD(lParam);   
   hdc = GetDC(hDlg);
   oldOpt = GetROP2(hdc);
   if(copt == OPT_MOVE1) //移动
   {
    SetROP2(hdc, R2_NOTXORPEN);
    MoveToEx(hdc, fp.x, fp.y,NULL);
    LineTo(hdc, sp.x, sp.y);
    MoveToEx(hdc, fp.x, fp.y,NULL);
    LineTo(hdc, cp.x, cp.y);
    sp.x = cp.x;
    sp.y = cp.y;
    SetROP2(hdc, oldOpt);
   }
   else if(copt == OPT_IN1) //放大
   {
    SetROP2(hdc, R2_NOTXORPEN);
    Rectangle(hdc, fp.x,fp.y,sp.x,sp.y);
    Rectangle(hdc, fp.x,fp.y,cp.x,cp.y);
    sp = cp; 
    SetROP2(hdc, oldOpt);
   }
   break;
  case WM_LBUTTONUP:
   cp.x = LOWORD(lParam);
   cp.y = HIWORD(lParam);
   if(copt == OPT_MOVE1) //移动
   {
    GetClientRect(hDlg,&r);
    if(((fp.x-cp.x)*(fp.x-cp.x)+(fp.y-cp.y)*(fp.y-cp.y))<0.1) //两点距离过小
    {
     
     c = (r.right+r.left)/2 - ((fp.x+cp.x)/2-c);
     d = (r.bottom+r.top)/2-(r.bottom-(fp.y+cp.y)/2-d);
    }
    else
    {
     c += cp.x-fp.x;
     d += fp.y-cp.y;
    }
    copt = OPT_MOVE;
    InvalidateRect(hDlg,&r,FALSE);
    UpdateWindow(hDlg);
   }
   else if(copt == OPT_IN1) //放大
   {
    if(((fp.x-cp.x)*(fp.x-cp.x)+(fp.y-cp.y)*(fp.y-cp.y))<0.1) //两点距离过小
    {
     GetClientRect(hDlg,&r);
     mul = 2;
     s *= mul;
     c = (r.right+r.left)/2 - mul*((fp.x+cp.x)/2-c);
     d = (r.bottom+r.top)/2-mul*(r.bottom-(fp.y+cp.y)/2-d);
     InvalidateRect(hDlg,&r,FALSE);
     UpdateWindow(hDlg);
    }
    else
    {
     GetClientRect(hDlg,&r);
     if((r.right-r.left)/abs(fp.x-cp.x)<(r.bottom-r.top)/abs(fp.y-cp.y))
      mul = (r.right-r.left)/abs(fp.x-cp.x);
     else
      mul = (r.bottom-r.top)/abs(fp.y-cp.y);
     s *= mul;
     c = (r.right+r.left)/2-mul*((fp.x+cp.x)/2-c);
     d = (r.bottom+r.top)/2-mul*(r.bottom-(fp.y+cp.y)/2-d);
     InvalidateRect(hDlg,&r,FALSE);
     UpdateWindow(hDlg);
    }
    copt = OPT_IN;
   }
   break;
  case WM_INITDIALOG:
   ShowWindow(hDlg,SW_MAXIMIZE);
   //初始化文件查找ofn
   ofn.lStructSize       = sizeof(OPENFILENAME);
   ofn.hwndOwner         = hDlg;
   ofn.hInstance         = NULL;
   ofn.lpstrFilter       = szFilter;
   ofn.lpstrCustomFilter = NULL;
   ofn.nMaxCustFilter    = 0;
   ofn.nFilterIndex      = 0;
   ofn.lpstrFile         = buf;       
   ofn.nMaxFile          = MAX_PATH;
   ofn.lpstrFileTitle    = NULL;
   ofn.nMaxFileTitle     = MAX_PATH;
   ofn.lpstrInitialDir   = NULL;
   ofn.lpstrTitle        = "打开";
   ofn.Flags             = 0;
   ofn.nFileOffset       = 0;
   ofn.nFileExtension    = 0;
   ofn.lpstrDefExt       = TEXT("usr");
   ofn.lCustData         = 0L;
   ofn.lpfnHook          = NULL;
   ofn.lpTemplateName    = NULL;
   //在当前目录下查找*.usr文件
   hFind = FindFirstFile(".//*.usr", &FindFileData);
   if (hFind != INVALID_HANDLE_VALUE)
   {
    ReadData(FindFileData.cFileName,&pc,&cel_num);
    FindClose(hFind);
    //设置标题
    strcpy(buf,"Exercise - ");
    GetModuleFileName(NULL,buf+MAX_PATH,MAX_PATH);
    memcpy(buf+strlen(buf),buf+MAX_PATH,strrchr(buf+MAX_PATH, '//')-buf-MAX_PATH+1);
    strcat(buf,FindFileData.cFileName);
    SetWindowText(hDlg,buf);
    GetClientRect(hDlg,&r);
    InvalidateRect(hDlg,&r,FALSE);
    UpdateWindow(hDlg);
   }
   //设置程序左上角图标
   SendMessage(hDlg,WM_SETICON,(WPARAM)ICON_BIG,
        (LPARAM)LoadIcon(GetModuleHandle(NULL),
                                                     MAKEINTRESOURCE(IDI_ICON1)));
   break;
  case WM_TIMER:
   if(wParam == 0)
   {
    if(col!=RGB(255,0,0))
     col = RGB(255,0,0);
    else col = RGB(0,255,0);
    FlashData(GetDlgItem(hDlg,IDC_RECT),pc,s,c,d,col);
   }
   break;
  case WM_COMMAND:
   //处理菜单消息
   if(HIWORD(wParam)==0)
   {
    switch(LOWORD(wParam))
    {
     case MN_SEARCH_BY_TYPE:
      KillTimer(hDlg, 0);
      UnFlashData(GetDlgItem(hDlg,IDC_RECT),pc,s,c,d);
      if(DialogBox(hInst,MAKEINTRESOURCE(DLG_SEARCH_TYPE),hDlg,SearchByTypeDlgProc))
      { 
       for(i=0;i       for(j=0;j<9;j++)
       {
        if(pc[i].type == types[j])
         pc[i].isflash = TRUE;
       }
       SetTimer(hDlg, 0, 500, NULL);
      }
      SetFocus(hDlg);
      break;
     case MN_SEARCH_BY_ID:
      KillTimer(hDlg, 0);
      UnFlashData(GetDlgItem(hDlg,IDC_RECT),pc,s,c,d);
      if(DialogBox(hInst,MAKEINTRESOURCE(DLG_SEARCH_ID),hDlg,SearchByIDDlgProc))
      { 
       SetTimer(hDlg, 0, 500, NULL);
      }
      SetFocus(hDlg);
      break;
     case MN_EXIT: //退出同WM_CLOSE
      FreeData();
      KillTimer(hDlg,0);
      EndDialog(hDlg,0);
      break;
     case MN_FILE_CLOSE:
      FreeData();
      KillTimer(hDlg,0);
      GetClientRect(hDlg,&r);
      InvalidateRect(hDlg,&r,FALSE);
      SetWindowText(hDlg,"Exercise");
      UpdateWindow(hDlg);
      break;
     case MN_FILE_OPEN: //打开文件
      strcpy(ofn.lpstrFile,"武汉实习数据");
      if(GetOpenFileName(&ofn))
      {
       FreeData();
       KillTimer(hDlg,0);
       ReadData(ofn.lpstrFile,&pc,&cel_num);
       strcpy(buf,"Exercise - ");
       strcat(buf,ofn.lpstrFile);
       SetWindowText(hDlg,buf);
       GetClientRect(hDlg,&r);
       InvalidateRect(hDlg,&r,FALSE);
       UpdateWindow(hDlg);
      }
      break;
     case MN_VIEW_NAVIGATE: //移动
      copt = OPT_MOVE;
      break;
     case MN_VIEW_ZOOM_IN: //放大
      copt = OPT_IN;
      break;
     case MN_VIEW_ZOOM_OUT: //缩小
      copt = OPT_OUT;
      break;
     case MN_VIEW_FULL_SCREEN: //全屏()
      copt = OPT_NONE;
      Reset();
      GetClientRect(hDlg,&r);
      InvalidateRect(hDlg,&r,FALSE);
      UpdateWindow(hDlg);
      break;
    }
   }
   break;
               
                case WM_PAINT: 
   hdc = BeginPaint(hDlg, &ps);
   GetClientRect(hDlg,&r);
   BitBlt(hdc,0,0,r.right,r.bottom,hdc,0,0,SRCCOPY);
   EndPaint(hDlg, &ps);
   hwnd = GetDlgItem(hDlg,IDC_RECT);
   DrawData(hwnd, pc, s, c, d);
                        break;
  case WM_CLOSE:
   FreeData();
   KillTimer(hDlg,0);
   EndDialog(hDlg,0);
   break;
  default:
   return FALSE;
 }
 return FALSE;
}
BOOL DrawData(HWND hwnd, PCELL pCell, long extend, long mx, long my)
{
 CELL *p;
 unsigned int m,n;
 HDC hdc;
 RECT r;
 HPEN hNewPen,hOldPen;
 PAINTSTRUCT ps;
 COLORREF color,colEdge;
 int width;
 HBRUSH hNewBrush,hOldBrush;
 LOGBRUSH lgb;
 POINT *points;
 hdc = BeginPaint(hwnd, &ps);
 //draw background
 GetClientRect(hwnd,&r);
 hNewPen = CreatePen(PS_NULL, 0, 0);
 hOldPen = SelectObject(hdc, hNewPen);
 lgb.lbColor = RGB(255,255,214);
 lgb.lbStyle = BS_SOLID;
 hNewBrush = CreateBrushIndirect(&lgb);
 hOldBrush = SelectObject(hdc, hNewBrush);
 Rectangle(hdc, 0, 0, r.right+1, r.bottom+1);
 SelectObject(hdc,hOldPen);
 DeleteObject(hNewPen);
 SelectObject(hdc,hOldBrush);
 DeleteObject(hNewBrush);
 
 p = pCell;
 for(m=0; m {
  switch(p->type/10000)
  {
  case 2: //面
   GetColorAndWidth(p->type, &color, &colEdge, &width);
   hNewPen = CreatePen(PS_SOLID, width, colEdge);
   hOldPen = SelectObject(hdc, hNewPen);
   lgb.lbColor = color;
   lgb.lbStyle = BS_SOLID;
   hNewBrush = CreateBrushIndirect(&lgb);
   hOldBrush = SelectObject(hdc, hNewBrush);
   points = (POINT*)malloc(sizeof(POINT)*(p->pt_num));
   for(n=0; npt_num; n++)
   {
    points[n].x = extend*(p->ppoints[n].x)+mx;
    points[n].y = r.bottom-extend*(p->ppoints[n].y)-my;
   }
   Polygon(hdc,points,p->pt_num);
   free(points);
   SelectObject(hdc,hOldPen);
   DeleteObject(hNewPen);
   SelectObject(hdc,hOldBrush);
   DeleteObject(hNewBrush);
   break;
  case 1: //线
  case 3: //控制点
  default:
   GetColorAndWidth(p->type, &color, &colEdge, &width);
   hNewPen = CreatePen(PS_SOLID, width, color);
   hOldPen = SelectObject(hdc, hNewPen);
   
   MoveToEx(hdc,extend*((p->ppoints[0]).x)+mx,r.bottom-extend*(p->ppoints[0].y)-my,NULL);
   for(n=1; npt_num; n++)
   {    
    LineTo(hdc,extend*(p->ppoints[n].x)+mx,r.bottom-extend*(p->ppoints[n].y)-my); 
   }
   SelectObject(hdc,hOldPen);
   DeleteObject(hNewPen);
  }
 }
 
 EndPaint(hwnd, &ps);
 return TRUE;
}
BOOL GetColorAndWidth(unsigned long type, COLORREF *color, COLORREF *colEdge, int *width)
{
 switch(type)
 {
 case 10000: //图廓点
  *color = RGB(181,170,156);
  *width = 1;
  break;
 case 10001: //铁路
  *color = RGB(222,211,173);
  *width = 1;
  break;
 case 10003: //汽渡虚线
  *color = RGB(107,174,181);
  *width = 1;
  break;
 case 10004: //主要道路
  *color = RGB(255,255,255);
  *width = 3;
  break;
 case 20001: //码头
  *color = RGB(0,0,255);
  *colEdge = RGB(0,0,0);
  *width = 1;
  break;
 case 20002: //铁路中转站
  *color = RGB(99,158,57);
  *colEdge = RGB(181,195,181);
  *width = 1;
  break;
 case 20003: //河流、湖泊
  *color = RGB(189,227,255);
  *colEdge = RGB(165,199,214);
  *width = 1;
  break;
 case 20004: //居民地
  *color = RGB(255,199,99);
  *colEdge = RGB(214,195,140);
  *width = 1;
  break;
 default: //默认
  *color = RGB(255,255,255);
  *colEdge = RGB(0,0,0);
  *width = 1; 
 }
 return TRUE;
}
BOOL FreeData()
{
 PCELL p;
 unsigned int i;
 p = pc;
 for(i=0; i {
  free(p->ppoints);
 }
 if(cel_num!=0)
  free(pc);
 cel_num = 0;
 return TRUE;
}
BOOL Reset()
{
 RECT r;
 HWND hWndRect;
 if(pc==NULL || cel_num <=0)
  return FALSE;
 hWndRect = GetDlgItem(hWnd,IDC_RECT);
 GetClientRect(hWndRect,&r);
 if((MaxRect.bottom-MaxRect.top)/(MaxRect.right-MaxRect.left) > (r.bottom-r.top)/(r.right-r.left))
 {
  s = (r.bottom-r.top)/(MaxRect.bottom-MaxRect.top);
 }
 else
 {
  s = (r.right-r.left)/(MaxRect.right-MaxRect.left);
 }
 c = (r.right+r.left)/2 - s*(MaxRect.right+MaxRect.left)/2;
 d = (r.bottom+r.top)/2 - s*(MaxRect.bottom+MaxRect.top)/2;
 copt = OPT_NONE;
 return TRUE;
}
BOOL GetMaxRect()
{
 unsigned int i,j;
 PCELL p;
 MaxRect.bottom = 0;
 MaxRect.left = 0;
 MaxRect.right = 0;
 MaxRect.top = 0;
 p = pc;
 for(i=0; i for(j=0; jpt_num; j++)
 {
  if(MaxRect.bottom < p->ppoints[j].y)
   MaxRect.bottom = p->ppoints[j].y;
  if(MaxRect.left > p->ppoints[j].x)
   MaxRect.left = p->ppoints[j].x;
  if(MaxRect.top > p->ppoints[j].y)
   MaxRect.top = p->ppoints[j].y;
  if(MaxRect.right < p->ppoints[j].x)
   MaxRect.right = p->ppoints[j].x;
 }
 return TRUE;
}
LRESULT CALLBACK SearchByIDDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
 unsigned int i;
 char buf[100]={0};
 switch(msg)
 {
 case WM_INITDIALOG:
  for(i=0; i  {
   itoa(pc[i].id, buf, 10);
   SendDlgItemMessage(hDlg,IDC_COMBO_ID,CB_ADDSTRING,0,(LPARAM)buf);
   pc[i].isflash = FALSE;
  }
  return FALSE;
 case WM_COMMAND:
  switch (LOWORD(wParam))
           {
            case IDC_SEARCH_ID_OK:
    if(SendDlgItemMessage(hDlg,IDC_COMBO_ID,WM_GETTEXTLENGTH ,0,0)>0)
    {
     SendDlgItemMessage(hDlg,IDC_COMBO_ID,WM_GETTEXT ,10,(LPARAM)buf);
     if((unsigned char)atoi(buf)     {
      pc[atoi(buf)].isflash = TRUE;
      EndDialog(hDlg, 1);
      return TRUE;
     } 
    }
    EndDialog(hDlg, 0);
    return TRUE;
            case IDC_SEARCH_ID_CANCEL:
                  EndDialog(hDlg, 0);
                  return TRUE ;
   break;
  }
  break;
 case WM_CLOSE:
                EndDialog (hDlg, 0);
                return TRUE;
 }
 return FALSE;
}
BOOL FlashData(HWND hwnd, PCELL pCell, long extend, long mx, long my, COLORREF col)
{
 CELL *p;
 unsigned int m,n;
 HDC hdc;
 RECT r;
 HPEN hNewPen,hOldPen;
 COLORREF color,colEdge;
 int width;
 HBRUSH hNewBrush,hOldBrush;
 LOGBRUSH lgb;
 POINT *points;
 hdc = GetDC(hwnd);
 GetClientRect(hwnd,&r);
 p = pCell;
 for(m=0; m {
  if(!p->isflash)
   continue;
  switch(p->type/10000)
  {
  case 2: //面
   GetColorAndWidth(p->type, &color, &colEdge, &width);
   hNewPen = CreatePen(PS_SOLID, width, col);
   hOldPen = SelectObject(hdc, hNewPen);
   lgb.lbColor = col;
   lgb.lbStyle = BS_SOLID;
   hNewBrush = CreateBrushIndirect(&lgb);
   hOldBrush = SelectObject(hdc, hNewBrush);
   points = (POINT*)malloc(sizeof(POINT)*(p->pt_num));
   for(n=0; npt_num; n++)
   {
    points[n].x = extend*(p->ppoints[n].x)+mx;
    points[n].y = r.bottom-extend*(p->ppoints[n].y)-my;
   }
   Polygon(hdc,points,p->pt_num);
   free(points);
   SelectObject(hdc,hOldPen);
   DeleteObject(hNewPen);
   SelectObject(hdc,hOldBrush);
   DeleteObject(hNewBrush);
   break;
  case 1: //线
  case 3: //控制点
  default:
   GetColorAndWidth(p->type, &color, &colEdge, &width);
   hNewPen = CreatePen(PS_SOLID, width, col);
   hOldPen = SelectObject(hdc, hNewPen);
   
   MoveToEx(hdc,extend*((p->ppoints[0]).x)+mx,r.bottom-extend*(p->ppoints[0].y)-my,NULL);
   for(n=1; npt_num; n++)
   {    
    LineTo(hdc,extend*(p->ppoints[n].x)+mx,r.bottom-extend*(p->ppoints[n].y)-my); 
   }
   SelectObject(hdc,hOldPen);
   DeleteObject(hNewPen);
  }
 }
 return TRUE;
}
BOOL UnFlashData(HWND hwnd, PCELL pCell, long extend, long mx, long my)
{
 CELL *p;
 unsigned int m,n;
 HDC hdc;
 RECT r;
 HPEN hNewPen,hOldPen;
 COLORREF color,colEdge;
 int width;
 HBRUSH hNewBrush,hOldBrush;
 LOGBRUSH lgb;
 POINT *points;
 hdc = GetDC(hwnd);
 GetClientRect(hwnd,&r);
 p = pCell;
 for(m=0; m {
  if(!p->isflash)
   continue;
  pc[m].isflash = FALSE;
  switch(p->type/10000)
  {
  case 2: //面
   GetColorAndWidth(p->type, &color, &colEdge, &width);
   hNewPen = CreatePen(PS_SOLID, width, colEdge);
   hOldPen = SelectObject(hdc, hNewPen);
   lgb.lbColor = color;
   lgb.lbStyle = BS_SOLID;
   hNewBrush = CreateBrushIndirect(&lgb);
   hOldBrush = SelectObject(hdc, hNewBrush);
   points = (POINT*)malloc(sizeof(POINT)*(p->pt_num));
   for(n=0; npt_num; n++)
   {
    points[n].x = extend*(p->ppoints[n].x)+mx;
    points[n].y = r.bottom-extend*(p->ppoints[n].y)-my;
   }
   Polygon(hdc,points,p->pt_num);
   free(points);
   SelectObject(hdc,hOldPen);
   DeleteObject(hNewPen);
   SelectObject(hdc,hOldBrush);
   DeleteObject(hNewBrush);
   break;
  case 1: //线
  case 3: //控制点
  default:
   GetColorAndWidth(p->type, &color, &colEdge, &width);
   hNewPen = CreatePen(PS_SOLID, width, color);
   hOldPen = SelectObject(hdc, hNewPen);
   
   MoveToEx(hdc,extend*((p->ppoints[0]).x)+mx,r.bottom-extend*(p->ppoints[0].y)-my,NULL);
   for(n=1; npt_num; n++)
   {    
    LineTo(hdc,extend*(p->ppoints[n].x)+mx,r.bottom-extend*(p->ppoints[n].y)-my); 
   }
   SelectObject(hdc,hOldPen);
   DeleteObject(hNewPen);
  }
 }
 return TRUE;
}
LRESULT CALLBACK SearchByTypeDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
 int i=0;
 switch(msg)
 {
 case WM_INITDIALOG:
  return FALSE;
 case WM_COMMAND:
  switch (LOWORD(wParam))
           {
            case IDC_SEARCH_TYPE_OK:
    for(i=0;i<9;i++)
     types[i] = 0;
    if(IsDlgButtonChecked(hDlg, IDC_CHECK1)==BST_CHECKED)
     types[0] = 30000;
    if(IsDlgButtonChecked(hDlg, IDC_CHECK2)==BST_CHECKED)
     types[1] = 10000;
    if(IsDlgButtonChecked(hDlg, IDC_CHECK3)==BST_CHECKED)
     types[2] = 10001;
    if(IsDlgButtonChecked(hDlg, IDC_CHECK4)==BST_CHECKED)
     types[3] = 10003;
    if(IsDlgButtonChecked(hDlg, IDC_CHECK5)==BST_CHECKED)
     types[4] = 10004;
    if(IsDlgButtonChecked(hDlg, IDC_CHECK6)==BST_CHECKED)
     types[5] = 20001;
    if(IsDlgButtonChecked(hDlg, IDC_CHECK7)==BST_CHECKED)
     types[6] = 20002;
    if(IsDlgButtonChecked(hDlg, IDC_CHECK8)==BST_CHECKED)
     types[7] = 20003;
    if(IsDlgButtonChecked(hDlg, IDC_CHECK9)==BST_CHECKED)
     types[8] = 20004;
    EndDialog(hDlg, 1);
    return TRUE;
            case IDC_SEARCH_TYPE_CANCEL:
                  EndDialog(hDlg, 0);
                  return TRUE ;
   break;
  }
  break;
 case WM_CLOSE:
                EndDialog (hDlg, 0);
                return TRUE;
 }
 return FALSE;
}
 
 

你可能感兴趣的:(null,types,callback,search,path,float)