Question about console and windows programming

This is a discussion on Question about console and windows programming within the Windows Programming forums, part of the Platform Specific Boards category; I might sound like an idiot to you guys, but why does the following code only work in a DOS ...

  1. #1
    Unregistered
    Guest

    Question about console and windows programming

    I might sound like an idiot to you guys, but why does the following code only work in a DOS window and not in a regular Windows window?:

    #include <iostream.h>
    void main()
    {
    cout<<"Hello";
    }

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    cout sends output to the standard output stream......without a console, you cant see it

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    24
    A console windows program is almost like a MS-DOS Program.
    In order to create a Window, you need the following code, just to
    make a basic window.#include <windows.h>


    #include <windows.h>

    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
    /* Make the class name into a global variable */
    char szClassName[ ] = "WindowsApp";
    int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)

    {
    HWND hwnd; /* This is the handle for our window */
    MSG messages; /* Here messages to the application are saved */
    WNDCLASSEX wincl; /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
    wincl.style = CS_DBLCLKS; /* Catch 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 */
    wincl.cbClsExtra = 0; /* No extra bytes after the window class */
    wincl.cbWndExtra = 0; /* structure or the window instance */
    /* Use light-gray as the background of the window */
    wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);

    /* Register the window class, if fail quit the program */
    if(!RegisterClassEx(&wincl)) return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx(
    0, /* Extended possibilites for variation */
    szClassName, /* Classname */
    "Windows App", /* Title Text */
    WS_OVERLAPPEDWINDOW, /* default window */
    CW_USEDEFAULT, /* Windows decides the position */
    CW_USEDEFAULT, /* where the window ends up on the screen */
    544, /* The programs width */
    375, /* and height in pixels */
    HWND_DESKTOP, /* The window is a child-window to desktop */
    NULL, /* No menu */
    hThisInstance, /* Program Instance handler */
    NULL /* No Window Creation data */
    );

    /* Make the window visible on the screen */
    ShowWindow(hwnd, nFunsterStil);
    /* Run the message loop. It will run until GetMessage( ) returns 0 */
    while(GetMessage(&messages, NULL, 0, 0))
    {
    /* Translate virtual-key messages into character messages */
    TranslateMessage(&messages);
    /* Send message to WindowProcedure */
    DispatchMessage(&messages);
    }

    /* The program return-value is 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_DESTROY:
    PostQuitMessage(0); /* send a WM_QUIT to the message queue */
    break;
    default: /* for messages that we don't deal with */
    return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
    }


    This code was taken directly from bloodshed C++ Default Template for Windows APP.


    Hope this helps you out.
    Keep smiling, it makes the big guys wonder what you're up to.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Console C++ to full Windows
    By foxon177 in forum Windows Programming
    Replies: 5
    Last Post: 05-12-2008, 09:37 PM
  2. console screen (Windows)
    By hakan in forum C++ Programming
    Replies: 1
    Last Post: 03-12-2008, 06:35 AM
  3. Windows apps verses Console apps
    By nano78 in forum Windows Programming
    Replies: 8
    Last Post: 09-22-2007, 03:41 AM
  4. Windows Console!
    By Perica in forum Windows Programming
    Replies: 15
    Last Post: 10-18-2002, 08:08 PM
  5. Newbie Question -> Is Console programming different from Windows ?
    By Unregistered in forum Windows Programming
    Replies: 6
    Last Post: 04-16-2002, 08:50 PM

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