Window closes when edit is made
I'm making a little text editor. So far I have it with a menu and the edit box. When I comment out the edit box the program works fine, but when the edit code is included it tries closing it right after it opens and if you reply no to the close question another pops up. Any ideas?
Here is the code. I can add resource.h and menu.rc if anyone needs to see them.
Code:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "resource.h"
#define EDIT 1
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
char szClassName[] = "FreeEdit";
HINSTANCE hThisInstance;
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) {
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
HMENU menu;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_HREDRAW | CS_VREDRAW;
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
if(!RegisterClassEx(&wincl)) {
MessageBox (NULL, "There was an error starting FreePad :(" , "Error!", 0 + MB_ICONHAND + MB_SETFOREGROUND);
return 0;
}
hwnd = CreateWindowEx(
0,
szClassName,
"FreePad 00.00",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow(hwnd, nFunsterStil);
menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(ID_MENU));
SetMenu(hwnd, menu);
while(GetMessage(&messages, NULL, 0, 0)) {
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
HDC hdc;
TEXTMETRIC tm;
static HWND hwndEdit;
switch (message) {
case WM_CREATE:
hwndEdit = CreateWindow(TEXT ("edit"), NULL, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | WS_BORDER | ES_LEFT | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0,0,0,0, hwnd, (HMENU) EDIT, ((LPCREATESTRUCT) lParam)->hInstance, NULL);
return 0;
case WM_SETFOCUS:
SetFocus(hwndEdit);
return 0;
case WM_SIZE:
MoveWindow (hwndEdit, 0,0, LOWORD (lParam), HIWORD (lParam), TRUE);
return 0;
return 0;
case WM_COMMAND:
switch(wParam) {
case MENU_FILE_EXIT:
SendMessage( hwnd, WM_CLOSE, 0, 0L );
return 0;
case MENU_HELP_ABOUT:
MessageBox (NULL, "FreePad 00.00\nCopyright (C) 2003 Eric Marcarelli" , "About FreePad", 0 + MB_SETFOREGROUND);
return 0;
}
case WM_CLOSE:
if (IDYES == MessageBox (NULL, "Unsaved work will be lost. Close anyway?" , "Close?", 0 + MB_YESNO + MB_ICONQUESTION + MB_SETFOREGROUND))
DestroyWindow( hwnd );
return 0;
case WM_QUERYENDSESSION:
if (IDYES == MessageBox (NULL, "Unsaved work will be lost. Close anyway?" , "Close?", 0 + MB_YESNO + MB_ICONQUESTION + MB_SETFOREGROUND))
return 1;
else
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}