creating an application

This is a discussion on creating an application within the C++ Programming forums, part of the General Programming Boards category; I've been programming in C++ for a little while now, creating projects in this manner: Using Visual Studio 2005: Creating ...

  1. #1
    Registered User Cpro's Avatar
    Join Date
    Oct 2006
    Posts
    149

    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
    Application Settings
    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
    Code:
    #include <windows.h>
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
     	
    	MessageBox(NULL, "\tHello World!", "My first windows app", NULL);
    	return 0;
    }
    
    //http://www.cprogramming.com/tutorial/opengl_windows_programming.html
    And I get this error:
    Code:
    Error	1	error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
    Since I've never coded like this before, I am not able to figure out the problem.

    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.
    IDE - Visual Studio 2005
    Windows XP Pro

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    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.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    something like
    Code:
    MessageBox(NULL, TEXT("\tHello World!"), TEXT("My first windows app"), NULL);
    may help...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,555
    You need to make sure ALL your string constants passed to Win32 API functions are written as
    Code:
    MessageBox(NULL, T("\tHello World!"), TEXT("My first windows app"), NULL);
    The T/TEXT macro may have a leading underscore, I can't remember at the moment.

    Edit: Vart beat me to it
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by Salem View Post
    The T/TEXT macro may have a leading underscore, I can't remember at the moment.

    Edit: Vart beat me to it


    I think it is _T not just T...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Also, PCH is completely optional. Your program would function just fine without it.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    But it speeds up compilation, especially with the monolith Windows.h
    Last edited by Elysia; 05-29-2008 at 01:17 AM.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Have you profiled it and determined it to be a bottleneck?

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    I wonder what the numbers are...

    How long it takes to compile.
    How many source files Cpro has.

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    I run Linux.

  14. #14
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by Elysia View Post
    But it speeds up complication, especially with the monolith Windows.h
    I just noticed what you said. And I agree with you. It does speed up complications.

    Apologies.

  15. #15
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by robwhit View Post
    I run Linux.
    GCC supports PCHs since 3.4.


    But, windows.h taking long? It's an extremely straight-forward C header. Big, yeah, but quick to parse.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Creating a Dialog Based Application without MFC
    By MitchellH in forum C++ Programming
    Replies: 8
    Last Post: 05-21-2005, 10:02 AM
  3. MFC run application by clicking on file...
    By dug in forum Windows Programming
    Replies: 4
    Last Post: 12-02-2004, 03:33 AM
  4. Creating a Stand-Alone Application
    By QtApprentice in forum C++ Programming
    Replies: 4
    Last Post: 11-03-2003, 12:33 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21