Solved

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

Posted on 2003-11-22
8
242 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:Drew_Benton
8 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9805317
Please show your code - how do you display the received text.
0
 

Author Comment

by:Drew_Benton
ID: 9805924
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
 

Expert Comment

by:SirVampy
ID: 9809144
Just add:
 m_Receive_Box->RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW)
after SetWindowText.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Drew_Benton
ID: 9811772
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
 

Author Comment

by:Drew_Benton
ID: 9812208
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
 

Author Comment

by:Drew_Benton
ID: 9812299
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
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 10659647
Closed, 125 points refunded.
PashaMod
Community Support Moderator
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now