Silviyaa

Untitled

Apr 6th, 2021
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.97 KB | None | 0 0
  1. INT_PTR CALLBACK Shop(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  2. {
  3.     char iTxt[20],item[20];
  4.  
  5.     int ind2,length,ind;
  6.     string Drinks[7] ;
  7.     string Food[7];
  8.     string Clother[7];
  9.     char* str;
  10.     Drinks[0] = "beer";
  11.     Drinks[1] = "milk";
  12.     Drinks[2] = "soda";
  13.     Drinks[3] = "water";
  14.     Drinks[4] = "limonade";
  15.     Drinks[5] = "fanta";
  16.     Drinks[6] = "kola";
  17.  
  18.     Food[0] = "pizza";
  19.     Food[1] = "pasta";
  20.     Food[2] = "hamburger";
  21.     Food[3] = "fish";
  22.     Food[4] = "cheese";
  23.     Food[5] = "eggs";
  24.     Food[6] = "cake";
  25.  
  26.     Clother[0] = "shirt";
  27.     Clother[1] = "t-shirt";
  28.     Clother[2] = "jeans";
  29.     Clother[3] = "dress";
  30.     Clother[4] = "top";
  31.     Clother[5] = "pants";
  32.     Clother[6] = "shoes";
  33.     UNREFERENCED_PARAMETER(lParam);
  34.     switch (message)
  35.     {
  36.     case WM_INITDIALOG:
  37.         CheckDlgButton(hDlg, IDC_RADIO_KEYBOARD, BST_CHECKED);
  38.         CheckDlgButton(hDlg, IDC_RADIO_DRINKS, BST_CHECKED);
  39.         //CheckDlgButton(hDlg, IDC_RADIO_ARRAY, BST_CHECKED);
  40.         //CheckDlgButton(hDlg, IDC_RADIO_FOOD, BST_CHECKED);
  41.         //CheckDlgButton(hDlg, IDC_RADIO_CLOTHES, BST_CHECKED);
  42.         return (INT_PTR)TRUE;
  43.  
  44.     case WM_COMMAND:
  45.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  46.         {
  47.             EndDialog(hDlg, LOWORD(wParam));
  48.             return (INT_PTR)TRUE;
  49.         }
  50.         else if (LOWORD(wParam) == IDC_ADD) {
  51.        
  52.            
  53.             if (SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_FINDSTRING, -1, (LPARAM)iTxt) == LB_ERR) {
  54.                 if (IsDlgButtonChecked(hDlg, IDC_RADIO_KEYBOARD))
  55.                 {//вземаме съдържанието в Item(edit control) и го добавяме в Articles (list box)
  56.                     GetDlgItemText(hDlg, IDC_ITEM, (LPSTR)iTxt, 20);
  57.                     SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_ADDSTRING, 0, (LPARAM)iTxt);
  58.                 }
  59.                 if (IsDlgButtonChecked(hDlg, IDC_RADIO_ARRAY)) {
  60.                     if (IsDlgButtonChecked(hDlg, IDC_RADIO_DRINKS)) {
  61.                         SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_RESETCONTENT, 0, 0);
  62.                         for (int i = 0; i < 7; i++) {
  63.                             string temp = Drinks[i];
  64.                             str = &temp[0];
  65.                             SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_ADDSTRING, 0, (LPARAM)str);
  66.                         }
  67.  
  68.                     }else   if (IsDlgButtonChecked(hDlg, IDC_RADIO_FOOD)) {
  69.                         SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_RESETCONTENT, 0, 0);
  70.                         for (int i = 0; i < 7; i++) {
  71.                             string temp = Food[i];
  72.                             str = &temp[0];
  73.                             SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_ADDSTRING, 0, (LPARAM)str);
  74.                         }
  75.  
  76.                     }else   if (IsDlgButtonChecked(hDlg, IDC_RADIO_CLOTHES)) {
  77.                         SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_RESETCONTENT, 0, 0);
  78.                         for (int i = 0; i < 7; i++) {
  79.                             string temp = Clother[i];
  80.                             str = &temp[0];
  81.                             SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_ADDSTRING, 0, (LPARAM)str);
  82.                         }
  83.  
  84.                     }
  85.  
  86.                 }
  87.             }
  88.  
  89.         } else if (LOWORD(wParam) == IDC_BUY) {
  90.             char* text;
  91.  
  92.             ind2 = SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_GETCURSEL, 0, 0);
  93.             length= SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_GETTEXTLEN, ind2, 0);
  94.             text = new char[length + 1];
  95.             SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_GETTEXT, ind2, (LPARAM)text);
  96.             if (SendDlgItemMessage(hDlg, IDC_COMBO_CART,CB_FINDSTRING,-1, (LPARAM)text)==CB_ERR) {
  97.                 SendDlgItemMessage(hDlg, IDC_COMBO_CART, CB_ADDSTRING, 0, (LPARAM)text);
  98.                 SendDlgItemMessage(hDlg, IDC_COMBO_CART, CB_SELECTSTRING, -1, (LPARAM)text);
  99.             }
  100.         }
  101.         else if (LOWORD(wParam) == IDC_DELETE) {
  102.             ind = SendDlgItemMessage(hDlg, IDC_COMBO_CART, CB_GETCURSEL, 0, 0);
  103.             SendDlgItemMessage(hDlg, IDC_COMBO_CART, CB_DELETESTRING, ind, 0);
  104.         }
  105.         else if (LOWORD(wParam) == IDC_SEARCH) {
  106.             GetDlgItemText(hDlg, IDC_ITEM, item, 20);
  107.             SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_SELECTSTRING, -1, (LPARAM)item);
  108.             if (SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_SELECTSTRING, -1, (LPARAM)item) == LB_ERR) {
  109.                 MessageBox(NULL, "No such item!", "Information", MB_ICONINFORMATION | MB_YESNO);
  110.             }
  111.            
  112.         }
  113.         else if (LOWORD(wParam) == IDC_CLEAR) {
  114.             SetWindowText(GetDlgItem(hDlg, IDC_ITEM), "");
  115.             SendDlgItemMessage(hDlg, IDC_LIST_ARTICLES, LB_RESETCONTENT, 0, 0);
  116.         }
  117.        
  118.  
  119.         break;
  120.  
  121.     }
  122.     return (INT_PTR)FALSE;
  123. }
  124.  
Advertisement
Add Comment
Please, Sign In to add comment