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
Drew BentonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
Please show your code - how do you display the received text.
0
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 +=": ";
m_Receive_Box->GetWindowText(Cur2);
Cur += buffer;
Cur2 += Cur;
Cur2 += "\n";
m_Receive_Box->SetWindowText(Cur2);

**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.
0
SirVampyCommented:
Just add:
 m_Receive_Box->RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW)
after SetWindowText.
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

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
0
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?
0
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
0
PashaModCommented:
Closed, 125 points refunded.
PashaMod
Community Support Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.