|
See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi,
I have 2 threads that for some reason lock up and I can't figure out why. Maybe if someone could look at some of my code they can see something obviously wrong:
<br />
UINT CChildView::CaptureThread()<br />
{<br />
bool ShutterChanged = false;<br />
int saveShutter;<br />
while(!m_bTerminateThread)<br />
{<br />
if (m_bCapturePaused)<br />
{<br />
::SetEvent(m_hCapturePausedConfirm);<br />
switch(::WaitForSingleObject(m_hCaptureEvent, 5000))<br />
{<br />
case WAIT_OBJECT_0:<br />
break;
case WAIT_TIMEOUT:<br />
continue;
}<br />
}<br />
...rest of the thread<br />
Note that inside this thread I use an object which implements CCriticalSection object that I lock and unlock for each function. Both the GUI thread and this thread calls functions on this object.<br />
}<br />
Furthermore I define:<br />
inline void StartCapture()<br />
{<br />
m_bCapturePaused = FALSE;<br />
::SetEvent(m_hCaptureEvent);<br />
::ResetEvent(m_hCapturePausedConfirm);<br />
}<br />
inline void PauseCapture()<br />
{<br />
m_bCapturePaused = TRUE;<br />
::ResetEvent(m_hCaptureEvent);<br />
::WaitForSingleObject(m_hCapturePausedConfirm, INFINITE);<br />
}<br />
The problem is in the main program when the user clicks a button I want to pause the thread. The deadlock doesn't occur always. Also any runs through the debugger work, so I don't know how to solve this problem.
Thanks.
|
|
|
|
|
First, I finally found how to debug multiple threads in VC++ 6. Run in debug mode, click pause, click Debug->Threads. After I did that I immediately saw the thread executing a line CComboBox::GetCurSel(). I thought I didn't have any more GUI modification within a thread but I guess I do. I think the problem is now fixed. I guess people aren't kidding when they say don't modify the GUI from a thread.
|
|
|
|
|
I guess people aren't kidding when they say don't modify the GUI from a thread.
Don't modify the MFC GUI from a thread that did not create the MFC object - you can modify any of them from the same thread that created them, of course.
|
|
|
|
|
I need to develop a little application to send some keystrokes to the active window, something like the On Screen Keyboard. I need to know what is the window that lose the keyboard focus when the user click on a button in my application so I tried to gain a hook (a thread hook, not a global hook) so I wrote the following routine as CBT event handler:
<br />
LRESULT CALLBACK<br />
CMainFrame::CBTProc(int nCode, WPARAM wParam, LPARAM lParam)<br />
{<br />
LRESULT nResult;<br />
<br />
if (nCode == HCBT_SETFOCUS)<br />
{<br />
m_hGaining = (HWND) wParam;<br />
m_hLosing = (HWND) lParam;<br />
<br />
TRACE1("HWND Gaining: %x\n", m_hGainingFocusWnd);<br />
TRACE1("HWND Losing: %x\n", m_hLosingFocusWnd);<br />
}<br />
<br />
nResult = CallNextHookEx(m_hHook, nCode, wParam, lParam);<br />
<br />
return nResult;<br />
}<br />
The problem is that when I switch (using mouse or Alt+Tab) between my application and another one such as Notepad I got this behaviour:
Switching from Notepad to my application:
HWND Gaining: 0x50558 (the handle of my application window)
HWND Losing: 0 (NULL)
Switching from my application to Notepad:
the hook procedure don't trap anything at all
What's wrong? Why I get NULL in the first case and I don't trap nothing in the second one?
Thanks
Gaetano Sferra
|
|
|
|
|
In a call to SetWindowsHookEx(), set the last parameter as '0' This would associate hook with all the existing threads.
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Nilesh K. wrote:
In a call to SetWindowsHookEx(), set the last parameter as '0' This would associate hook with all the existing threads.
Looking into the MSDN, in the SetWindowsHookEx explaination I see the following:
lpfn
[in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
If I set the last parameter of the SetWindowsHookEx() (dwThradId) to 0 I cannot provide a pointer to an hook procedure that reside in the my application process as shown in my previous post, I shoud build a DLL.
My questions are:
Can I obtain a handle to the window losing the keyboard focus without use a global hook (a hook procedure in a DLL)?
Why when my application window lose the ketyboard focus the hook procedure isn't called? (It should trap a CBT event with the lParam set to the handle to my application window)
Why when my application window gain the keyboard focus I got NULL as handle to the window losing the keyboard focus? (I should get the correct handle because the CBT event destination is the my application process)
If my interpretation of MSDN or my deductions are wrong, please correct me.
Thanks
Gaetano Sferra
|
|
|
|
|
I doubt it would be possible without global hook procedure.
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Thank you Nilesh,
I will begin a DLL development to handle it.
Gaetano Sferra
|
|
|
|
|
inline float FastCosF(float value)<br />
{<br />
#ifdef Im_In_VisualStudio<br />
<br />
__asm<br />
{<br />
fld value;<br />
fcos;<br />
fstp value;<br />
}<br />
<br />
#else //in GNU compiler<br />
<br />
<br />
#endif<br />
<br />
return value;<br />
}<br />
Through googling i got this: asm ("fsin" : "=t" (value) : "0" (value));
but i don't think it works
|
|
|
|
|
which CPU are you targeting?
i think the author of that bit is assuming anyone using Visual Studio compiler is going to be making EXEs for use on Pentium (and compatible) processors. but since gcc is used on many different architectures, not just Pentiums, you can't make the same assumption - and you'll have to pick a processor(s) to write for.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Hmm i didn't consider that...shows how much i know about asm. Looks like for sake of multiplatform im just gonna have to use the built in math functions.
|
|
|
|
|
Please help me in writing a code to know whether a webcam is attached to any USB port or not? This is very urgent
Thanking you
anukampa
|
|
|
|
|
The easiest way would probably be to use the driver for that device to check it's status.
Elaine
The tigress is here
|
|
|
|
|
If the webcam has a valid driver installed you just
need to enumerate connected video devices and look
for a "friendlyname" that matches that of your webcam.
Look at AMCAP source code (in the DirectShow SDK samples)
for details of how to do that. AMCAP enumerates all
connected video devices and lists their "friendlyname"s
in a menu from which the user can select one.
Steve T
|
|
|
|
|
I need to know the Combobox selection that was before the user changed the selection.
If I use
OnChangeCbXXX() {<br />
int selection = m_cbXXX.GetCurSel()<br />
}
then selection holds the new value. How to get the value before the change???
|
|
|
|
|
Just create another member variable that defaults to -1. On the CBN_SELCHANGE handler, do something like:
OnChangeCbXXX()
{
int selection = m_cbXXX.GetCurSel();
TRACE("Previous selection = %d\n", m_prevsel);
TRACE(" Current selection = %d\n", selection);
m_prevsel = selection;
}
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
How can I find out opened files on LAN ? I would like to use it in my app. I mean this Computer management->System tools->Shared folders->Open files
|
|
|
|
|
See here and here for possibilities.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I have a window with a standard title bar (or caption bar) with the standard trio of Minimize, Max/Restore, and Close(SYSMENU) pushbuttons. Specifically, I have this window start maximized by sending myself a WM_SIZE message or by using the WS_MAXIMIZE style on creation. It looks great, but it isn't maximized. It can be moved by dragging the title bar, and I want the maximize button to be the restore button. More generally, I would like to know more about how to interact with a windows default title bar. I am not currently using MFCs in an effort to better understand the effort required to program for windows without MFCs. Any references to better references on the subject of title bar "maintenance" are also helpful.
|
|
|
|
|
Hi all!
How could I stop flickering in a list view control?
|
|
|
|
|
I assume the flickering is happening while items are being added to the control. If so, try calling SetRedraw(FALSE) beforehand.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
No!, it's happening when I resize the window.
|
|
|
|
|
Hello people,
I'm having a very weird problem at the moment and I can't figure it out. Here's the situation;
- I have a normal dialog (CDialog class) with a groupbox on it.
- Inside the groupbox, I create a CPropertySheet like this:
CWnd* pWnd = GetDlgItem(IDC_ST_TAB);
m_propSheet.Create(pWnd, WS_CHILD | WS_VISIBLE);
m_propSheet.SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
where IDC_ST_TAB is the ID of the groupbox and m_propSheet is a CPropertySheet object.
- Before I call create, I add several pages. All pages show fine.
- On one of the pages contains a custom listbox, this listbox has a popup menu on right click. The popup menu shows fine.
- When an item in the popup menu is clicked, it SHOULD pop up another dialog (again a CDialog class). It does seem to load the dialog, but never shows it! It hangs on DoModal().
Now here's the weird thing; when I change the m_propSheet.Create to say WS_POPUP or just nothing instead of WS_CHILD, I get a floating property sheet and then the dialogs DO pop up properly...
What am I missing here? All property sheets are also set as child in the resource (but I don't think it matters).
|
|
|
|
|
I have used a "Forms 2.0 ActiveX control" in my first piece of software created with VC++ 6.0. Unfortunalty my software will not run on a system unless MS Office is installed. What have I done wrong!!!
Can I include the nessesary files in my application to make my software run on a system without MS Office.
Thanxs
|
|
|
|