The Geek Forum

  • April 27, 2024, 02:37:55 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Due to the prolific nature of these forums, poster aggression is advised.

*

Recent Forum Posts

Shout Box

Members
Stats
  • Total Posts: 129551
  • Total Topics: 7148
  • Online Today: 141
  • Online Ever: 1013
  • (January 12, 2023, 01:18:11 AM)

Author Topic: Quick C++ question  (Read 2257 times)

Probie

  • Professional Blogger
  • ***
  • Coolio Points: +223/-5
  • Offline Offline
  • Posts: 644
  • The natural nap catalyst
    • View Profile
    • SoggyBlog
Quick C++ question
« on: November 05, 2009, 05:43:29 AM »


I'm doing a little proof of concept app using winapi and opengl. I have a main process which fires off a thread and within that thread it creates a window. Now the window isn't on the task bar it's a system tray app and the trayIcon object is a member of the window.

So thread class owns window, window owns tray, tray owns pop up menu. Now when i work this 'thread with window' into the final app, that will already have a working  trayicon and menu that will be associated with the other main app and i will just be running a window in a separate thread.

However for the current app its all a bit hacky...okay A LOT hacky. So I am having to add features to this app through the menu which then calls windowproc and windowproc is associated with the window as per usual. All these features work quite nicely...however!

When I called exit in my menu this goes to the big switch in the sky and calls close(), this then kills the trayicon and sends a mesage to wm_close destructs the window and used to close the app....however now we have this thread in the middle that owns the window when the window is close the thread is still running. I'm waffling... but the long of short of it is I did this:

class Window{
void* pParent; // going to be the thread that owns the window. Can't declare the proper type for a very good reason VC++ wont     
                    // explain and I can't find the right search criteria.
};

Window::Close()
{
if (m_trayIcon.IsVisible())
      m_trayIcon.OnDestroy();

   BluelineThread* pBlueline = static_cast<BluelineThread*>(pParent);
   if (pBlueline)
      pBlueline->m_bKeepThreadingAlive = false;

   if (m_hWnd)
      ::SendMessage(m_hWnd, WM_CLOSE, 0, 0);

}

pParent = this; // this happen in the window init

So what I want to know is....being that I know this is all hacky, how bad is it that I have done this? AND is it functional enough to leave in a prototype.

Also in my old company we could easily be able to pass a pointer of a parent to one of its children it was part of our model, so why can't I instance an object window in thread and thread in window? I'm sure it's very simple, but I just can't put my finger on it. Do I need to forward declare the class or something?


Logged
// ------- Probie ------- //
// ----------------------- //
// --- T3H GEEKERY --- //
// ----------------------- //
www.niccisixx.com - I can put this here, because I'm awesome.

Probie

  • Professional Blogger
  • ***
  • Coolio Points: +223/-5
  • Offline Offline
  • Posts: 644
  • The natural nap catalyst
    • View Profile
    • SoggyBlog
Re: Quick C++ question
« Reply #1 on: November 05, 2009, 10:49:18 AM »


I started re-writing it in mfc/opengl.....now I am getting pissed off. To many contradicting ideas...need to know more. Rubbish.
Logged
// ------- Probie ------- //
// ----------------------- //
// --- T3H GEEKERY --- //
// ----------------------- //
www.niccisixx.com - I can put this here, because I'm awesome.

BizB

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +439/-15
  • Offline Offline
  • Gender: Male
  • Posts: 4324
  • Keep making circles
    • View Profile
Re: Quick C++ question
« Reply #2 on: November 05, 2009, 12:10:37 PM »

I gots nuttin. I haven't written anything in C++ since 2002 and I've never dealt with systray and nonsense like that.
Logged
Without me, it's just 'aweso'.

12AX7

  • Guest
Re: Quick C++ question
« Reply #3 on: November 05, 2009, 12:10:58 PM »

   You'll get it. Hang in there. : )
Logged

ivan

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +499/-50
  • Offline Offline
  • Posts: 4929
  • Not a Mod, nor a Rocker. A Mocker.
    • View Profile
Re: Quick C++ question
« Reply #4 on: November 05, 2009, 12:45:34 PM »

I know COBOL like the back of my hand.
Logged
"I TYPE 120 WORDS PER MINUTE, BUT IT'S IN MY OWN LANGUAGE!"  -Detta

xolik: WHERE IS OBAMA'S GIFT CERTIFICATE?
Demosthenes: Is that from the gifters movement?


Detta: Crappy old shorts and a tank top.  This is how I dress for work. Because my job is to get puked on.
Demosthenes: So is mine.  I work in IT.


bananaskittles: The world is 4chan and God is a troll.

pbsaurus

  • Hacker
  • ****
  • Coolio Points: +354/-31
  • Offline Offline
  • Gender: Male
  • Posts: 9981
  • Everyone Loves The King Of The Sea
    • View Profile
    • http://www.myspace.com/flipperpete
Re: Quick C++ question
« Reply #5 on: November 05, 2009, 12:46:46 PM »

It's not a full moon right now Ivan