예제 #1
0
void SetSymbols(HWND hwndDlg, TCHAR **symbols)
{
    int i = 0;
    SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_RESETCONTENT , 0, 0);
    if (symbols) {
      while (symbols[i]) {
        SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_ADDSTRING, 0, (LPARAM)symbols[i]);
        i++;
      }
    }
    EnableSymbolSetButtons(hwndDlg);
    EnableWindow(GetDlgItem(hwndDlg, IDC_RIGHT), FALSE);
    EnableWindow(GetDlgItem(hwndDlg, IDC_LEFT), FALSE);
    EnableWindow(GetDlgItem(hwndDlg, IDC_DEL), FALSE);
}
예제 #2
0
INT_PTR CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
  switch(msg) {
    case WM_INITDIALOG:
    {
      int i = 0;

      for(i = (int)COMPRESSOR_SCRIPT; i <= (int)COMPRESSOR_BEST; i++) {
        SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_ADDSTRING, 0, (LPARAM)compressor_display_names[i]);
      }
      SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_SETCURSEL, (WPARAM)g_sdata.default_compressor, (LPARAM)0);

      SetSymbols(hwndDlg, g_sdata.symbols);
      SetFocus(GetDlgItem(hwndDlg, IDC_SYMBOL));
      break;
    }
    case WM_MAKENSIS_LOADSYMBOLSET:
    {
      TCHAR *name = (TCHAR *)wParam;
      TCHAR **symbols = LoadSymbolSet(name);
      HGLOBAL hMem;

      SetSymbols(hwndDlg, symbols);
      if(symbols) {
        hMem = GlobalHandle(symbols);
        GlobalUnlock(hMem);
        GlobalFree(hMem);
      }
      break;
    }
    case WM_MAKENSIS_SAVESYMBOLSET:
    {
      TCHAR *name = (TCHAR *)wParam;
      TCHAR **symbols = GetSymbols(hwndDlg);
      HGLOBAL hMem;

      if(symbols) {
        SaveSymbolSet(name, symbols);
        hMem = GlobalHandle(symbols);
        GlobalUnlock(hMem);
        GlobalFree(hMem);
      }
      break;
    }
    case WM_COMMAND:
    {
      switch (LOWORD(wParam)) {
        case IDOK:
        {
          ResetObjects();
          ResetSymbols();
          g_sdata.symbols = GetSymbols(hwndDlg);

          int n = SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
          if (n >= (int)COMPRESSOR_SCRIPT && n <= (int)COMPRESSOR_BEST) {
            g_sdata.default_compressor = (NCOMPRESSOR)n;
          }
          else {
            g_sdata.default_compressor = COMPRESSOR_SCRIPT;
          }
          EndDialog(hwndDlg, TRUE);
          SetCompressor(g_sdata.default_compressor);
        }
        break;
        case IDCANCEL:
          EndDialog(hwndDlg, TRUE);
          break;
        case IDC_RIGHT:
        {
          int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXTLENGTH, 0, 0);
          if(n > 0) {
            TCHAR *buf = (TCHAR*) MemAllocZI((n+1)*sizeof(TCHAR));
            SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXT, n+1, (LPARAM)buf);
            if(_tcsstr(buf,_T(" ")) || _tcsstr(buf,_T("\t"))) {
              MessageBox(hwndDlg,SYMBOLSERROR,ERRBOXTITLE,MB_OK|MB_ICONSTOP);
              MemFree(buf);
              break;
            }

            n = SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_GETTEXTLENGTH, 0, 0);
            if(n > 0) {
              TCHAR *buf2 = (TCHAR*) MemAllocZI((n+1)*sizeof(TCHAR));
              SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_GETTEXT, n+1, (LPARAM)buf2);
              TCHAR *buf3 = (TCHAR*) MemAllocZI((lstrlen(buf)+lstrlen(buf2)+2)*sizeof(TCHAR));
              wsprintf(buf3,_T("%s=%s"),buf,buf2);
              MemFree(buf);
              buf = buf3;
              MemFree(buf2);
            }
            int idx = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_ADDSTRING, 0, (LPARAM)buf);
            if (idx >= 0)
            {
              SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_SETSEL, FALSE, -1);
              SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_SETSEL, TRUE, idx);
            }
            EnableSymbolEditButtons(hwndDlg);
            SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_SETTEXT, 0, 0);
            SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_SETTEXT, 0, 0);
            MemFree(buf);
            EnableSymbolSetButtons(hwndDlg);
          }
        }
        break;
        case IDC_LEFT:
        {
          if (SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELCOUNT, 0, 0) != 1)
            break;

          int index;
          int num = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELITEMS, 1, (LPARAM) &index);
          if(num == 1) {
            int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXTLEN, (WPARAM)index, 0);
            if(n > 0) {
              TCHAR *buf = (TCHAR*) MemAllocZI((n+1)*sizeof(TCHAR));
              SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXT, (WPARAM)index, (LPARAM)buf);
              TCHAR *p = _tcsstr(buf,_T("="));
              if(p) {
                SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_SETTEXT, 0, (LPARAM)(p+1));
                *p=0;
              }
              SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_SETTEXT, 0, (LPARAM)buf);
              MemFree(buf);
              SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_DELETESTRING, (WPARAM)index, 0);
              EnableWindow(GetDlgItem(hwndDlg, IDC_LEFT), FALSE);
              EnableWindow(GetDlgItem(hwndDlg, IDC_DEL), FALSE);
              EnableSymbolSetButtons(hwndDlg);
            }
          }
        }
        break;
        case IDC_CLEAR:
        {
          SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_RESETCONTENT , 0, 0);
          EnableSymbolSetButtons(hwndDlg);
        }
        break;
        case IDC_LOAD:
        case IDC_SAVE:
        {
          g_symbol_set_mode = IDC_LOAD == LOWORD(wParam) ? 1 : 2;
          DialogBox(g_sdata.hInstance,MAKEINTRESOURCE(DLG_SYMBOLSET),hwndDlg,(DLGPROC)SymbolSetProc);
        }
        break;
        case IDC_DEL:
        {
          int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELCOUNT, 0, 0);
          int *items = (int*) MemAllocZI(n*sizeof(int));
          if (items) {
            SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELITEMS, (WPARAM)n, (LPARAM)items);
            for(int i=n-1;i>=0;i--)
              SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_DELETESTRING, (WPARAM)items[i], 0);
            MemFree(items);
          }
          EnableSymbolEditButtons(hwndDlg);
          EnableSymbolSetButtons(hwndDlg);
        }
        break;
        case IDC_SYMBOL:
          if(HIWORD(wParam) == EN_CHANGE)
          {
            int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXTLENGTH, 0, 0);
            EnableWindow(GetDlgItem(hwndDlg, IDC_RIGHT), n > 0);
          }
          break;
        case IDC_SYMBOLS:
          if (HIWORD(wParam) == LBN_SELCHANGE)
          {
            EnableSymbolEditButtons(hwndDlg);
          }
          else if (HIWORD(wParam) == LBN_DBLCLK)
          {
            SendDlgItemMessage(hwndDlg, IDC_LEFT, BM_CLICK, 0, 0);
          }
          break;
        }
      break;
    }
  }
  return FALSE;
}
예제 #3
0
파일: makensisw.cpp 프로젝트: kichik/nsis-1
BOOL CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
  switch(msg) {
    case WM_INITDIALOG:
    {
      int i = 0;
      LRESULT rv;

      for(i = (int)COMPRESSOR_SCRIPT; i <= (int)COMPRESSOR_BEST; i++) {
        rv = SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_ADDSTRING, 0, (LPARAM)compressor_display_names[i]);
      }
      rv = SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_SETCURSEL, (WPARAM)g_sdata.default_compressor, (LPARAM)0);

      SetSymbols(hwndDlg, g_sdata.symbols);
      SetFocus(GetDlgItem(hwndDlg, IDC_SYMBOL));
      break;
    }
    case WM_MAKENSIS_LOADSYMBOLSET:
    {
      char *name = (char *)wParam;
      char **symbols = LoadSymbolSet(name);
      HGLOBAL hMem;

      SetSymbols(hwndDlg, symbols);
      if(symbols) {
        hMem = GlobalHandle(symbols);
        GlobalUnlock(hMem);
        GlobalFree(hMem);
      }
      break;
    }
    case WM_MAKENSIS_SAVESYMBOLSET:
    {
      char *name = (char *)wParam;
      char **symbols = GetSymbols(hwndDlg);
      HGLOBAL hMem;

      if(symbols) {
        SaveSymbolSet(name, symbols);
        hMem = GlobalHandle(symbols);
        GlobalUnlock(hMem);
        GlobalFree(hMem);
      }
      break;
    }
    case WM_COMMAND:
    {
      switch (LOWORD(wParam)) {
        case IDOK:
        {
          ResetObjects();
          ResetInputScript();
          ResetSymbols();
          g_sdata.symbols = GetSymbols(hwndDlg);

          int n = SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
          if (n >= (int)COMPRESSOR_SCRIPT && n <= (int)COMPRESSOR_BEST) {
            g_sdata.default_compressor = (NCOMPRESSOR)n;
          }
          else {
            g_sdata.default_compressor = COMPRESSOR_SCRIPT;
          }
          EndDialog(hwndDlg, TRUE);
          SetCompressor(g_sdata.default_compressor);
        }
        break;
        case IDCANCEL:
          EndDialog(hwndDlg, TRUE);
          break;
        case IDRIGHT:
        {
          int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXTLENGTH, 0, 0);
          if(n > 0) {
            char *buf = (char *)GlobalAlloc(GPTR, (n+1)*sizeof(char));
            SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXT, n+1, (LPARAM)buf);
            if(my_strstr(buf," ") || my_strstr(buf,"\t")) {
              MessageBox(hwndDlg,SYMBOLSERROR,"Error",MB_OK|MB_ICONSTOP);
              GlobalFree(buf);
              break;
            }

            n = SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_GETTEXTLENGTH, 0, 0);
            if(n > 0) {
              char *buf2 = (char *)GlobalAlloc(GPTR, (n+1)*sizeof(char));
              SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_GETTEXT, n+1, (LPARAM)buf2);
              char *buf3 = (char *)GlobalAlloc(GPTR, (lstrlen(buf)+lstrlen(buf2)+2)*sizeof(char));
              wsprintf(buf3,"%s=%s",buf,buf2);
              GlobalFree(buf);
              buf = buf3;
              GlobalFree(buf2);
            }
            SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_ADDSTRING, 0, (LPARAM)buf);
            SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_SETTEXT, 0, 0);
            SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_SETTEXT, 0, 0);
            GlobalFree(buf);
            EnableSymbolSetButtons(hwndDlg);
          }
        }
        break;
        case IDLEFT:
        {
          int index = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETCURSEL, 0, 0);
          if(index != LB_ERR) {
            int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXTLEN, (WPARAM)index, 0);
            if(n > 0) {
              char *buf = (char *)GlobalAlloc(GPTR, (n+1)*sizeof(char));
              SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXT, (WPARAM)index, (LPARAM)buf);
              char *p = my_strstr(buf,"=");
              if(p) {
                SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_SETTEXT, 0, (LPARAM)(p+1));
                *p=0;
              }
              SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_SETTEXT, 0, (LPARAM)buf);
              GlobalFree(buf);
              SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_DELETESTRING, (WPARAM)index, 0);
              EnableWindow(GetDlgItem(hwndDlg, IDLEFT), FALSE);
              EnableWindow(GetDlgItem(hwndDlg, IDDEL), FALSE);
              EnableSymbolSetButtons(hwndDlg);
            }
          }
        }
        break;
        case IDCLEAR:
        {
          SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_RESETCONTENT , 0, 0);
          EnableSymbolSetButtons(hwndDlg);
        }
        break;
        case IDLOAD:
        {
          g_symbol_set_mode=1;
          DialogBox(g_sdata.hInstance,MAKEINTRESOURCE(DLG_SYMBOLSET),hwndDlg,(DLGPROC)SymbolSetProc);
        }
        break;
        case IDSAVE:
        {
          g_symbol_set_mode=2;
          DialogBox(g_sdata.hInstance,MAKEINTRESOURCE(DLG_SYMBOLSET),hwndDlg,(DLGPROC)SymbolSetProc);
        }
        break;
        case IDDEL:
        {
          int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELCOUNT, 0, 0);
          int *items = (int *)GlobalAlloc(GPTR, n*sizeof(int));
          int rv = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELITEMS, (WPARAM)n, (LPARAM)items);
          int i;
          for(i=n-1;i>=0;i--) {
            SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_DELETESTRING, (WPARAM)items[i], 0);
          }
          EnableSymbolSetButtons(hwndDlg);
        }
        break;
        case IDC_SYMBOL:
          if(HIWORD(wParam) == EN_CHANGE)
          {
            int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOL, WM_GETTEXTLENGTH, 0, 0);
            if(n > 0) {
              EnableWindow(GetDlgItem(hwndDlg, IDRIGHT), TRUE);
            }
            else {
              EnableWindow(GetDlgItem(hwndDlg, IDRIGHT), FALSE);
            }
          }
          break;
        case IDC_SYMBOLS:
          if(HIWORD(wParam) == LBN_SELCHANGE)
          {
            int n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELCOUNT, 0, 0);
            if(n == 0) {
              EnableWindow(GetDlgItem(hwndDlg, IDLEFT), FALSE);
              EnableWindow(GetDlgItem(hwndDlg, IDDEL), FALSE);
            }
            else if(n == 1) {
              EnableWindow(GetDlgItem(hwndDlg, IDLEFT), TRUE);
              EnableWindow(GetDlgItem(hwndDlg, IDDEL), TRUE);
            }
            else if(n > 1) {
              EnableWindow(GetDlgItem(hwndDlg, IDLEFT), FALSE);
              EnableWindow(GetDlgItem(hwndDlg, IDDEL), TRUE);
            }
          }
          break;
        }
      break;
    }
  }
  return FALSE;
}