• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

Updating a different program's display window when it does not have focus

Hi ev1. What I'm currently working on is a basic chat program. I have only 1 issue i need to solve. I have two windows, which are 2 different programs, one is a client, one is a server. The problem is that when the client sends a message (text) to the server, and the server does not have focus, the text isn't displayed until it regains focus or i move the mouse over the box. I tried overloading the "DefWindowProc" function so that it'll update the program even when its not in focus, but it didn't work. I tried using the class wizard to update the view on focus loss, and the other provided functions. For ease of answering, the server window has 1 component, a RichEdit box, added via the insert active x control. For 1 final explanation, if you use AIM or MSN Messenger, if someone sends you a message, and the chat dialog is up, but not in focus, you still can see the message, i want to emulate the same. Thanks! - Drew

PS If you need more info on nething, plz ask, i didn't want to just put down useless stuff
1 Solution
Please show your code - how do you display the received text.
Drew_BentonAuthor Commented:
Ok i used a function that listens, and its long b/c it uses threads, so ill show the text part

void Listen(CMFC_ChatDlg *win,CRichText *m_Receive_Box)
    // the main loop ... run once
    // If quit flag, break
    // lock the mutex
    // make the polling set and copy everything from masterSet
    // unlock the mutex
    // check if our set is empty, if so 'continue'
    // set the wait time
    // check for no sockets with data
    // check for errors
    // run loop for every socket in the polling set
       - Process the socket, get message size, check for errors, and finally get the actual message, which is stored in a char[4096], using the "recv()" function.

char ctmp[256];
itoa(clientSocket,ctmp,10);  // Converts the clients number to a string

CString Cur2 = ""; // Holds the text already in the receive box
CString Cur = "Client ";
Cur += ctmp;
Cur +=": ";
Cur += buffer;
Cur2 += Cur;
Cur2 += "\n";

**What happens is that after receving text, which is stored in "buffer", the contents of the "m_Receive_Box", a CRichText is stored in "Cur2". Then the message received is formated, and stored in "Cur", so the effect of "Client 1024: Message Sent" is produced. Finally this new message is appended to the original contents, and the "m_Receive_Box" text is set.

The problem is that i can't get the window to display this new text, unless the form gets focus or the mouse passes over. I probally could make the window have focus after every message, but that's undesiralbe, since I just want that "m_Receive_Box" to be updated, and is not typical of a chat program.
Just add:
after SetWindowText.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Drew_BentonAuthor Commented:
SirVampy thnx, but i need to clairfy more. The text i send to the window from the client shows, but only if the server program has foucs or if the mouse is dragged over the program. I tried that code, but the same happens still. So ill try to give a better explanation, 2 windows are on screen, the client, on the left, and the server, on the right. I type in a message on the client window and hit send, it should send the data to the server program, since im testing locally, and it does. But the problem is that the server does not process this im thinking, so the text is not displayed at all, untill the server window receives focus or a move the mouse over the actual window. I was thinking i needed to simulate an event similar to this, but now I think I'm seeing that this server window isn't processing messages at all, hence the window will not update. But i know there has to be a way to make a program i guess update constantly? even when its not the active window or the window in focus. AIM is an example, 1 window can be in foucs yet text can be dispayed in the other. Thnx
- Drew
Drew_BentonAuthor Commented:
After working some more, I'm sure its with the program, now the question is can i have the program run in the background (when its not in focus) by using threads, and if so, my "Listen()" function is the function that needs to be in a thread, do you think that'll work?
Drew_BentonAuthor Commented:
Ok ev1, I figured it out, what i did was set up a timer to run ever 100ms. each time, it calls the listen function, that way, even if the function does not have focus, it still updates. Thnx
- Drew
Closed, 125 points refunded.
Community Support Moderator
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now