Code:
#include <windows.h>
#define TextBoxDefined 101
const char ClassName[] = "WindowClass";
// Message Queue Commands
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg) // if&else commands to follow when interpreting the current message in queue
{
case WM_CREATE:
{
HWND TextBox;
TextBox = CreateWindowEx(WS_EX_CLIENTEDGE,
"EDIT",
"Predefined Text",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
0,
0,
0,
0,
hwnd,
(HMENU)TextBoxDefined,
GetModuleHandle(NULL),
NULL);
if(TextBox == NULL)
MessageBox(hwnd, "Text Box creation failed", "Error", MB_OK | MB_ICONERROR);
HFONT hfDefault;
hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
SendMessage(TextBox, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE,0));
}
break;
case WM_SIZE:
{
HWND TextBox;
TextBox = GetDlgItem(hwnd, TextBoxDefined);
RECT FullWindow;
GetClientRect(hwnd, &FullWindow);
SetWindowPos(TextBox, //this object being our textbox
NULL, //???
0, //horizontal position from left
0, //vertical position from right
FullWindow.right, //full window horiztonal size
FullWindow.bottom, //full window vertical size
SWP_NOZORDER); //???
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY: //if message was the cancel button [x]???
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
//WinMain() instead of main()
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
//Window class
WNDCLASSEX wc;
//Window class parameters
wc.cbSize = sizeof(WNDCLASSEX); //???
wc.style = 0; //???
wc.lpfnWndProc = WndProc; //???
wc.cbClsExtra = 0; //???
wc.cbWndExtra = 0; //???
wc.hInstance = hInstance; //???
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); //Executable's desktop icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); //Cursor
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); //Window color
wc.lpszMenuName = NULL; //No menu
wc.lpszClassName = ClassName; //???
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //Window icon? , Sm = small?
if(!RegisterClassEx(&wc)) //error handling
{
MessageBox(NULL, "Registration Failure", "Error", MB_OK); //Okay button
return 0; //return fail
}
////////////////////////////////////////////////////////////////////////////
//The actual window
HWND MyParentWindow;
//The window's parameters
MyParentWindow = CreateWindowEx(
0, //Style
ClassName, //Current class name , Does this mean MyParentWindow takes on wc's characteristics via the name ClassName?
"Title", //Title
WS_OVERLAPPEDWINDOW, //minimize, maximize, close
0,//position x in pixels relative to screen
0,//position y in pixels relative to screen
500,//size x dimension in pixels
500,//size y dimension in pixels
NULL, //MyParentWindow is the parent window and it does not have a parent, thus NULL
NULL, //no menu was defined
hInstance, //???
NULL); //???
if(MyParentWindow == NULL) //error handling
{
MessageBox(NULL, "MyParentWindow Creation Failure", "Error", MB_OK); //okay button
return 0;
}
ShowWindow(MyParentWindow, nCmdShow); //show the window called "MyParentWindow"
UpdateWindow(MyParentWindow); //update the window called "MyParentWindow"
////////////////////////////////////////////////////////////////////////////
// Message loop
MSG Msg;
//GetMessage() gets a message from message queue.
while(GetMessage(&Msg, NULL, 0, 0) > 0) //while there are more than 0 messages?
{
TranslateMessage(&Msg); //current message interpreted???
DispatchMessage(&Msg); //result of current message???
}
return Msg.wParam; //return result???
}
My new question is this: