1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#include <windows.h>
#define FirstChild 100 //child window
HINSTANCE handle; //handle associated with a window
HWND mainWIN; //handle to the main window
//prototype
long APIENTRY Windows_Procedure (HWND , UINT , WPARAM , LPARAM );
bool registering_class (HINSTANCE handle_to_win_procedure)
{
WNDCLASSEX mynewclass; //declaring structure object
mynewclass.cbSize = sizeof (mynewclass); //giving the size of class
mynewclass.style = CS_HREDRAW | CS_VREDRAW; //specifying class styles
mynewclass.Windows_Procedure; //passing pointer of windows procedure
mynewclass.cbClsExtra = 0; //no extra bytes for allocating the window class structure
mynewclass.cbWndExtra = 0; //no extra bytes for the windows instance
mynewclass.handle_to_win_procedure; //specifying the handle to the windows procedure
mynewclass.hIcon = NULL; //if this is null, then application will load a default icon
mynewclass.hCursor = LoadCursor (NULL, IDC_CROSS) //specifying the image of the mouse cursor
mynewclass.hbrBackground = GetStockObject (WHITE_BRUSH) //setting the background of client to a white shade
mynewclass.lpszMenuName = "Main Menu"; //specifying the name of window menu
mynewclass.lpszClassName = "Main Class"; //specifying the name of the window class
mynewclass.hIconSm = NULL;
RegisterClassEx (&mynewclass);
}
//creating main windows
mainWIN = CreateWindowEX (
0, //No extended styles
"Main Class", //The name of the window class
"My Awesome Window", //the name of the window itself
WS_OVERLAPPEDWINDOW | //Style of the window
WS_HSCROLL | WS_VSCROLL,
CW_USEDEFAULT, //default horizontal position
CW_USEDEFAULT, //default vertical position
CW_USEDEFAULT, //default width
CW_USEDEFAULT, //default height
(HWND) NULL, //no parent of owner window
(HMENU) NULL, //use window menu
hinstance, //instance handle
null); //no window creation data
if (!mainWIN) //checking to see if theres any problems with handle to main window
return false;
ShowWindow (mainWIN, SW_SHOWMAXIMIZED); //displays the window
UpdateWindow (mainWIN); //updates window and sends a WS_PAINT message to paint the application
long APIENTRY Windows_Procedure (HWND handle1, UINT message, WPARAM w, LPARAM l)
{
RECT coordinates_of_client;
switch (message) //message will contain an integer value
{
case WM_CREATE:
CreateWindowEX //creating child window
(
0, //no extended styles
"Main Class", //name of child window class
(LPCTSTR) NULL, //child window will not have a name
WS_CHILD | WS_BORDER, //specifying the style of the window
0,0,0,0, //no scrolls or height or width on child window
handle1, //specifying parent window for this child window
(HMENU) (int) (FirstChild) //menu for child window
NULL //no windows creation data
);
return 0;
case WM_SIZE:
GetClientRect (handle1, &coordinates_of_client);
EnumChildWindows (handle1, EnumChildProc, (LPARAM)& coordinates_of_client);
return 0;
}
ShowWindow (handle1, SW_SHOW);
return DefWindowProc (handle1, message, w,l)
}
|