Reputation: 1
I am a noob spelling it out will help. Using c++ win32 api i need to get an int variable from a textfield to control a for loop.
I have my button, textfields and, variables all setup. I just need "Textfield1" given to "int LVL1" and "Textfield2" given to "int LVL2".
I basically have no idea where to start, tried searching here and other places and keep getting char or java answers.g
I got this far what am I doing wrong? GetDlgItemInt( TextField1, LVL1, NULL, false); But doesn't change the value.
CODE:
case WM_CREATE:{ TextField1 = CreateWindow("Edit", "Current Lvl",
TextField2 = CreateWindow("EDIT", "Desired Lvl",
Button = CreateWindow("BUTTON", "Submit",
break; } case WM_COMMAND:
if(LOWORD(wParam == 1)){system("echo \"Submit\" Button"); ///Used for debuggin only int souls[793] = {0, 0 , 673 , 690 , 707 , 724 , 741 , 758 , 775 , 793 , 811 , 829 , 847 , 1039 , 1238 , 1445 , 1660 , 1883 , 2114 , 2353 , 2601 , 2857 , 3122 , 3396 , 3678 , 3970 , 4271 , 4581 , 4900 , 5229 , 5567 , 5915 , 6273 , 6641 , 7019 , 7407 , 7805 , 8214 , 8634 , 9064 , 9505 , 9957 , 10420 , 10894 , 11379 , 11876 , 12384 , 12904 , 13436 , 13979 , 14535 , 15103 , 15683 , 16275 , 16880 , 17497 , 18127 , 18770 , 19426 , 20095 , 20777 , 21472 , 22181 , 22904 , 23640 , 24390 , 25154 , 25932 , 26724 , 27530 , 28351 , 29186 , 30036 , 30901 , 31780 , 32675 , 33585 , 34510 , 35450 , 36406 , 37377 , 38364 , 39367 , 40386 , 41421 , 42472 , 43539 , 44623 , 45724 , 46841 , 47975 , 49126 , 50294 , 51479 , 52681 , 53901 , 55138 , 56393 , 57666 , 58956 , 60265 , 61592 , 62937 , 64300 , 65682 , 67082 , 68501 , 69939 , 71396 , 72872 , 74367 , 75881 , 77415 , 78969 , 80542 , 82135 , 83748 , 85381 , 87034 , 88707 , 90401 , 92115 , 93850 , 95606 , 97382 , 99180 , 100999 , 102839 , 104700 , 106583 , 108487 , 110413 , 112361 , 114331 , 116323 , 118337 , 120373 , 122432 , 124514 , 126618 , 128745 , 130895 , 133068 , 135264 , 137483 , 139726 , 141992 , 144282 , 146596 , 148933 , 151295 , 153681 , 156091 , 158525 , 160984 , 163467 , 165975 , 168508 , 171066 , 173649 , 176257 , 178890 , 181549 , 184234 , 186944 , 189680 , 192442 , 195230 , 198044 , 200884 , 203751 , 206644 , 209564 , 212511 , 215484 , 218485 , 221513 , 224568 , 227650 , 230760 , 233897 , 237062 , 240255 , 243476 , 246725 , 250002 , 253307 , 256641 , 260004 , 263395 , 266815 , 270264 , 273742 , 277249 , 280785 , 284351 , 287946 , 291571 , 295226 , 298910 , 302625 , 306370 , 310145 , 313950 , 317786 , 321652 , 325549 , 329477 , 333436 , 337426 , 341447 , 345499 , 349583 , 353699 , 357846 , 362025 , 366236 , 370479 , 374754 , 379061 , 383401 , 387773 , 392178 , 396616 , 401086 , 405590 , 410127 , 414697 , 419300 , 423937 , 428607 , 433311 , 438049 , 442821 , 447627 , 452467 , 457341 , 462250 , 467194 , 472172 , 477185 , 482233 , 487316 , 492434 , 497587 , 502776 , 508000 , 513260 , 518556 , 523887 , 529255 , 534659 , 540099 , 545575 , 551088 , 556637 , 562223 , 567846 , 573506 , 579203 , 584937 , 590708 , 596517 , 602364 , 608248 , 614170 , 620130 , 626128 , 632164 , 638238 , 644351 , 650502 , 656692 , 662921 , 669188 , 675495 , 681841 , 688226 , 694650 , 701114 , 707617 , 714160 , 720743 , 727366 , 734029 , 740732 , 747476 , 754259 , 761084 , 767949 , 774855 , 781802 , 788790 , 795819 , 802889 , 810001 , 817154 , 824349 , 831586 , 838864 , 846185 , 853548 , 860953 , 868400 , 875890 , 883422 , 890997 , 898615 , 906276 , 913980 , 921727 , 929517 , 937351 , 945229 , 953150 , 961115 , 969124 , 977177 , 985274 , 993415 , 1001601 , 1009831 , 1018106 , 1026426 , 1034790 , 1043200 , 1051655 , 1060155 , 1068700 , 1077291 , 1085927 , 1094609 , 1103337 , 1112111 , 1120931 , 1129797 , 1138710 , 1147668 , 1156674 , 1165726 , 1174825 , 1183971 , 1193164 , 1202404 , 1211691 , 1221026 , 1230408 , 1239838 , 1249316 , 1258841 , 1268415 , 1278037 , 1287707 , 1297425 , 1307192 , 1317007 , 1326871 , 1336784 , 1346746 , 1356757 , 1366817 , 1376927 , 1387085 , 1397294 , 1407552 , 1417860 , 1428218 , 1438626 , 1449084 , 1459592 , 1470151 , 1480760 , 1491420 , 1502131 , 1512892 , 1523705 , 1534569 , 1545484 , 1556450 , 1567468 , 1578537 , 1589658 , 1600831 , 1612056 , 1623333 , 1634662 , 1646044 , 1657477 , 1668964 , 1680503 , 1692095 , 1703740 , 1715438 , 1727189 , 1738993 , 1750851 , 1762762 , 1774727 , 1786746 , 1798818 , 1810945 , 1823126 , 1835361 , 1847650 , 1859994 , 1872392 , 1884845 , 1897353 , 1909916 , 1922534 , 1935207 , 1947936 , 1960719 , 1973559 , 1986454 , 1999405 , 2012412 , 2025475 , 2038594 , 2051769 , 2065001 , 2078289 , 2091634 , 2105036 , 2118495 , 2132010 , 2145583 , 2159213 , 2172900 , 2186645 , 2200447 , 2214307 , 2228225 , 2242201 , 2256235 , 2270327 , 2284478 , 2298686 , 2312954 , 2327280 , 2341665 , 2356109 , 2370612 , 2385174 , 2399795 , 2414476 , 2429216 , 2444016 , 2458876 , 2473796 , 2488775 , 2503815 , 2518915 , 2534075 , 2549296 , 2564577 , 2579919 , 2595322 , 2610786 , 2626311 , 2641897 , 2657545 , 2673253 , 2689024 , 2704856 , 2720750 , 2736706 , 2752724 , 2768804 , 2784946 , 2801151 , 2817418 , 2833748 , 2850141 , 2866597 , 2883115 , 2899697 , 2916342 , 2933050 , 2949822 , 2966657 , 2983556 , 3000519 , 3017546 , 3034637 , 3051792 , 3069012 , 3086295 , 3103644 , 3121057 , 3138535 , 3156078 , 3173686 , 3191359 , 3209097 , 3226901 , 3244770 , 3262705 , 3280706 , 3298773 , 3316905 , 3335104 , 3353369 , 3371700 , 3390098 , 3408562 , 3427093 , 3445691 , 3464356 , 3483088 , 3501887 , 3520754 , 3539687 , 3558689 , 3577758 , 3596895 , 3616100 , 3635373 , 3654714 , 3674123 , 3693601 , 3713147 , 3732762 , 3752446 , 3772199 , 3792020 , 3811911 , 3831871 , 3851900 , 3871999 , 3892167 , 3912405 , 3932713 , 3953091 , 3973539 , 3994057 , 4014646 , 4035304 , 4056034 , 4076834 , 4097705 , 4118647 , 4139660 , 4160744 , 4181899 , 4203126 , 4224424 , 4245795 , 4267236 , 4288750 , 4310335 , 4331993 , 4353723 , 4375525 , 4397400 , 4419347 , 4441367 , 4463460 , 4485626 , 4507865 , 4530177 , 4552563 , 4575021 , 4597554 , 4620160 , 4642840 , 4665594 , 4688422 , 4711324 , 4734300 , 4757351 , 4780476 , 4803677 , 4826951 , 4850301 , 4873725 , 4897225 , 4920800 , 4944450 , 4968176 , 4991977 , 5015854 , 5039807 , 5063836 , 5087941 , 5112122 , 5136380 , 5160713 , 5185124 , 5209611 , 5234175 , 5258816 , 5283534 , 5308329 , 5333201 , 5358151 , 5383178 , 5408284 , 5433466 , 5458727 , 5484065 , 5509482 , 5534977 , 5560550 , 5586202 , 5611932 , 5637741 , 5663629 , 5689596 , 5715642 , 5741767 , 5767972 , 5794255 , 5820619 , 5847062 , 5873585 , 5900188 , 5926871 , 5953634 , 5980477 , 6007401 , 6034405 , 6061491 , 6088656 , 6115903 , 6143230 , 6170639 , 6198129 , 6225700 , 6253353 , 6281087 , 6308903 , 6336801 , 6364781 , 6392843 , 6420987 , 6449214 , 6477522 , 6505914 , 6534388 , 6562945 , 6591585 , 6620308 , 6649114 , 6678003 , 6706976 , 6736032 , 6765173 , 6794396 , 6823704 , 6853095 , 6882571 , 6912131 , 6941775 , 6971504 , 7001317 , 7031215 , 7061198 , 7091266 , 7121419 , 7151657 , 7181981 , 7212389 , 7242884 , 7273464 , 7304130 , 7334882 , 7365720 , 7396644 , 7427654 , 7458751 , 7489934 , 7521204 , 7552561 , 7584005 , 7615535 , 7647153 , 7678858 , 7710650 , 7742530 , 7774497 , 7806552 , 7838695 , 7870926 , 7903245 , 7935652 , 7968148 , 8000731 , 8033404 , 8066165 , 8099015 , 8131954 , 8164982 , 8198099 , 8231305 , 8264601 , 8297986 , 8331461 , 8365026 , 8398682 , 8432426 , 8466260 , 8500184 , 8534200 , 8568306 , 8602502 , 8636790 , 8671168 , 8705636 , 8740196 , 8774848 , 8809590 , 8844424 , 8879350 , 8914366 , 8949476 , 8984676 , 9019970 , 9055354 , 9090832 , 9126402 , 9162064 , 9197818 , 9233666 , 9269608 , 9305640 , 9341768 , 9377986 , 9414300 , 9450706 , 9487208 , 9523802 , 9560490 , 9597272 , 9634148 , 9671118 , 9708182 , 9745340 , 9782594 , 9819942 , 9857386 , 9894922 , 9932556 , 9970284 , 10008108 , 10046026 , 10084040 , 10122150 , 10160356 , 10198658 , 10237056 , 10275550 , 10314138 , 10352826 , 10391608 , 10430488 , 10469464 , 10508536 , 10547706 , 10586974 , 10626338 , 10665798 , 10705358 , 10745014 , 10784768 , 10824620 , 10864570 , 10904618 , 10944764 , 10985008 , 11025350 , 11065792 , 11106332 , 11146972 , 11187708 , 11228546 , 11269482 , 11310516 , 11351650 , 11392884 , 11434218 , 11475650 , 11517184 , 11558816 , 11600550 , 11642382 , 11684316 , 11726350 , 11768484 , 11810720 , 11853056 , 11895492 , 11938030}; ///Above is the values for addition. souls[0] is never used. (Array currently incomplete) int SoulTotal = 0; int LVL1 = 2; int LVL2 = 2;
LVL1 = (int)GetDlgItemInt(TextField1, LVL1, &textOkay, TRUE);
system("Pause"); cout << "Textfield1 = " << LVL1 << endl; /** Get interger from Textfields */for(int x = LVL1;x>LVL2;x++){
}
Upvotes: 0
Views: 429
Reputation: 171
I always get the string and convert it to an int. Look at the documentation for GetWindowText().
So first, retrieve a handle to the window of the text field:
HWND hText = GetDlgItem(hParent, ID_TEXT_FIELD1); // hParent is parent window of text field
Then, you want to get the length of the text to know how much memory to allocate and to check for a maximum/minimum length:
int len = GetWindowTextLength(hText);
Now allocate a buffer to retrieve the string from the field.
char* buf = new char[len + 1];
And retrieve the text:
int ret = GetWindowText(hText, buf, sizeof(buf));
According to the docs, ret will be greater than zero if the function succeeded, so if it is, continue and convert the buffer to an integer:
int LVL1 = atoi(buf); // atoi() is from stdlib.h
This will work assuming you made the text field only accept numbers, or parse the buffer correctly. So now you have the integer value, and you can do the same for LVL2.
Don't forget to free the buffer:
delete[] buf;
Upvotes: 0