Need Help With Windows Applications In C++

For all of you programmers out there familiar with C++, how would you program a button to open a new window in a dialog based executible file?

I’m a little confused by what you’re trying to do. Are you using MFC or the straight Windows API? Do you have the button/main window code done and you’re just trying to open a second window? Finally, what do you want to have appear in this new window?

Anyway, either reply here or email me and I’ll hook you up with some code snippets for any/all of these cases (I have a lot laying around from RoboGUI and RoboEmu).

First of all, I’m using MFC and second of all, I want the button displaying “Search” to open a new window and search for a specific file in a database. So far, I have about half of the project done. All of the windows are made, and all the buttons, etc. are in place. All I have to do is program the buttons to open new windows, save files, load files, search for files using specific keywords, and import pictures.

In that case, just create a message handler for the button using Class Wizard. Assuming you decide to call it something like OnSearchButton and your class for your search dialog is called CSearchDlg, the function would look something like this:


void CYourMainWndClass::OnSearchButton(){
  CSearchDlg searchDlg;
  int ret;

  
  ret=searchDlg.DoModal();

  if(ret==-1 || IDABORT)
    //error occurred
  else
    //ret contains value passed to EndDialog.  Process accordingly


}

That’s the basics. If you’re looking for something more advanced, email me.

Uh, where exactly in the code would you put this? I’m actually more familiar with DOS based and I wanted to learn Windows based.

Try this book.

Programming Windows by Charles Petzold

I know you may not want to read books, but it’s the best Windows programming book you can buy. It’s probabaly the only one you really need.

Actually, One by Andre LaMonth is pretty good (I think it’s called “Tips By Window Guru’s” or something like that (search for it over at GameDev.Net))

Beware of Lamothe books… they’re good to learn by, but the rule of thumb is never, ever use the style of coding he does. 99% of the time it’s considered just plain bad form and nastily inefficient. Still, I learned DirectX through one of his books, and after hanging around some real programmers to straighten out my misuse of some stuff, it worked real well :slight_smile: More on-topic, if you’re using MSVC++ 6, I belive double-clicking the search button in the resource editor while holding CTRL will bring up the place you need to put the aforementioned code. You’ll need to make a class for your search dialog, and the same procedure (or at least a similar one; I’m doing this from memory) will create that class from the resource. Good luck and happy coding.

PS - Gamedev.net rules, and you really need to check out the chat. It’ll solve all your programming woes.

Yeah, just ditch the CTRL key–you don’t need it.

GameDev is alright, but they still need to update their articles more. But more topic, this actually might depend on your compiler. Because MSVC++ .NET is different than MSVC++ 6 (or below). I’m not exact on this statement, but I’ve seen it, and read reviews about how MSV* .NET is different than MSV* (where the stars stand for like ‘B’ for Visual Basic)…plus, MSVC++ .NET seems more like VB 6 for the fact that you have drag-and-drops (unless I was looking at a wrong box)