Author Topic: creating wxThread and wxFrame classes in seperate files.  (Read 5886 times)

Offline nishalns

  • Multiple posting newcomer
  • *
  • Posts: 22
creating wxThread and wxFrame classes in seperate files.
« on: July 24, 2013, 12:35:46 pm »
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.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: creating wxThread and wxFrame classes in seperate files.
« Reply #1 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline nishalns

  • Multiple posting newcomer
  • *
  • Posts: 22
Re: creating wxThread and wxFrame classes in seperate files.
« Reply #2 on: July 25, 2013, 02:07:18 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...

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: creating wxThread and wxFrame classes in seperate files.
« Reply #3 on: July 25, 2013, 02:13:11 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
Code
#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.

Offline nishalns

  • Multiple posting newcomer
  • *
  • Posts: 22
Re: creating wxThread and wxFrame classes in seperate files.
« Reply #4 on: July 26, 2013, 05:57:37 am »
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.