Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. UI Thread dummy window !?!?!?

UI Thread dummy window !?!?!?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondesignsysadminhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Luc Bergeron
    wrote on last edited by
    #1

    Hi to all !!! I'm currently trying to code a Winsock server application. I'm using the main process thread to listen to incoming connection. When a connection is detected (i'm using WSAAsyncSelect) i spawn a new UI thread that will process that connection. I do not want a window to appear but i'm creating a dummy window because I need the message map... But the problem i'm having right now is that the messages for the WSAAsyncSelect goes to the dummy window and not to the UI thread message map... Here is how I create the dummy window... //------------------------------------------------- bool CConnection::InitDummyWnd(void) { m_pDummyDlg = new CDummyDlg; if (!m_pDummyDlg->Create(IDD_DUMMY, NULL)) return false; m_pMainWnd = (CWnd *)m_pDummyDlg; m_pMainWnd->SubclassWindow(m_pDummyDlg->GetSafeHwnd()); m_pMainWnd->ShowWindow(SW_SHOW); return true; } bool CConnection::PrepareWSAAsync(void) { if (WSAAsyncSelect(m_sock.getSocket(), m_pMainWnd->GetSafeHwnd(), WSA_THREADSOCKETEVENT, FD_READ | FD_WRITE | FD_CLOSE) == SOCKET_ERROR) { WORD err = WSAGetLastError(); return false; } return true; } //------------------------------------------------------------ How can I make sure that the thread message map gets all the winsock message instead of the dummy window message map ??? Thanks for any advice ! Luc B.

    J 1 Reply Last reply
    0
    • L Luc Bergeron

      Hi to all !!! I'm currently trying to code a Winsock server application. I'm using the main process thread to listen to incoming connection. When a connection is detected (i'm using WSAAsyncSelect) i spawn a new UI thread that will process that connection. I do not want a window to appear but i'm creating a dummy window because I need the message map... But the problem i'm having right now is that the messages for the WSAAsyncSelect goes to the dummy window and not to the UI thread message map... Here is how I create the dummy window... //------------------------------------------------- bool CConnection::InitDummyWnd(void) { m_pDummyDlg = new CDummyDlg; if (!m_pDummyDlg->Create(IDD_DUMMY, NULL)) return false; m_pMainWnd = (CWnd *)m_pDummyDlg; m_pMainWnd->SubclassWindow(m_pDummyDlg->GetSafeHwnd()); m_pMainWnd->ShowWindow(SW_SHOW); return true; } bool CConnection::PrepareWSAAsync(void) { if (WSAAsyncSelect(m_sock.getSocket(), m_pMainWnd->GetSafeHwnd(), WSA_THREADSOCKETEVENT, FD_READ | FD_WRITE | FD_CLOSE) == SOCKET_ERROR) { WORD err = WSAGetLastError(); return false; } return true; } //------------------------------------------------------------ How can I make sure that the thread message map gets all the winsock message instead of the dummy window message map ??? Thanks for any advice ! Luc B.

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      It is the call WSAAsyncSelect(m_sock.getSocket(), m_pMainWnd->GetSafeHwnd(),...) that is telling Winsock to send notifications to your dummy window. The problem is that WSAAsyncSelect needs a valid HWND to send the notifications to. One workaround for this is having PreTranslateMessage overriden so that it intercepts messages intended to the dummy window from Winsock, like this:

      BOOL CConection::PreTranslateMessage(MSG *pMsg)
      {
      if(pMsg->message==WSA_THREADSOCKETEVENT){
      pMsg->hwnd=0; // divert this message to the thread
      }
      return 0;
      }

      Haven't checked it out myself, so it'd be great if you tell us back whether this works. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      L 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        It is the call WSAAsyncSelect(m_sock.getSocket(), m_pMainWnd->GetSafeHwnd(),...) that is telling Winsock to send notifications to your dummy window. The problem is that WSAAsyncSelect needs a valid HWND to send the notifications to. One workaround for this is having PreTranslateMessage overriden so that it intercepts messages intended to the dummy window from Winsock, like this:

        BOOL CConection::PreTranslateMessage(MSG *pMsg)
        {
        if(pMsg->message==WSA_THREADSOCKETEVENT){
        pMsg->hwnd=0; // divert this message to the thread
        }
        return 0;
        }

        Haven't checked it out myself, so it'd be great if you tell us back whether this works. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        L Offline
        L Offline
        Luc Bergeron
        wrote on last edited by
        #3

        Nope doesn't work. My CConnection::PreTranslateMessage never gets called !?!?!

        J 1 Reply Last reply
        0
        • L Luc Bergeron

          Nope doesn't work. My CConnection::PreTranslateMessage never gets called !?!?!

          J Offline
          J Offline
          Joaquin M Lopez Munoz
          wrote on last edited by
          #4

          Hmmm... Do you mean CConnection::PreTranslateMessage never ever gets called (for this or for any other message) and yet the Winsock messages make their way to the dummy window message map? At least some standard messages delivered to the dummy window upon creation should go across PreTranslateMessage. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups