creating an application
I've been programming in C++ for a little while now, creating projects in this manner:
Using Visual Studio 2005:
Creating a new project
Under Visual C++ - going to Win32
Win32 Console Application
Checking Empty Project
Currently, when I code like this and compile, an executable will be created, and I can run my program by opening it. This was the only way I was taught.
However, now I would like to make an actual application with a window (not the dos-like window that the executable uses), buttons, and space for input and output. I have a few questions.
1) Would I still create the project like I did above? If differently, how?
2) I created a project like i did above, and copied and pasted some code from the tutorial
And I get this error:
int APIENTRY WinMain(HINSTANCE hInstance,
MessageBox(NULL, "\tHello World!", "My first windows app", NULL);
Since I've never coded like this before, I am not able to figure out the problem.
Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char ' to 'LPCWSTR'
Basically, I want to take some of my C++ programs that I've created (using the method at the top) and make them have actual windows, buttons, and space for input and output.
I am learning this on my own (following online tutorials), and any help would be greatly appreciated.
Also, I wasn't sure if i should post this here, or in the Windows Programming section.
I do believe it's something to do with UNICODE?
You need to make sure you open the new project as a Windows App not a console app.
MessageBox(NULL, TEXT("\tHello World!"), TEXT("My first windows app"), NULL);
You need to make sure ALL your string constants passed to Win32 API functions are written as
The T/TEXT macro may have a leading underscore, I can't remember at the moment.
MessageBox(NULL, T("\tHello World!"), TEXT("My first windows app"), NULL);
Edit: Vart beat me to it :)
Originally Posted by Salem
I think it is _T not just T...
Yeah, it's _T. Also replace char with TCHAR.
And for Windows projects, I really do suggest the use of PCH. Just do as you do, but don't click empty project. Select windows app instead.
Put Windows.h in stdafx.h (and don't forget to put #include "stdafx.h") in all source files.
Also, PCH is completely optional. Your program would function just fine without it.
But it speeds up compilation, especially with the monolith Windows.h ;)
Have you profiled it and determined it to be a bottleneck?
Indeed, windows.h takes a lot of time to compile (as in, not instant, as pretty much all other standard library headers are). Especially if you start inserting it into every source file.
I wonder what the numbers are...
How long it takes to compile.
How many source files Cpro has.
Don't be so anti-PCH. They are good thing™.
You will probably want to learn them sooner or later and they don't add complexity.
I just noticed what you said. And I agree with you. It does speed up complications.
Originally Posted by Elysia
GCC supports PCHs since 3.4.
Originally Posted by robwhit
But, windows.h taking long? It's an extremely straight-forward C header. Big, yeah, but quick to parse.