News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

creating wxThread and wxFrame classes in seperate files.

Started by nishalns, July 24, 2013, 12:35:46 PM

Previous topic - Next topic

nishalns

I am referring to the program given in the link: http://docs.wxwidgets.org/trunk/classwx_thread.html. Now, in my program I want to write "MyFrame" and "MyThread" classes in seperate '.h' and '.cpp' files. How would I do that?

Also, is there a way by which I can add threads to my project in wxsmith just as I add wxFrame, wxDialog,etc. from the wxSmith menu.

MortenMacFly


  • Create the frame using wxSmith, naming it as you like (i.e. MyFrame). This results in MyFrame.cpp and MyFrame.h being created.
  • Implement the Thread class into own files
  • Reference this class in your "MyFrame" class, or wherever needed. Notice that wxSmith has (by design) no interface to a wxThread, as it is not a GUI (related) class.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

nishalns

Quote from: MortenMacFly on July 24, 2013, 03:49:36 PM

  • Create the frame using wxSmith, naming it as you like (i.e. MyFrame). This results in MyFrame.cpp and MyFrame.h being created.
  • Implement the Thread class into own files
  • Reference this class in your "MyFrame" class, or wherever needed. Notice that wxSmith has (by design) no interface to a wxThread, as it is not a GUI (related) class.


Can you give me a short example demonstrating this. I'm finding it a bit difficult to understand...

ollydbg

Quote from: nishalns on July 25, 2013, 02:07:18 PM
Can you give me a short example demonstrating this. I'm finding it a bit difficult to understand...
Suppose you have a MyThread.h and MyThread.cpp which have class MyThread's declaration and implementation, then in the MyFrame.h or MyFrame.cpp, just use
#include "MyThreads.h"
Put MyFrame.cpp into your project, that's all.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

nishalns

Well, thanks all for answering my question. Actually, I included the 'MyThread.h' in 'MyFrame.h' and vice versa and also used forward declaration and the problem was solved.