Creating a Windows Form
All tutorials created in C++ to be posted in here.
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.
Doesn't VC++ Have this as default when you load a win32 project ?
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 wrote:just realised that VC stands for Visual C, :|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
Most program other than Visual Studio C++ require you to make the form from scratch
Snyper345 wrote:Most program other than Visual Studio C++ require you to make the form from scratchthus this code is here
I know I was just wondering if Visual C++ have got this by default lol
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.
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 wrote:I think your lying, and this looks extremely close to it if not it exactlyGoodGuy17 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.
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

Copyright Information
Copyright © Codenstuff.com 2020 - 2023