I'm just starting out in C++ and want to use TextOut to print a character that is generated at runtime based on keyboard input but am having trouble converting TCHAR to LPCWSTR so that it can be used in the TextOut method.
my code is

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	int kbrdId, kbrdEvent;
	TCHAR chCharCode;
        int lKeyData;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: Add any drawing code here...
		EndPaint(hWnd, &ps);
		break;
	case WM_CHAR:
		{
			chCharCode = (TCHAR) wParam;
			lKeyData = lParam;
			kbrdId    = LOWORD(wParam);
			kbrdEvent = HIWORD(wParam);
			TCHAR s (32);
			HDC hdc = GetDC(hWnd);
			TextOut (hdc, 40,40, chCharCode, 1);
		}
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

I want to print any character that is pressed on the keyboard on the screen.
please don't suggest printf because it this is a GUI not a console app.
thanks

LPCWSTR is a pointer to TCHAR so just use the & address operator to make the conversion
TextOut (hdc, 40,40,&chCharCode, 1);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.