|
To track mouse events use _TrackMouseEvent. It sends to wnd event WM_MOUSELEAVE, when mouse goes out.
Example:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static BOOL bMouseInside;
switch (message)
{
case WM_MOUSEMOVE:
{
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = hWnd;
tme.dwFlags = TME_LEAVE;
_TrackMouseEvent(&tme);
if(!bMouseInside)
{
bMouseInside = TRUE;
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
}
}
break;
case WM_MOUSELEAVE:
bMouseInside = FALSE;
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
break;
The second approach is to use timer for periodically checking mouse position. If you received WM_MOUSEMOVE for the first time, you should enable timer, until you detect mouse absence
Example:
BOOL CMouseEvent::OnMouseMove....
{
if( m_uTimer != 0 )
return TRUE;
m_uTimer = ::SetTimer( pWnd->m_hWnd, IDS_TIMER_MOUSE_EVENT, 10, NULL );
if( m_uTimer )
{
m_hWnd = pWnd->m_hWnd;
::SendMessage( pWnd->m_hWnd, UWM_MOUSE_ENTER, 0, 0 );
}
return m_uTimer != 0 ? TRUE : FALSE ;
}
BOOL CMouseEvent::OnTimer(CWnd *pWnd )
{
CPoint pt;
::GetCursorPos( &pt );
if( pWnd != CWnd::WindowFromPoint( pt ) )
{
::KillTimer( pWnd->m_hWnd, m_uTimer );
m_uTimer = 0;
m_hWnd = NULL;
}
return TRUE;
}
|
|
|
|
|
In a thread that i've created with CreateThread i create a window. But when that thread returns the window closes, why? and how can i prevent it?
thanks
|
|
|
|
|
Windows belong to the thread where they are created. You cannot do anything to change this. If you want your window to be more long-lived than the thread, you have not other option but to delegate the creation of the window to another thread (preferrably the app main thread). If you take this approach, take into account all communication between the secondary thread and the windows must be done using SendMessage /PostMessage .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
hmm, so i could just instead of createing the window, use SendMessage to my main app and handle that message and create window there... good thinking!
|
|
|
|
|
Yes, that's a solution.
One more word of caution: If your secondary thread engages in blocking calls to the main thread with SendMessage , a possibility of dead-lock exists --imagine the main thread signals the sec. thread to finish and is waiting for it to die, while the sec. thread is hopelessly waiting for the main thread to anwser to its SendMessage . To prevent this situation, use SendMessageTimeout when calling from the secondary thread to the main one.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
hello @all,
is there a possibility to make a table (invisible) inside a combobox??
mfc
|
|
|
|
|
Running this inside a worker thread causes my app to crash..
CSocket sSocket;
sSocket.Create(); <-- causes the crash..
any ideas why?
|
|
|
|
|
CSocket needs to live inside a thread which has a message pump, like the main thread or (alternatively) UI threads. Worker threads, by definition, do not have such pump.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Anybody knows how solve this problem ?
When I use CListCtrl::DeleteColumn() function to delete the column with index zero (first column), it remove only the header from this column, but the items go to column one (it remove the itens from the last column).
[]'s
Cris.
|
|
|
|
|
Interesting. One alternative is to delete the items in that column manually because calling DeleteColumn().
Kuphryn
|
|
|
|
|
Deleting the items of a column ? Which function ? Could you explain me ?
Thanks,
Cris.
|
|
|
|
|
For example, set all items in the column you want to delete to "" and then call DeleteColumn().
Kuphryn
|
|
|
|
|
it doesn't work too ...
Thanks for your help but, should be a way to make this ...
[]'s
Cris.
|
|
|
|
|
Here's what the MSDN's LVM_DELETECOLUMN documentation says:
"Column zero of the list-view control cannot be deleted. If you must delete column zero, insert a zero length dummy column zero and delete column one and above."
Chris Richardson
|
|
|
|
|
Ok, and how can I remove the zero length dummy column ?
Which version of MSDN you met this ? And where exatly you found it (which keyword) ?
Thanks,
Cris.
|
|
|
|
|
I guess I'm not sure how to remove the zero length dummy column. I am using the October 2001 MSDN, the keyword I typed in the index was LVN_DELETECOLUMN.
Chris Richardson
|
|
|
|
|
Can someone tell me what windows message is sent when you right-mouse click on the title bar (or left mouse click on the small icon) of a dialog based window application?
I need to add a menu item to the "Close" and "Move" menu items.
Here's what I have so far:
CMenu *pSystemMenu = (CMenu *)GetSystemMenu(FALSE);
pSystemMenu->AppendMenu (MF_STRING, ID_MY_MENU_ITEM, _T("My menu item"));
I put that code in OnInitDialog() message handler. So the item shows up but of course nothing happens when I click it.
So in a Doc/View arch. application, the message is WM_SYSCOMMAND but I can't find this type of message in a Dialog based application.
-steve
Manufacturing Software Developer
Hewlett-Packard Company
|
|
|
|
|
You've got to define a handler for ID_MY_MENU_ITEM . Check the docs for the ON_COMMAND macro.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Excellent! That's it! I appreciate the feedback.
Manufacturing Software Developer
Hewlett-Packard Company
|
|
|
|
|
Hello All, I am having some problems trying to learn the basics of FTP'ing a file (uploading and downloading). I have read most of the information on this website and even found some postings that helped but I am still having some problems. I was hoping some of the brainiacs out there could help. This is what I am trying to do: I want to open the FTP session, upload a file, close the session. Then, periodically, I want to open the session, see if there are any files to be downloaded, if there are download the file(s) and close the session. I found a posting that said to use CFtpConnection and so that is what I am trying to do.
I am using the CFtpConnection class, so to open the session I use GetFtpConnection. I pass in the server name, user name, password, then use INTERNET_DEFAULT_FTP_PORT.
Upon trying to upload the file, I am using the PutFile. I use the CFileFind class to get the filename. I then call PutFile with the remote file (it is on the network), the local file, FTP_TRANSFER_TYPE_BINARY, and then 1. This function is failing.
Upon trying to download the file, I am using the GetFile. I pass it the remote file, the local file, FALSE for the BFailIfExists, FTP_TRANSFER_TYPE_BINARY, and then 1. This function is failing.
Then I have the closing of the connection after the upload or download functions,
m_Session.Close();
m_pFtpConnection->Close();
if(m_pFtpConnection!=NULL)
delete m_pFtpConnection;
if(m_Session!=NULL)
delete m_Session;
Another problem I have is that this is all being done inside another application. I open the session, upload the file, then close the session. When I go to open the session again, it gives me "the handle is invalid" message. Can anyone help!!!
|
|
|
|
|
using CloseHandle on the handle returned by CreateThread doesen't work, how do i do it?
thanks
|
|
|
|
|
just return from the thread, or use ExitThread,
to communicate with the thread see events pr semaphores
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
how is it i communicate with the thread? events pr semaphores?
thanks
|
|
|
|
|
The best way is to provide a mechanism inside of your newly created thread that will accept a message to shut itself down. That is the only way to insure that all of the resources have been properly released by the new thread.
However in an emergency you can use the ::TerminateThread API function to "kill" the thread from another thread.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
I have been writing an app that uses a contextual dialog bar which displays information pertaining to the type of object represented by the active view in an MDI MFC app.
When the user selects a new view I need to know what view has been selected in order to change the dialog information. When the user closes a view but another is available I need to know what view has been selected automatically (again). When the user has closed the last view I need to close the dialog bar all together.
This sounded easy but I have tried all manner of messages - WM_ACTIVATE, WM_SHOWWINDOW, WM_KILLFOCUS, WM_SETFOCUS... Everytime I think I have it a message will not come through when I expect it and everything falls apart.
Is there an easy way to know this information?
thanks
kirk
|
|
|
|