Creating a Windows Form

All tutorials created in C++ to be posted in here.
11 posts Page 1 of 2
Contributors
User avatar
RyanTheCoder
New Member
New Member
Posts: 14
Joined: Sun Jul 04, 2010 1:38 pm

Creating a Windows Form
RyanTheCoder
This shows you how to make a basic windows form in C++ through code
Code: Select all
#include <windows.h>

/*  Declare Windows a  procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  put class name into a global variable  */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* handle for our window */
    MSG messages;            /* 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;      /* function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* recognize double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* use your 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 */
    /* windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

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

    /* class is registered, let's create a 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;
}
Last edited by RyanTheCoder on Mon Feb 21, 2011 12:07 am, edited 1 time in total.
-RyanTheCoder-
-OMG It's a Blog!-
-The Mother Site-
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: Creating a Windows Form
Axel
Doesn't VC++ Have this as default when you load a win32 project ?
http://vagex.com/?ref=25000
User avatar
RyanTheCoder
New Member
New Member
Posts: 14
Joined: Sun Jul 04, 2010 1:38 pm

Re: Creating a Windows Form
RyanTheCoder
Axel wrote:
Doesn't VC++ Have this as default when you load a win32 project ?
i dont use VC, i dont even know what it stands for, second, i code in notepad and debug it myself
-RyanTheCoder-
-OMG It's a Blog!-
-The Mother Site-
User avatar
RyanTheCoder
New Member
New Member
Posts: 14
Joined: Sun Jul 04, 2010 1:38 pm

Re: Creating a Windows Form
RyanTheCoder
RyanTheCoder wrote:
Axel wrote:
Doesn't VC++ Have this as default when you load a win32 project ?
i dont use VC, i dont even know what it stands for, second, i code in notepad and debug it myself
just realised that VC stands for Visual C, :|
-RyanTheCoder-
-OMG It's a Blog!-
-The Mother Site-
User avatar
Snyper345
VIP - Donator
VIP - Donator
Posts: 471
Joined: Mon Nov 01, 2010 1:53 am

Re: Creating a Windows Form
Snyper345
Most program other than Visual Studio C++ require you to make the form from scratch
Image
Image
User avatar
RyanTheCoder
New Member
New Member
Posts: 14
Joined: Sun Jul 04, 2010 1:38 pm

Re: Creating a Windows Form
RyanTheCoder
Snyper345 wrote:
Most program other than Visual Studio C++ require you to make the form from scratch
thus this code is here
-RyanTheCoder-
-OMG It's a Blog!-
-The Mother Site-
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: Creating a Windows Form
Axel
I know I was just wondering if Visual C++ have got this by default lol
http://vagex.com/?ref=25000
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Re: Creating a Windows Form
GoodGuy17
You should give credits to http://www.daniweb.com/code/snippet216375.html, because it looks like that is where you got this code. My mistake if you didn't get it there.
User avatar
RyanTheCoder
New Member
New Member
Posts: 14
Joined: Sun Jul 04, 2010 1:38 pm

Re: Creating a Windows Form
RyanTheCoder
GoodGuy17 wrote:
You should give credits to http://www.daniweb.com/code/snippet216375.html, because it looks like that is where you got this code. My mistake if you didn't get it there.
actually no. my dads a programmer, my moms a programmer, and i like to program. i didn't get it from any websites, sorry.
-RyanTheCoder-
-OMG It's a Blog!-
-The Mother Site-
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1891
Joined: Wed Dec 16, 2009 9:56 pm

Re: Creating a Windows Form
zachman61
RyanTheCoder wrote:
GoodGuy17 wrote:
You should give credits to http://www.daniweb.com/code/snippet216375.html, because it looks like that is where you got this code. My mistake if you didn't get it there.
actually no. my dads a programmer, my moms a programmer, and i like to program. i didn't get it from any websites, sorry.
I think your lying, and this looks extremely close to it if not it exactly
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
11 posts Page 1 of 2
Return to “C++ Tutorials”