Hi I am creating a program in C++ using visual studios 2003, and for a project I am required to create a application. In this application for testing purposes I am outputing a number to show that a certain key was pressed. I am getting
error C2664: 'TextOutA' : cannot convert parameter 4 from 'std::string' to 'LPCSTR'
As the error.
My code is
any help would be appreciated. Thanks
error C2664: 'TextOutA' : cannot convert parameter 4 from 'std::string' to 'LPCSTR'
As the error.
My code is
Code:
/* Trim fat from windows*/
#define WIN32_LEAN_AND_MEAN
#pragma comment(linker, "/subsystem:windows")
/* Pre-processor directives*/
//#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <String>
#include <cString>
using namespace std;
/*
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
*/
/* Windows Procedure Event Handler*/
string keyin="0";
void GamePaint(HDC hDc);
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
/* Device Context*/
HDC hDC;
/* Text for display*/
/* Switch message, condition that is met will execute*/
string trst;
switch(message)
{
/* Window is being created*/
case WM_CREATE:
return 0;
break;
/* Window is closing*/
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;
/* Window needs update*/
case WM_KEYDOWN:
{
// get virtual key code and data bits
int virtual_code = (int)wParam;
int key_state = (int)lParam;
// switch on the virtual_key code to be clean
switch(virtual_code)
{
case VK_RIGHT:
{
keyin="1";
} break;
case VK_LEFT:
{
keyin="2";
} break;
case VK_UP:
{
keyin="3";
} break;
case VK_DOWN:
{
keyin="4";
} break;
// more cases...
default: break;
} // end switch
// tell windows that you processed the message
return(0);
} break;
case WM_PAINT:
hDC = BeginPaint(hwnd,&ps);
GamePaint(hDC);
/* Set txt color to blue*/
trst="Hi";
SetTextColor(hDC, RGB(0,0,255));
TextOut(hDC,150,150,(trst),2);
// TextOut(hDC,0,0,keyin,strlen(keyin));
EndPaint(hwnd, &ps);
return 0;
break;
default:
break;
}
return (DefWindowProc(hwnd,message,wParam,lParam));
}
void GamePaint(HDC hDC)
{
HPEN hBluePen = CreatePen(PS_SOLID, 2, RGB(0,0,255));
HBRUSH hPurpleBrush = CreateSolidBrush(RGB(255,0,255));
HBRUSH hRedBrush = CreateSolidBrush(RGB(255,0,0));
RECT rect={80,80,129,129};
// HPEN hPen = SelectObject(hDC, hBluePen);
// Image image(L"test.jpg");
// graphics.DrawImage(&image, 60, 10);
MoveToEx(hDC, 10,40,NULL);
LineTo(hDC, 44, 10);
LineTo(hDC, 78, 40);
SelectObject(hDC, hRedBrush);
Ellipse(hDC, 150, 150, 180, 180);
SelectObject(hDC, hBluePen);
SetTextColor(hDC, RGB(0,0,255));
Rectangle(hDC, 80, 80, 130, 130);
FillRect(hDC, &rect,hPurpleBrush);
DeleteObject(hBluePen);
}
/* Main function*/
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX windowClass; //window class
HWND hwnd; //window handle
MSG msg; //message
bool done; //flag saying when app is complete
/* Fill out the window class structure*/
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = "MyClass";
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
/* Register window class*/
if (!RegisterClassEx(&windowClass))
{
return 0;
}
/* Class registerd, so now create window*/
hwnd = CreateWindowEx(NULL, //extended style
"MyClass", //class name
"A Real Win App", //app name
WS_OVERLAPPEDWINDOW | //window style
WS_VISIBLE |
WS_SYSMENU,
100,100, //x/y coords
400,400, //width,height
NULL, //handle to parent
NULL, //handle to menu
hInstance, //application instance
NULL); //no extra parameter's
/* Check if window creation failed*/
if (!hwnd)
return 0;
done = false; //initialize loop condition variable
/* main message loop*/
while(!done)
{
PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE);
if (msg.message == WM_QUIT) //check for a quit message
{
done = true; //if found, quit app
}
else
{
/* Translate and dispatch to event queue*/
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
Comment