Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all 3021 articles
Browse latest View live

Issue with search function, and rating system

$
0
0
I am having issue with the search function, when I search my database instead of getting the information saved on the database I just get 1, so how can I fix it so it shows the info of the game which I have saved ? Also went it comes to rating, it has to be a system from 0-10, and if I make multiply inputs it should divide the total value with the number of inputs. Hopefully what I am saying makes sense. Code: --------- #include #include #include #include using namespace std; const int GameName = 50; // gameType is our custom data type which will be a struct with 4 members struct gameType { string name; string type; string price; string publisher; string dataBase[GameName]; int gameRating; }; // function prototypes int menu(); // display a menu to the user gameType addGame(); void addRating(gameType game[], int postion); void outputData(const gameType game[], int currentgame); void showgameByName(const gameType game[], int currentgame); int loadFromFile(gameType game[]); void saveToFile(const gameType game[], int currentgame); int findGame(const gameType game[], int currentgame, string name); int main() { // declare an array of 50 games gameType game[50]; int choice; string name; string type; string price; string publisher; int gameRating; // currently though, we have 0 game int currentgame = 0; // set up a loop to show and process our menu and the user's choice do { // call and display the menu and get the user's choice choice = menu(); // process that choice if (choice == 1) { // call the addGames function, which returns a variable // of type gameType. Store that in the array at the // the first open position, which is currentgame game[currentgame] = addGame(); // increment currentgame to note the new # of game currentgame++; } else if (choice == 2) { int position; // variable to hold the correct index for // the game to add an rating to cout << "Which game do you want to add an rating for? " << endl; showgameByName(game, currentgame); cin >> position; addRating(game, --position); } //Seach for game using name, genre, or rating else if (choice == 3) { cout << "Enter one of the following: Name of Video Game, Type of Video Game, or Rating of Video Game: " << endl; cin >> name, type, gameRating; cout << findGame(game, currentgame, type) << endl; } else if (choice == 4) { // call our output function passing to it the array of structs // which contains ALL data and the # of game, which will // tell the function how many game to loop through outputData(game, currentgame); } else if (choice == 5) { // populate our array from a file of data currentgame = loadFromFile(game); } else if (choice == 6) { // dump our array of structs to a file saveToFile(game, currentgame); } } while (choice != 7); return 0; } int menu() { int choice; cout << "1. Add Video Game" << endl << "2. Add Video Game Rating" << endl << "3. Search for Video Game" << endl << "4. Show Saved Video Games " << endl << "5. Load Data from File" << endl << "6. Save Data to File" << endl << "7. Exit Program" << endl; cin >> choice; return choice; } gameType addGame() { // create a temporary structure to hold the input gameType temp; cout << "Enter title of the game: "; // always use a cin.get() BEFORE a getline, AFTER a cin >> cin.get(); getline(cin, temp.name); cout << "Enter the Genre: "; cin >> temp.type; cout << "Enter Price Paid: "; cin >> temp.price; cout << "Publisher: "; cin >> temp.publisher; // set up the initial videogame dataBase with 0 prices temp.gameRating = 0; // send this game back to main return temp; } void addRating(gameType game[], int position) { string price; // ask what rating to add cout << "Enter the rating you want to add to the game: "; cin >> price; // add the price entered above to the next avaiable index // within the dataBase member variable (which is an array) // of the current games game[position].dataBase[game[position].gameRating] = price; // increment the number of rating in that person's dataBase game[position].gameRating++; } void outputData(const gameType game[], int currentgame) { for (int i = 0; i < currentgame; i++) { cout << left << setw(25) << "Name:" << game[i].name << endl; cout << left << setw(25) << "Genre:" << game[i].type << endl; cout << left << setw(25) << "Price:" << "$" << game[i].price << endl; cout << left << setw(25) << "Publisher:" << game[i].publisher << endl; // inner loop to output each rating in their dataBase for (int j = 0; j < game[i].gameRating; j++) cout << setw(25) << "Game Rating:" << " " << left << setw(30) << game[i].dataBase[j] << endl; cout << endl; } } void showgameByName(const gameType game[], int currentgame) { for (int i = 0; i < currentgame; i++) cout << left << setw(3) << (i + 1) << game[i].name << endl; } int loadFromFile(gameType game[]) { ifstream fin; fin.open("data.dat"); int num = 0; getline(fin, game[num].name); while (!(fin.eof())) { fin >> game[num].type; fin >> game[num].price; fin >> game[num].publisher; fin >> game[num].gameRating; // inner loop to get each rating in their dataBase for (int j = 0; j < game[num].gameRating; j++) fin >> game[num].dataBase[j]; num++; fin.get(); getline(fin, game[num].name); } return num; } void saveToFile(const gameType game[], int currentgame) { ofstream fout; fout.open("data.dat"); for (int i = 0; i < currentgame; i++) { fout << game[i].name << endl << game[i].type << endl << game[i].price << endl << game[i].publisher << endl; fout << game[i].gameRating << endl; // inner loop to output each rating in their dataBase for (int j = 0; j < game[i].gameRating; j++) fout << game[i].dataBase[j] << endl; } } int findGame(const gameType game[], int currentgame, string name) { for (int i = 1; i < currentgame; i++) { if (game[i].name == name); return i; } return -1; } ---------

MFC tree control highlight item selected by the keyboard ?

$
0
0
I have this old code in which I had: Code: --------- void ModCTreeCtrl::OnLButtonDown(UINT nFlags, CPoint point) { UINT uFlags; HTREEITEM htItem = this->HitTest(point, &uFlags); if ((htItem != NULL) && (uFlags & TVHT_ONITEM)) this->Select(htItem, TVGN_DROPHILITE); CTreeCtrl::OnLButtonDown(nFlags, point); } --------- in a derived class from a CTreeCtrl , actually I don't remember why I needed this (I think it had something to do with selection that changed in the current version , any idea ?) , anyway for some reason this prevent the "blue" highlight of the selected item from happening when I change the selected item using arrow keys , any idea why does this happen and how to fix it ? Whenever I change the selected item using arrow key it doesn't get automatically highlighted

aide code source C++

$
0
0
Bonsoir tout le monde, je suis une étudiante. Je n’ai pas des bonnes connaissances en c++. Mon travail n’est plus de programmation mais simplement j’ai besoin de travail sur des programmes qui existent déjà. Dans mon cas je n’ai pas trouvé un programme qui réponds à mes besoins alors j’ai écrit moi-même l’énoncé de mon programme et je compte sur vos collaborations pour écrire le code source Voilà l’énoncé du programme : Etant donné : Un texte t : correctness enhancement Et un alphabet P tiré aléatoirement Donc Je lance un tirage aléatoire d’un alphabet p quel qu’on (a, b, c, d, e, f,…) et je ne suis pas sûr que cet alphabet p est dans t S’il est dans t alors • La variable f (find) devrait avoir la valeur : true • La variable Z devrait contenir le résultat de la vérification de si l’alphabet tiré aléatoirement appartient aux 6 lettres voyelles (a, e, i, o, u, y) ou les 20 lettres consonnes (les autres lettres autres que les voyelles). • on met dans n la liste des indices où l’alphabet p tiré aléatoirement apparaît dans le texte t. • on met dans m le nombre de fois que l’alphabet tiré aléatoirement p apparaît dans le texte t. Sinon (si l’alphabet p tiré aléatoirement n’est pas dans le texte t) • f devrait avoir la valeur : false • z devrait avoir la valeur : 0 • n devrait avoir la valeur : 0 • et m devrait avoir la valeur : 0

[RESOLVED] aide code source C++

$
0
0
Bonsoir tout le monde, je suis une étudiante. Je n’ai pas des bonnes connaissances en c++. Mon travail n’est plus de programmation mais simplement j’ai besoin de travail sur des programmes qui existent déjà. Dans mon cas je n’ai pas trouvé un programme qui réponds à mes besoins alors j’ai écrit moi-même l’énoncé de mon programme et je compte sur vos collaborations pour écrire le code source Voilà l’énoncé du programme : Etant donné : Un texte t : correctness enhancement Et un alphabet P tiré aléatoirement Donc Je lance un tirage aléatoire d’un alphabet p quel qu’on (a, b, c, d, e, f,…) et je ne suis pas sûr que cet alphabet p est dans t S’il est dans t alors • La variable f (find) devrait avoir la valeur : true • La variable Z devrait contenir le résultat de la vérification de si l’alphabet tiré aléatoirement appartient aux 6 lettres voyelles (a, e, i, o, u, y) ou les 20 lettres consonnes (les autres lettres autres que les voyelles). • on met dans n la liste des indices où l’alphabet p tiré aléatoirement apparaît dans le texte t. • on met dans m le nombre de fois que l’alphabet tiré aléatoirement p apparaît dans le texte t. Sinon (si l’alphabet p tiré aléatoirement n’est pas dans le texte t) • f devrait avoir la valeur : false • z devrait avoir la valeur : 0 • n devrait avoir la valeur : 0 • et m devrait avoir la valeur : 0

Can't click on controls/menu when detach MDI child out of MDI client area

$
0
0
Whole sample project can be found here: Sample project (https://drive.google.com/open?id=0Byc4Rs2GTQ1RSUI1bzIyNFlWWmc) Normal MDI child: Attachment 34857 (http://forums.codeguru.com/attachment.php?attachmentid=34857) MDI child is detached out of MDI client area: Attachment 34859 (http://forums.codeguru.com/attachment.php?attachmentid=34859) Problem is after MDI child is detached, I am not able to click on menu/controls anymore. I think one approach is to subclass winproc of MDI app, and then catching the messages and redirect them (like this one (https://www.experts-exchange.com/questions/20358590/How-to-get-Clicks-on-a-form.html)). But I dont know where to begin. Any idea/ other approaches are welcome! The code I used to detach MDI child: Code: --------- HWND MDIHwnd = pMainFrame->m_hWndMDIClient; HWND mdiChildHwnd = GetWindow(MDIHwnd, GW_CHILD); unsigned int style = GetWindowLongPtr(mdiChildHwnd, GWL_STYLE); style = (style & (~WS_CHILD) | WS_POPUP); SetWindowLongPtr(mdiChildHwnd, GWL_STYLE, style); WaitForInputIdle(mdiChildHwnd, INFINITE); SetParent(mdiChildHwnd, NULL); WaitForInputIdle(mdiChildHwnd, INFINITE); SetWindowLongPtr(mdiChildHwnd, GWLP_HWNDPARENT, (long)MDIHwnd); ---------

WINDOWPLACEMENT and Maximized View

$
0
0
Hello, Tried to find an explanation for this behavior in the forum but could not find an answer. The GetWindowPlacement and SetWindowPlacement code using the registry works fine. The application always starts with the last shown window. However, if the user maximizes the view, any attempt to resize the maximized view automatically restores the window to the last window size! If the window is NOT maximized, user can resize normally by dragging on the window corners. Is this normal behavior? Thanks

[RESOLVED] Can't click on controls/menu when detach MDI child out of MDI client area

$
0
0
Whole sample project can be found here: Sample project (https://drive.google.com/open?id=0Byc4Rs2GTQ1RSUI1bzIyNFlWWmc) Normal MDI child: Attachment 34857 (http://forums.codeguru.com/attachment.php?attachmentid=34857) MDI child is detached out of MDI client area: Attachment 34859 (http://forums.codeguru.com/attachment.php?attachmentid=34859) Problem is after MDI child is detached, I am not able to click on menu/controls anymore. I think one approach is to subclass winproc of MDI app, and then catching the messages and redirect them (like this one (https://www.experts-exchange.com/questions/20358590/How-to-get-Clicks-on-a-form.html)). But I dont know where to begin. Any idea/ other approaches are welcome! The code I used to detach MDI child: Code: --------- HWND MDIHwnd = pMainFrame->m_hWndMDIClient; HWND mdiChildHwnd = GetWindow(MDIHwnd, GW_CHILD); unsigned int style = GetWindowLongPtr(mdiChildHwnd, GWL_STYLE); style = (style & (~WS_CHILD) | WS_POPUP); SetWindowLongPtr(mdiChildHwnd, GWL_STYLE, style); WaitForInputIdle(mdiChildHwnd, INFINITE); SetParent(mdiChildHwnd, NULL); WaitForInputIdle(mdiChildHwnd, INFINITE); SetWindowLongPtr(mdiChildHwnd, GWLP_HWNDPARENT, (long)MDIHwnd); ---------

Auto-complete selection

$
0
0
Hi, ALL, Is there a way to know when the auto-complete combo box selection occurs? Either by mouse click or "Enter" press. It doesn't look like it is from looking here (https://msdn.microsoft.com/en-us/library/windows/desktop/bb776292(v=vs.85).aspx). But maybe there is some hidden way? Thank you.

is there a faster alterantive for CreateFileW ?

$
0
0
I'm writing a directory enumerator and CreateFileW takes as long as NtQueryDirectoryFile when it's cached , is there a faster alternative to get the handle ?

What does mean: lParam | 0x80000000 in a WM_LBUTTONDOWN

$
0
0
Hello everyone, as the title, what does lParam | 0x80000000 mean in a WM_LBUTTONDOWN? I know that HI e LO lparam words specifies cursor coordinates, but what does it mean if I use an OR bitwise operator with 0x80000000? Thank you

Child Dialog constraint inside a Window

$
0
0
Hello everyone, could you please help me to find a good solution to constraint a dialog inside a window? So it move when window move, resize when window resize and so on. Thank you

Project Centennial

$
0
0
I've just been reading some stuff about Project Centennial (https://developer.microsoft.com/en-us/windows/projects/events/build2016/project-centennial-bringing-existing-desktop-applications-to-the-universal-windows-platform). Unfortunately... the sound system's stopped working on my PC (so I wasn't able to view the video) but from what I could gather, Project Centennial is Microsoft's plan to make sure that, in future, only certain "security aware" apps will be allowed to run on Windows 10. Does anyone know how this will affect compilations? I'm guessing that only the latest compilers will be supported? (and probably only compilers from Microsoft??) So anything written with gcc (or some older versions of MSVC) maybe won't be allowed any more... :cry:

MFC virtual ctreectrl ?

$
0
0
I'm trying to display a list of file system entries , for example the tree of a partition , what I want to do is to display entries expanded but only add entries to the ctreectrl as needed so for example if what fits in the display area is seven rows: D: Folder1 sub1 sub2 Folder2 sub1 sub2 so if Folder2 have thousand of items only 2 will be loaded & so on, is this possible ?

validation and menu call

$
0
0
Code: --------- case 1 : { char OTX; cout<<"Enter the code reserved for staff and faculty :"<>OTX; char answer; if (answer != 'OTX' && answer != 'otx' ) { cout<<"Access not authorized!\n"<>choice; } --------- hi everyone . So I have this piece of code where I want to be able to validate in upper and lower case a code reserved for some people and if its wrong I should send him back to the menu to choose an option . I.m getting Code: --------- char answer --------- uninitialized and I want to also if I can send the user back to menu without writing it again in the case . thx u

Why does 'virtual' make a difference here ??

$
0
0
I'm building a dll (let's call it DLL A) which uses a 3rd party dll (DLL B). But DLL A has never needed to link to the link library for DLL B. Recently, a new *name()* function got added to one of the classes in DLL B:- Code: --------- class LIBCONTROLCP_API ControlProtocol : public PBD::Stateful, public PBD::ScopedConnectionList, public BasicUI { public: ControlProtocol (Session&, std::string name); virtual ~ControlProtocol(); *std::string name() const { return _name; } // <--- This function got added * virtual int set_feedback (bool /*yn*/) { return 0; } virtual bool get_feedback () const { return false; } protected: std::string _name; }; --------- (assume that LIBCONTROLCP_API is either __dllimport or __dllexport, as appropriate). After the new function got added, I realised that I couldn't build DLL A any more without linking it to the link lib for DLL B. But the functions *get_feedback()* and *set_feedback()* have always worked without me needing the link lib. So I added *virtual *to name's declaration, like so:- Code: --------- virtual std::string name() const { return _name; } // I declared it as *virtual* --------- and the linker seems to accept this now without needing DLL B's link lib any more. I'm just curious to know why *virtual *would make a difference here :confused:

Embedding Python in C++ [BOOST]

$
0
0
Hi everyone, I have a problem that I'm unable to solve. I'm trying to embed Python in my C++ application. I saw examples online that use Python.h, however, I don't have that file and don't really know how to get it. I install the Python-dev and follow the usual steps of linking a third-party library. I was able to eventually get Visual Studio to see the Python.h file, but I get a compile time error. Instead of just repeating what I said earlier today, I'm going to link to my post in Qt: https://forum.qt.io/topic/78316/calling-python-from-qt-c/5 Anyway, I was successful at getting BOOST to work in Visual Studio and I tried to follow the instructions from BOOST's website and I cannot seem to get it to work. http://www.boost.org/doc/libs/1_64_0/libs/python/doc/html/tutorial/tutorial/embedding.html The problem with the objects that they are showing, they don't show it in an actual C++ program. I'm assuming that the Py_Initialize() and the objects are called in the main() function and I also made sure to include the BOOST python file, but I had no luck. Anyhow, please help me figure out how to use Python with C++. Having access to a high-level and low-level language will go a long ways in making me productive as a programmer. Thanks in advance.

Need help with my code.

$
0
0
SO for this project im using binary trees and im supposed to make a phone book contact list. I have the set up sorrect but for some reason I cant get the contact list or even the names if the people I input to come up. Code: --------- #include #include #include #include #include #include using namespace std; // define the class class PhoneContacts { // declare the variables. char name[20], phoneno[15]; public: // declare the member functions. void FindContacts(); void DisplayContacts(); char *getContactname() { return name; } char *getPhoneno() { return phoneno; } void updateContact(char *nam, char *telno) { strcpy_s(name, nam); strcpy_s(phoneno, telno); } }; //function to find the contacts. void PhoneContacts::FindContacts() { cout << "\nEnter Name : "; cin >> name; cout << "Enter Contact No. : "; cin >> phoneno; } // function to display the contacts. void PhoneContacts::DisplayContacts() { cout << "\n"; cout << setw(20) << name; cout << setw(15) << phoneno; } // Main int main() { // create object of the class. PhoneContacts pc; fstream fs; int opt; // open the file. fs.open("input.txt"); char ch, nam[20], phono[10]; int choice, status = 0; do { cout << endl << "*****Contact Book*****" << endl << endl; cout << "1) Add Contact\n" << endl << endl; cout << "2) Display current contact" << endl << endl; cout << "3) Find Contact Name." << endl << endl; cout << "4) Find Contact Number" << endl << endl; cout << "5) Update Contact No." << endl << endl; cout << "6) Exit" << endl << endl; cout << "Choose your choice : "; cin >> choice; switch (choice) { case 1: pc.FindContacts(); // write the new record fs.write((char *)&pc, sizeof(pc)); break; case 2: //Display Contacts list fs.seekg(0, ios::beg); cout << "\n\nRecords in Contact Book\n"; while (fs) { fs.read((char *)&pc, sizeof(pc)); if (!fs.eof()) pc.DisplayContacts(); } fs.clear(); break; case 3:// finding the contact name. cout << endl << endl << "Enter Contact Name: "; cin >> nam; fs.seekg(0, ios::beg); status = 0; while (fs.read((char *)&pc, sizeof(pc))) { if (strcmp(nam, pc.getContactname()) == 0) { status = 1; pc.DisplayContacts(); } } fs.clear(); if (status == 0) cout << endl << endl << "Contact is not found" << endl; break; case 4: //find contact name using the phone number. cout << endl << endl << "Enter Telephone No : "; cin >> phono; fs.seekg(0, ios::beg); status = 0; while (fs.read((char *)&pc, sizeof(pc))) { if (strcmp(phono, pc.getPhoneno()) == 0) { status = 1; pc.DisplayContacts(); } } fs.clear(); if (status == 0) cout << endl << endl << "Contact is not found" << endl; break; case 5: //Updating the contact Telephone No. cout << endl << endl << "Enter Name : " << endl; cin >> nam; fs.seekg(0, ios::beg); status = 0; int cnt = 0; while (fs.read((char *)&pc, sizeof(pc))) { cnt++; if (strcmp(nam, pc.getContactname()) == 0) { status = 1; break; } } fs.clear(); if (status == 0) cout << endl << endl << "Contact is not found" << endl; else { int location = (cnt - 1) * sizeof(pc); cin.get(ch); if (fs.eof()) fs.clear(); cout << "Enter New Telephone No : "; cin >> phono; fs.seekp(location); pc.updateContact(nam, phono); fs.write((char *)&pc, sizeof(pc)); fs.flush(); } break; } cout << endl << endl << "Do you want to continue? Press 1 otherwise 0: " << endl << endl; cin >> opt; } while (opt == 1); cout << endl << endl << "Thank you" << endl; system("pause"); return 0; } ---------

loop store of data

$
0
0
hello . I have a question on 2d arrays and loop Is there anyone to help. thx . Anyone??

error C2440: 'static_cast' : cannot convert from 'int (__thiscall CINVOICEView::* )(v

$
0
0
Hi I am trying to port old version C++ code into Visual Studio 2013. When I am trying to do this, I am getting the following error. 1> INVOICEView.cpp 1>INVOICEView.cpp(23): error C2440: 'static_cast' : cannot convert from 'int (__thiscall CINVOICEView::* )(void)' to 'AFX_PMSG' 1> None of the functions with this name in scope match the target type 1>INVOICEView.cpp(23): fatal error C1903: unable to recover from previous error(s); stopping compilation ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== Here is the code.... ON_COMMAND(ID_SAVE_TO_HOST, OnSaveToHost) #define ON_COMMAND(id, memberFxn) \ { WM_COMMAND, CN_COMMAND, (WORD)id, (WORD)id, AfxSigCmd_v, \ static_cast (memberFxn) }, // ON_COMMAND(id, OnBar) is the same as // ON_CONTROL(0, id, OnBar) or ON_BN_CLICKED(0, id, OnBar) int CINVOICEView::OnSaveToHost() { return (SaveToHost()); } Any help to fix the above error would be appreciated. Please do let me know if you need any additional details. Thank you.

Inicial path in browse folder dialog

$
0
0
I read about to set an initial path when we show a dialog for browse a folder, and i tried to do like i read. The dialog show this path and only this folder, not a tree, and i can`t change it. I want see the tree of directories and expanded the folders to show me the 'initial folder' that i want. Please, help. Thank you. PERE.
Viewing all 3021 articles
Browse latest View live