- #1
NoodleDurh
- 23
- 0
What is wrong with the code? I can't figure it out, it works in dev c++ but windows visual studios doesn't work :(
here are the erros:
1>Windowed Application.cpp
1>c:\users\noodle\documents\visual studio 2008\projects\windowed application\windowed application\windowed application.cpp(22) : error C2440: '=' : cannot convert from 'char' to 'LPCWSTR'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\noodle\documents\visual studio 2008\projects\windowed application\windowed application\windowed application.cpp(56) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'char [12]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\noodle\documents\visual studio 2008\projects\windowed application\windowed application\windowed application.cpp(82) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\noodle\documents\visual studio 2008\projects\windowed application\windowed application\windowed application.cpp(83) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\noodle\documents\visual studio 2008\projects\windowed application\windowed application\windowed application.cpp(84) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\noodle\documents\visual studio 2008\projects\windowed application\windowed application\windowed application.cpp(97) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [17]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\Users\Noodle\Documents\Visual Studio 2008\Projects\Windowed Application\Windowed Application\Debug\BuildLog.htm"
1>Windowed Application - 6 error(s), 0 warning(s)
Code:
#include <windows.h>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
/*Declares Window Procedure*/
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM,LPARAM);
HWND Textfield,Button;
char szClassName [] = "Windows App";
int WINAPI WinMain(HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nCmdShow)
{
HWND hwnd; /*This is the handle for our window*/
MSG messages; /*Here messages to the application are saved*/
WNDCLASSEX wincl; /*Data structures for windowclass*/
/*Window Structure*/
wincl.hInstance = hThisInstance;
wincl.lpszClassName = *szClassName;
wincl.lpfnWndProc = WindowProcedure; /*This Function is called by Windowss*/
wincl.style = CS_DBLCLKS; /*Catches Double Clicks*/
wincl.cbSize = sizeof(WNDCLASSEX);
/*Use default icon and mouse-pointer*/
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /*No Menu Name*/
wincl.cbClsExtra = 0; /*No Extrea bytes after he window class*/
wincl.cbWndExtra = 0;/*Structure or the window instance*/
/*Use of Window's Default colour as the background of the window*/
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/*Register the window class,and if it fails quit the program*/
if(!RegisterClassEx(&wincl))
{return 0;}
hwnd = CreateWindowEx
(
0, /*Extended possibilities fo variation*/
szClassName, /*Classname*/
"App", /*Title txt*/
WS_OVERLAPPEDWINDOW, /*default Window can resize*/
CW_USEDEFAULT, /*Windows Decides the position*/
CW_USEDEFAULT,/*Where the window ends up in the screen*/
544, /*the programs Width*/
375, /*Programs hight in pixels*/
HWND_DESKTOP,/*the window is a child-window to desktop*/
NULL, /*No menu*/
hThisInstance,/*Program Instancehandler*/
NULL/*No Window Creation data*/
);
/*Make the window visible on screen*/
ShowWindow (hwnd, nCmdShow);
/*Run the message loop. It wil run until GetMessage() returns 0*/
while (GetMessage(&messages,NULL,0,0))
{
/*Translates virtural-Key messages into character messages*/
TranslateMessage(&messages);
/*Sends message to WindowProcedure*/
DispatchMessage(&messages);
}
/*Returns value of 0, the Value that PostQuitMessage() gave*/
return messages.wParam;
}
/*This function is called by the Windows Function DispatchMessage()*/
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)
{
switch (message) /*handle the messages*/
{
case WM_CREATE:
Textfield = CreateWindow("EDIT","Hello World",WS_VISIBLE| WS_CHILD|WS_BORDER,20 , 20, 300,25,hwnd, NULL, NULL, NULL);
Button = CreateWindow ("Button","Yes", WS_VISIBLE|WS_CHILD |WS_BORDER, 120,120,100,20 , hwnd, (HMENU) 1,NULL, NULL);
Button = CreateWindow ("Button","No", WS_VISIBLE|WS_CHILD |WS_BORDER, 280,120,100,20 , hwnd, (HMENU) 2,NULL, NULL);
break;
case WM_DESTROY:
PostQuitMessage(0); /*Send a WM_QUIT to the message queue*/
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case 1:
cout << " Awesome Job! \0 \n \a";
break;
case 2:
::MessageBox(hwnd, "You Are Now Dead","You Pushed My Buttons",MB_OK);
::MessageBeep(MB_ICONERROR);
PostQuitMessage(0);
break;
}
break;
default: /*for messages that we don't deal with*/
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
here are the erros:
1>Windowed Application.cpp
1>c:\users\noodle\documents\visual studio 2008\projects\windowed application\windowed application\windowed application.cpp(22) : error C2440: '=' : cannot convert from 'char' to 'LPCWSTR'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\noodle\documents\visual studio 2008\projects\windowed application\windowed application\windowed application.cpp(56) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'char [12]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\noodle\documents\visual studio 2008\projects\windowed application\windowed application\windowed application.cpp(82) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\noodle\documents\visual studio 2008\projects\windowed application\windowed application\windowed application.cpp(83) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\noodle\documents\visual studio 2008\projects\windowed application\windowed application\windowed application.cpp(84) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\noodle\documents\visual studio 2008\projects\windowed application\windowed application\windowed application.cpp(97) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [17]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\Users\Noodle\Documents\Visual Studio 2008\Projects\Windowed Application\Windowed Application\Debug\BuildLog.htm"
1>Windowed Application - 6 error(s), 0 warning(s)