UP-DOWN Control

   case WM_NOTIFY:
switch(wParam){
case (WPARAM)IDC_VERTICAL_SPIN:
InitPaperPosition(hdlg, lParam, GetDlgItem(hdlg, IDC_SURFACE_POS_X));
break;
case (WPARAM)IDC_HORIZONTAL_SPIN:
InitPaperPosition(hdlg, lParam, GetDlgItem(hdlg, IDC_SURFACE_POS_Y));
break;
}
return FALSE;


OOL InitPaperPosition(HWND hdlg,LPARAM lParam,HWND hEdit)
{
    double d = 0;
    char str[32];
char str2[32] = "0";
LPNMUPDOWN lpnmud;
    lpnmud=(LPNMUPDOWN)lParam;

    if (lpnmud->hdr.code==UDN_DELTAPOS){
        GetWindowText(hEdit,str,(int)sizeof(str));
d=atof(str);
if((lpnmud->iDelta)<0) {
d+=0.1;
}else if((lpnmud->iDelta)>0) {
d-=0.1;
}
        sprintf(str,"%.1lf",d);

if(d > 50.0) {
           SetWindowText(hEdit,"-50.0");
           return TRUE;
}else if(d < -50.0) {
   SetWindowText(hEdit,"50.0");
           return TRUE;
}

        PrePaperPosSetting(d,str,str2,hEdit);

return TRUE;
}
return FALSE;
}




VOID PrePaperPosSetting(double d,char *str,char *str2,HWND hEdit)
{
  char *p;
  char *q;
  int i,j;

  if (d > 0) {
      p = str;
      if ( * (p + 1) == '.') {
          strcat_s(str2, 32, str);
          SetWindowText(hEdit, str2);
      } else {
          SetWindowText(hEdit, str);
      }
  } else if (d < 0) {
     p = str;
     if ( * (p + 2) == '.') {
         i = 0;
         p = p + 1;
         while (str[i] != '\0') i++;
            j = i;
            i--;
            q = & str[i];
         while (q >= p) {
            str[j] = * q;
            q--;
            j--;
         }
* p = '0';
         str[i + 2] = '\0';
         SetWindowText(hEdit, str);
    } else {
         SetWindowText(hEdit, str);
    }
  } else {
      SetWindowText(hEdit, "00.0");
  }
}

你可能感兴趣的:(UP-DOWN Control)