Code:
#include <windows.h>
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
HINSTANCE hInstGlobal;
HWND hEdit;
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
HWND hWnd;
WNDCLASSEX WndClsEx;
// Create the application window
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProcedure;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = "Kazalio Studios";
WndClsEx.hInstance = hInstance;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// Register the application
RegisterClassEx(&WndClsEx);
// Create the window object
hWnd = CreateWindow("Kazalio Studios",
"KaPad",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
// Find out if the window was created
if( !hWnd ) // If the window was not created,
return 0; // stop the application
// Display the window to the user
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
// Decode and treat the messages
// as long as the application is running
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE:
HMENU hMenu;
hMenu = CreateMenu();
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_TYPE | MIIM_ID;
mii.fType = MFT_STRING;
char *string;
string = new char[40];
mii.dwTypeData = string;
mii.cch = lstrlen (string);
HMENU hMenu2;
hMenu2 = CreatePopupMenu ();
lstrcpy (string, "&New");
mii.dwTypeData = string;
mii.cch = lstrlen (string);
mii.wID = 1;
InsertMenuItem (hMenu2, 1, TRUE, &mii);
lstrcpy (string, "&Open");
mii.dwTypeData = string;
mii.cch = lstrlen (string);
mii.wID = 2;
InsertMenuItem (hMenu2, 2, TRUE, &mii);
lstrcpy (string, "&Save");
mii.dwTypeData = string;
mii.cch = lstrlen (string);
mii.wID = 2;
InsertMenuItem (hMenu2, 3, TRUE, &mii);
mii.fMask = MIIM_TYPE;
mii.fType = MFT_SEPARATOR;
InsertMenuItem (hMenu2, 4, TRUE, &mii);
mii.fMask = MIIM_TYPE | MIIM_ID;
mii.fType = MFT_STRING;
lstrcpy (string, "&Exit");
mii.dwTypeData = string;
mii.wID = 4;
InsertMenuItem (hMenu2, 5, TRUE, &mii);
lstrcpy (string, "&File");
mii.dwTypeData = string;
mii.cch = lstrlen (string);
mii.fMask = MIIM_TYPE | MIIM_SUBMENU;
mii.hSubMenu = hMenu2;
InsertMenuItem (hMenu, 0, FALSE, &mii);
HMENU hMenu3;
hMenu3 = CreatePopupMenu ();
mii.fMask = MIIM_TYPE | MIIM_ID;
mii.fType = MFT_STRING;
lstrcpy (string, "&Using KaPad");
mii.dwTypeData = string;
mii.wID = 8;
InsertMenuItem (hMenu3, 2, TRUE, &mii);
mii.fMask = MIIM_TYPE;
mii.fType = MFT_SEPARATOR;
InsertMenuItem (hMenu3, 4, TRUE, &mii);
mii.fMask = MIIM_TYPE | MIIM_ID;
mii.fType = MFT_STRING;
lstrcpy (string, "&Credits");
mii.dwTypeData = string;
mii.wID = 8;
InsertMenuItem (hMenu3, 2, TRUE, &mii);
lstrcpy (string, "&Help");
mii.fMask = MIIM_TYPE | MIIM_SUBMENU;
mii.hSubMenu = hMenu3;
InsertMenuItem (hMenu, 3, FALSE, &mii);
SetMenu (hWnd, hMenu);
RECT rect;
GetClientRect (hWnd, &rect);
hEdit = CreateWindow ("EDIT", "hello",
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE,
0, 0, rect.right, rect.bottom,
hWnd, (HMENU) 10,
hInstGlobal, NULL);
return 0;
case WM_SIZE:
GetClientRect (hWnd, &rect);
MoveWindow (hEdit, 0, 0, rect.right,
rect.bottom, TRUE);
return 0;
case WM_COMMAND:
if (HIWORD(wParam) == 0)
{
switch LOWORD(wParam)
{
case 1:
char *EditString;
EditString = new char[80];
lstrcpy (EditString, "");
SetWindowText (hEdit, EditString);
delete [] EditString;
return 0;
case 2:
HANDLE hFile;
hFile = CreateFile ("c:\\text.txt",
GENERIC_READ, 0,
NULL, OPEN_EXISTING,
0, NULL);
DWORD Size;
Size = GetFileSize (hFile, NULL);
char *FileText;
FileText = new char[Size+1];
DWORD Readd;
ReadFile (hWnd, FileText, Size+1, &Readd, NULL);
CloseHandle (hFile);
SetWindowText (hEdit, FileText);
delete [] EditString;
return 0;
case 3:
hFile = CreateFile ("C:\\text.txt", GENERIC_WRITE,
0, NULL, CREATE_ALWAYS, NULL,
NULL);
FileText = new char[GetWindowTextLength(hEdit)+1];
GetWindowText (hEdit, FileText, GetWindowTextLength(
hEdit)+1);
WriteFile (hFile, FileText,
GetWindowTextLength(hEdit)+1, &Readd, NULL);
CloseHandle (hFile);
delete [] FileText;
return 0;
case 4:
PostQuitMessage(0);
return 0;
}
}
// If the user wants to close the application
case WM_DESTROY:
// then close it
PostQuitMessage(WM_QUIT);
break;
default:
// Process the left-over messages
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
// If something was not done, let it go
return 0;
}
Can you help me solve this problem?