⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ace.c

📁 This is a CNCPro source file. It is include the G-Code interpreter source.
💻 C
📖 第 1 页 / 共 2 页
字号:
               wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
               wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
               wndclass.lpszMenuName  = NULL ;
               wndclass.lpszClassName = "code" ;
	            wndclass.hIconSm       = LoadIcon (hInst, szAppName) ;
               RegisterClassEx (&wndclass) ;
               szTemp1=(char *) calloc(strlen(priority[iPriority].precode)+1,sizeof(char));
               szTemp2=(char *) calloc(strlen(priority[iPriority].postcode)+1,sizeof(char)),
               sprintf(szTemp1,"%s",priority[iPriority].precode);
               sprintf(szTemp2,"%s",priority[iPriority].postcode);
               return FALSE ;

          case WM_COMMAND :
               switch (LOWORD (wParam))
                    {
                     case IDD_OK :
                         DestroyWindow(prehwnd);
                         DestroyWindow(posthwnd);
			                free(priority[iPriority].precode);
                         free(priority[iPriority].postcode);
                         priority[iPriority].precode=szTemp1;
                         priority[iPriority].postcode=szTemp2;
                         priority[iPriority].optimize=SendMessage(GetDlgItem(hDlg, IDD_OPTIMIZE), BM_GETCHECK, 0, 0);
                         GetWindowText(GetDlgItem(hDlg, IDD_RELEASE), szString, 30);
                         endptr=NULL;
                         fTemp=(float) strtod(szString, &endptr);
                         if(*endptr==NULL) priority[iPriority].release=fTemp;
                         GetWindowText(GetDlgItem(hDlg, IDD_CLOSE), szString, 30);
                         endptr=NULL;
                         fTemp=(float) fabs(strtod(szString, &endptr));
                         if(*endptr==NULL) priority[iPriority].close=fTemp;
                         EndDialog (hDlg, 0) ;
                         return TRUE ;
                    case IDD_CANCEL :
                         DestroyWindow(prehwnd);
                         DestroyWindow(posthwnd);
			                EndDialog (hDlg, 0) ;
                         return TRUE ;
                    case IDD_PRECODE :
                         if(prehwnd==NULL)
                           {prehwnd = CreateWindow ("code", "Pre-Priority Code",
                                                    WS_OVERLAPPEDWINDOW,
                                                    CW_USEDEFAULT, CW_USEDEFAULT,
                                                    CW_USEDEFAULT, CW_USEDEFAULT,
                                                    NULL, NULL, NULL, NULL) ;
                            SetWindowText(GetWindow(prehwnd, GW_CHILD), szTemp1);
                           }
                         ShowWindow (prehwnd, SW_SHOWNORMAL) ;
                         UpdateWindow (prehwnd) ;
                         return TRUE ;
                    case IDD_POSTCODE :
                         if(posthwnd==NULL)
                           {posthwnd = CreateWindow ("code", "Post-Priority Code",
                                                     WS_OVERLAPPEDWINDOW,
                                                     CW_USEDEFAULT, CW_USEDEFAULT,
                                                     CW_USEDEFAULT, CW_USEDEFAULT,
                                                     NULL, NULL, NULL, NULL) ;
                            SetWindowText(GetWindow(posthwnd, GW_CHILD), szTemp2);
                           }
                         ShowWindow (posthwnd, SW_SHOWNORMAL) ;
                         UpdateWindow (posthwnd) ;
                         return TRUE ;
                    }
               break ;
          }
     return FALSE ;
     }

LRESULT CALLBACK CodeWndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
     {
     static HWND hwndEdit ;
     static int iTemp;

     switch (iMsg)
          {
          case WM_CREATE :
               hwndEdit = CreateWindow ("edit", NULL,
                         WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
                              WS_BORDER | ES_LEFT | ES_MULTILINE |
                              ES_AUTOHSCROLL | ES_AUTOVSCROLL,
                         0, 0, 0, 0,
                         hwnd, (HMENU) 1,
                         ((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
               return 0 ;

          case WM_SETFOCUS :
               SetFocus (hwndEdit) ;
               return 0 ;

          case WM_SIZE : 
               MoveWindow (hwndEdit, 0, 0, LOWORD (lParam),
                                           HIWORD (lParam), TRUE) ;
               return 0 ;

          case WM_COMMAND :
               if (LOWORD (wParam) == 1)
                    if (HIWORD (wParam) == EN_ERRSPACE ||
                        HIWORD (wParam) == EN_MAXTEXT)
                              MessageBox (hwnd, "Edit control out of space.",
                                          szAppName, MB_OK | MB_ICONSTOP) ;
               return 0 ;
          case WM_DESTROY :
               if(prehwnd==hwnd)
                 {prehwnd=NULL;
                  free(szTemp1);
                  szTemp1=(char *) calloc((iTemp=(GetWindowTextLength(hwndEdit)+1)),sizeof(char));
                  GetWindowText(hwndEdit, szTemp1, iTemp);
                 }
               if(posthwnd==hwnd)
                 {posthwnd=NULL;
                  free(szTemp2);
                  szTemp2=(char *) calloc((iTemp=(GetWindowTextLength(hwndEdit)+1)),sizeof(char));
                  GetWindowText(hwndEdit, szTemp2, iTemp);
                 }
               return 0;
          }
     return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
     }

BOOL CALLBACK ConvertDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
     {
     switch (iMsg)
          {
          case WM_INITDIALOG :
               SendMessage(GetDlgItem(hDlg, IDD_IJREL), BM_SETCHECK, convertop.ijrel, 0);
               SendMessage(GetDlgItem(hDlg, IDD_IJFIRST), BM_SETCHECK, convertop.ijfirst, 0);
               SendMessage(GetDlgItem(hDlg, IDD_LINENUM), BM_SETCHECK, convertop.line_num, 0);
               return FALSE ;

          case WM_COMMAND :
               switch (LOWORD (wParam))
                    {
		              case IDD_OK :
                         convertop.ijrel=SendMessage(GetDlgItem(hDlg, IDD_IJREL), BM_GETCHECK, 0, 0);
                         convertop.ijfirst=SendMessage(GetDlgItem(hDlg, IDD_IJFIRST), BM_GETCHECK, 0, 0);
                         convertop.line_num=SendMessage(GetDlgItem(hDlg, IDD_LINENUM), BM_GETCHECK, 0, 0);
                         EndDialog (hDlg, 0) ;
			                return TRUE ;
                    }
               break ;
          }
     return FALSE ;
     }

int DelPriority(int num, int count)
{
   int i;
   if(num>0 && num<=count) free(priority[num-1].precode);
   if(num>0 && num<=count) free(priority[num-1].postcode);
   for(i=num;i<count;i++) priority[i-1]=priority[i];
   if(count==1) free(priority);
   return count-1;
}

int NewPriority(int count)
{
   int i;
   temp_pri=(struct priority_obj *) calloc((count+1), sizeof(struct priority_obj));
   for(i=0;i<count;i++) temp_pri[i]=priority[i];
   if(count>0) free(priority);
   priority=temp_pri;
   priority[count].release=3;
   priority[count].close=.001;
   priority[count].optimize=TRUE;
   priority[count].precode=(char *) calloc(1, sizeof(char));
   priority[count].postcode=(char *) calloc(1, sizeof(char));
   return count+1;
}

int ReadLayer (char *file)
{
   int i, count=0, temp;
   char string[100];
   fpos_t pos;
   FILE *ifp;
   ifp=fopen(file,"r");
   while(1)
     {if((temp=fscanf(ifp,"%s",string))!=EOF && temp!=0 && strcmp(string,"0")==0)
        {fgetpos(ifp, &pos);
         if((temp=fscanf(ifp,"%s",string))!=EOF && temp!=0 && strcmp(string,"LAYER")==0)
           {while(1)
              {if((temp=fscanf(ifp,"%s",string))==EOF || temp==0) break;
               if(strcmp(string,"0")==0) break;
               else if(strcmp(string,"2")==0)
                 {temp_lay=(struct layer_obj *) calloc(++count, sizeof(struct layer_obj));
                  for(i=0;i<count-1;i++) temp_lay[i]=layer[i];
                  if(count>1) free(layer);
                  layer=temp_lay;
                  temp=fscanf(ifp,"%s",layer[count-1].name);
                  break;
                 }
               else if((temp=fscanf(ifp,"%s",string))==EOF || temp==0) break;
              }
           }
         else fsetpos(ifp, &pos);
        }
      if(temp==0 || temp==EOF) break;
     }
   if(count==0)
     {layer=(struct layer_obj *) calloc(++count, sizeof(struct layer_obj));
      sprintf(layer[0].name,"0");
     }
   for(i=0;i<count;i++)
     {layer[i].status=TRUE;
      layer[i].priority=1;
      layer[i].depth=.25;
      layer[i].arc=IDD_EITHERARC;
      layer[i].zchar='Z';
     }
   fclose(ifp);
   return count;
}

BOOL CALLBACK EndDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
     {
     switch (iMsg)
          {
          case WM_COMMAND :
               switch (LOWORD (wParam))
                    {
		              case IDD_OK :
                         EndDialog(hDlg, 0);
                         return TRUE ;
                    }
               break;
         }
     return FALSE ;
     }

void GetDir(char num, char dir[])
{
   int iTemp;
   static char szWinDir[_MAX_PATH], szAceIni[_MAX_PATH], szString[100];
   FILE *ifp;

   GetWindowsDirectory(szWinDir, _MAX_PATH);
   sprintf(szAceIni,"%s\\ace.ini",szWinDir);
   if((ifp=fopen(szAceIni,"r"))!=NULL)
     {while((iTemp=fscanf(ifp,"%s",szString))!=EOF && strcmp(szString,"[1]")!=0);
      if(iTemp!=EOF)
        {iTemp=fgetc(ifp);
         while(1)
           {while(iTemp!=EOF && iTemp!='\n' && iTemp!='[') iTemp=fgetc(ifp);
            if(iTemp==EOF || iTemp=='[') break;
            iTemp=fgetc(ifp);
            if(iTemp==num && (iTemp=fgetc(ifp))=='=')
              {fgets(dir,_MAX_PATH,ifp);
               iTemp=strlen(dir);
               if(iTemp>1) dir[iTemp-1]=0;
               if(iTemp>2 && dir[iTemp-2]=='\\') dir[iTemp-2]=0;
               break;
              }
           }
        }
      fclose(ifp);
     }
}

void SaveDir(char num, char dir[])
{
   int iTemp;
   static char szWinDir[_MAX_PATH], szAceIni[_MAX_PATH], szString[_MAX_PATH];
   FILE *ifp, *ofp;

   GetWindowsDirectory(szWinDir, _MAX_PATH);
   sprintf(szAceIni,"%s\\ace.ini",szWinDir);
   ofp=fopen("temp.tmp","w");
   if((ifp=fopen(szAceIni,"r"))!=NULL)
     {while(1)
        {if((iTemp=fgetc(ifp))=='[')
           {fputc(iTemp,ofp);
            if((iTemp=fgetc(ifp))=='1')
              {fputc(iTemp,ofp);
               if((iTemp=fgetc(ifp))==']')
                 {fputc(iTemp,ofp);
                  break;
                 }
              }
           }
         if(iTemp==EOF) break;
         fputc(iTemp, ofp);
        }
      if(iTemp!=EOF)
        {iTemp=fgetc(ifp);
         while(1)
           {while(iTemp!=EOF && iTemp!='\n') {fputc(iTemp,ofp); iTemp=fgetc(ifp);}
            if(iTemp==EOF) break;
            fputc(iTemp,ofp); iTemp=fgetc(ifp);
            if(iTemp==num)
              {fputc(iTemp,ofp); iTemp=fgetc(ifp);
               if(iTemp=='=')
                 {fputc(iTemp,ofp);
                  fgets(szString,_MAX_PATH,ifp);
                  fprintf(ofp,"%s\n",dir);
                  iTemp=fgetc(ifp);
                 }
              }
           }
        }
      fclose(ifp);
     }
   fclose(ofp);
   ifp=fopen("temp.tmp","r");
   ofp=fopen(szAceIni,"w");
   while((iTemp=fgetc(ifp))!=EOF) fputc(iTemp, ofp);
   fclose(ifp);
   fclose(ofp);
   remove("temp.tmp");
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -