Click here to Skip to main content
15,909,242 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: my problem is output for this weight conversion pounds to kilogram that starts from 100 to 300. Pin
Michael Hulthin12-May-22 1:06
Michael Hulthin12-May-22 1:06 
GeneralRe: my problem is output for this weight conversion pounds to kilogram that starts from 100 to 300. Pin
Member 1563347212-May-22 1:21
Member 1563347212-May-22 1:21 
GeneralRe: my problem is output for this weight conversion pounds to kilogram that starts from 100 to 300. Pin
Member 1563347212-May-22 1:44
Member 1563347212-May-22 1:44 
GeneralRe: my problem is output for this weight conversion pounds to kilogram that starts from 100 to 300. Pin
Michael Hulthin12-May-22 1:59
Michael Hulthin12-May-22 1:59 
GeneralRe: my problem is output for this weight conversion pounds to kilogram that starts from 100 to 300. Pin
Member 1563347212-May-22 2:16
Member 1563347212-May-22 2:16 
Questionhow to capture mouse movement and click in windows service Pin
Shkuratov U11-May-22 16:57
Shkuratov U11-May-22 16:57 
AnswerRe: how to capture mouse movement and click in windows service Pin
Richard MacCutchan11-May-22 21:43
mveRichard MacCutchan11-May-22 21:43 
AnswerRe: how to capture mouse movement and click in windows service Pin
Richard Deeming11-May-22 21:44
mveRichard Deeming11-May-22 21:44 
Questionconflicting types for 'uint32_t' issue Pin
focusdoit5-May-22 3:17
focusdoit5-May-22 3:17 
AnswerRe: conflicting types for 'uint32_t' issue Pin
Richard MacCutchan5-May-22 4:02
mveRichard MacCutchan5-May-22 4:02 
AnswerRe: conflicting types for 'uint32_t' issue Pin
Randor 5-May-22 9:28
professional Randor 5-May-22 9:28 
GeneralRe: conflicting types for 'uint32_t' issue Pin
focusdoit5-May-22 14:04
focusdoit5-May-22 14:04 
GeneralRe: conflicting types for 'uint32_t' issue Pin
Randor 5-May-22 14:31
professional Randor 5-May-22 14:31 
GeneralRe: conflicting types for 'uint32_t' issue Pin
Richard MacCutchan5-May-22 22:23
mveRichard MacCutchan5-May-22 22:23 
QuestionComplier error C2280 explanation Pin
ForNow5-May-22 1:37
ForNow5-May-22 1:37 
AnswerRe: Complier error C2280 explanation Pin
CPallini5-May-22 1:59
mveCPallini5-May-22 1:59 
GeneralRe: Complier error C2280 explanation Pin
ForNow5-May-22 2:07
ForNow5-May-22 2:07 
GeneralRe: Complier error C2280 explanation Pin
CPallini5-May-22 2:10
mveCPallini5-May-22 2:10 
GeneralRe: Complier error C2280 explanation Pin
ForNow5-May-22 2:21
ForNow5-May-22 2:21 
GeneralRe: Complier error C2280 explanation Pin
CPallini5-May-22 2:34
mveCPallini5-May-22 2:34 
GeneralRe: Complier error C2280 explanation Pin
ForNow5-May-22 3:01
ForNow5-May-22 3:01 
Questioncannot Create CListBox : CFormView without IDD Pin
rtischer82774-May-22 4:04
rtischer82774-May-22 4:04 
QuestionRe: cannot Create CListBox : CFormView without IDD Pin
David Crow4-May-22 4:47
David Crow4-May-22 4:47 
QuestionWaitForSingleObject Visual C++ bug Pin
coco2431-May-22 8:35
coco2431-May-22 8:35 
Hi,

I am following an example from a book, and I have an WaitForSingleObject that works just first time and I don't know
how to resolve that.

The main things are happening in the ChildThreadProc. At the first execution of the ChildThreadProc the procedure steps through all lines of code, but when is launched again, the execution stops at WaitForSingleObject, as if hAutoEvent isn't signaled or I don't know what is happening, and please help me to figure this out.

So,
In the WindProc main procedure when the window is created, is created the Event also:

C++
case WM_CREATE:  // Make an auto-reset event with initial state of signaled
	    hAutoEvent = CreateEvent ( NULL, FALSE, TRUE, "EXAMPLE-AUTOEVENT" );
		return DefWindowProc(hWnd, message, wParam, lParam);


The example of WaitForSingleObject is presented in the following procedure:

C++
// Child thread procedure. The child waits to get event. It then sits idle
// for five seconds and sets the event again so another thread can use it.

DWORD WINAPI ChildThreadProc ( HWND hWnd )
{
	char szBuffer[256];   //work area for print formatting
	HANDLE hAutoEvent = OpenEvent( SYNCHRONIZE, FALSE, "EXAMPLE-AUTOEVENT");
	wsprintf(szBuffer, "Thread %x waiting for Event %x", GetCurrentThreadId(), hAutoEvent );
	SendMessage(hWnd, WM_USER, 0, (LPARAM)szBuffer);

	// Check that write auto reset is signaled.
	WaitForSingleObject(hAutoEvent, INFINITE );
	wsprintf(szBuffer, " Thread %x got event", GetCurrentThreadId() );
	SendMessage(hWnd, WM_USER, 0, (LPARAM)szBuffer );
	Sleep(2000);

	//Release event
	wsprintf(szBuffer, "Thread %x is dome with event", GetCurrentThreadId() );
	SendMessage(hWnd, WM_USER, 0, (LPARAM)szBuffer);
	SetEvent(hAutoEvent);
	CloseHandle( hAutoEvent);
	ExitThread( TRUE );


The ChildThreadProc is started here:

C++
case IDM_TEST:
			{
				DWORD id=0;
				CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)ChildThreadProc, hWnd, 0, &id );
			}
			break;


and here is where text out is handled:

C++
case WM_USER:
		{
			TCHAR szBuffer[101];
			static int row = 0;
			static int msg_num = 1;

			HDC hDC = GetDC(hWnd);

			FillMemory(szBuffer, 100, 32 );
			TextOut( hDC, 0, row, szBuffer, 100 );
			wsprintf(szBuffer, "%3d: %s", msg_num++, (LPSTR)lParam );
			TextOut(hDC, 0, row, szBuffer, lstrlen(szBuffer) );
            row = (row > 200 ) ? 0 : row += 20;
			ReleaseDC(hWnd,hDC);

		}
		break;


Please help me to find what I am not doing right.

Thank you,
AnswerRe: WaitForSingleObject Visual C++ bug Pin
Randor 1-May-22 10:22
professional Randor 1-May-22 10:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.