Thread: Visual Studio C++ 2005 first task "Create a window"

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    Visual Studio C++ 2005 first task "Create a window"

    I wrote the my very first Win 32 program using VC++ 2005. The code below in my guess is suppose to at least create a window when i run the program, nothing much. It compiles with no errors but nothing shows

    Code:
    // Test.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    
    #include <windows.h>
    
    
    // Step 4: the Window Procedure
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
         switch(msg)
         {
         case WM_CREATE:
    
              break;
              case WM_CLOSE:
                   DestroyWindow(hwnd);
              break;
              case WM_DESTROY:
                   PostQuitMessage(0);
              break;
              default:
                   return DefWindowProc(hwnd, msg, wParam, lParam);
         }
         return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                             LPSTR lpCmdLine, int nCmdShow)
    {
         WNDCLASSEX wc;
         HWND hwnd;
         MSG Msg;
         static char appName[] = "Your Application";
    
         //Step 1: Registering the Window Class
         wc.cbSize = sizeof(WNDCLASSEX);
         wc.style = CS_HREDRAW | CS_VREDRAW;
         wc.lpfnWndProc = WndProc;
         wc.cbClsExtra = 0;
         wc.cbWndExtra = 0;
         wc.hInstance = hInstance;
         wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
         wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
         wc.lpszMenuName = NULL;
         wc.lpszClassName = appName;
         wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    
         if(!RegisterClassEx(&wc))
         {
              MessageBox(NULL, "Window Registration Failed!", "Error!",
                   MB_ICONERROR | MB_OK);
              return 0;
         }
    
         // Step 2: Creating the Window
         hwnd = CreateWindowEx(
              WS_EX_CLIENTEDGE,
              appName,
              "Your Window Title",
              WS_OVERLAPPEDWINDOW,
              CW_USEDEFAULT, CW_USEDEFAULT, 400, 400,
              NULL, NULL, hInstance, NULL);
    
         if(hwnd == NULL)
         {
              MessageBox(NULL, "Window Creation Failed!", "Error",
                   MB_ICONERROR | MB_OK);
              return 0;
         }
    
         ShowWindow(hwnd, nCmdShow);
         UpdateWindow(hwnd);
    
         // Step 3: The Message Loop
         while(GetMessage(&Msg, NULL, 0, 0) > 0)
         {
              TranslateMessage(&Msg);
              DispatchMessage(&Msg);
         }
         return int(Msg.wParam);
    }
    Q. How do i run it after i press build (F7), forgive me i'm used to Visual Studio C++ 6.0 where there's compile+run

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Press F5 to run (and it will compile if needed too).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    Press F5 to run (and it will compile if needed too).

    --
    Mats
    thanx, good start for me! F5 called debugging??? confusing, should be RUN me thinks

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ok, "Run Without Debug" is "CTRL-F5" (from memory, I very, very, rarely use that option, as I tend to run my code from command-line if I'm not actively debugging).

    But F5 will "run under debugger", which is probably what you want most of the time when you are developing the code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM