Hi, Versuche grad ein Text Editor zu schreiben.
Hab 2 Probleme.
- Wenn ich ein Child schließe, wird nicht gefragt ob ich es schließen will. wie kann ich das machen?
- Ich will wenn ich auf den einen Button klick das ein Text im aktuellen Child Fenster hinzugefügt wird. Wie mach ich das?
(hab die stelle markiert im main.c file)
Schon mal Danke für Die Hilfe
Das ist die .rh Datei
#include "mdi\_unit.h"
MAIN MENU
{
POPUP "File"
{
MENUITEM "New", CM\_FILE\_NEW MENUITEM "Open...", CM\_FILE\_OPEN
MENUITEM "Save", CM\_FILE\_SAVE, GRAYED
MENUITEM "Save As...", CM\_FILE\_SAVEAS, GRAYED
MENUITEM SEPARATOR
MENUITEM "Exit", CM\_FILE\_EXIT
}
POPUP "Edit", GRAYED
{
MENUITEM "Undo\tCtrl+Z", CM\_EDIT\_UNDO
MENUITEM SEPARATOR
MENUITEM "Cut\tCtrl+X", CM\_EDIT\_CUT
MENUITEM "Copy\tCtrl+C", CM\_EDIT\_COPY
MENUITEM "Paste\tCtrl+V", CM\_EDIT\_PASTE
}
POPUP "Add", GRAYED
{
POPUP "Variables"
{
POPUP "video\_mode"
{
MENUITEM "800x600", CM\_ADD\_VM86
MENUITEM "1024x768", CM\_ADD\_VM17
MENUITEM "1200x1024", CM\_ADD\_VM11
}
}
}
POPUP "Window", GRAYED
{
MENUITEM "Cascade", CM\_WINDOW\_CASCADE
MENUITEM "Tile Horizontal", CM\_WINDOW\_TILEHORZ
MENUITEM "Tile Vertical", CM\_WINDOW\_TILEVERT
MENUITEM "Arrange Icons", CM\_WINDOW\_ARRANGE
}
}
Das ist die main.c datei
#include
#include
#include "mdi\_unit.h"
#define ID\_STATUSBAR 4997
#define ID\_TOOLBAR 4998
#define ID\_MDI\_CLIENT 4999
#define ID\_MDI\_FIRSTCHILD 50000
#define IDC\_CHILD\_EDIT 2000
#include
#include
using namespace std;
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK MDIChildWndProc(HWND hwnd, UINT Message, WPARAM wParam,
LPARAM lParam);
char g\_szAppName[] = "MyMDIWindow";
char g\_szChild[] = "MyMDIChild";
HINSTANCE g\_hInst;
HWND g\_hMDIClient, g\_hStatusBar, g\_hToolBar;
HWND g\_hMainWindow;
BOOL LoadFile(HWND hEdit, LPSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;
hFile = CreateFile(pszFileName, GENERIC\_READ, FILE\_SHARE\_READ, NULL,
OPEN\_EXISTING, FILE\_ATTRIBUTE\_NORMAL, 0);
if(hFile != INVALID\_HANDLE\_VALUE)
{
DWORD dwFileSize;
dwFileSize = GetFileSize(hFile, NULL);
if(dwFileSize != 0xFFFFFFFF)
{
LPSTR pszFileText;
pszFileText = LPSTR(GlobalAlloc(GPTR, dwFileSize + 1));
if(pszFileText != NULL)
{
DWORD dwRead;
if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
{
pszFileText[dwFileSize] = 0; // Null terminator
if(SetWindowText(hEdit, pszFileText))
bSuccess = TRUE; // It worked!
}
GlobalFree(pszFileText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}
BOOL SaveFile(HWND hEdit, LPSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;
hFile = CreateFile(pszFileName, GENERIC\_WRITE, 0, NULL,
CREATE\_ALWAYS, FILE\_ATTRIBUTE\_NORMAL, 0);
if(hFile != INVALID\_HANDLE\_VALUE)
{
DWORD dwTextLength;
dwTextLength = GetWindowTextLength(hEdit);
if(dwTextLength \> 0)// No need to bother if there's no text.
{
LPSTR pszText;
pszText = LPSTR(GlobalAlloc(GPTR, dwTextLength + 1));
if(pszText != NULL)
{
if(GetWindowText(hEdit, pszText, dwTextLength + 1))
{
DWORD dwWritten;
if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
bSuccess = TRUE;
}
GlobalFree(pszText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}
BOOL GetFileName(HWND hwnd, LPSTR pszFileName, BOOL bSave)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
pszFileName[0] = 0;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "Script Files (\*.wdl)\0\*.wdl\0All Files (\*.\*)\0\*.\*\0\0";
ofn.lpstrFile = pszFileName;
ofn.nMaxFile = MAX\_PATH;
ofn.lpstrDefExt = "wdl";
if(bSave)
{
ofn.Flags = OFN\_EXPLORER | OFN\_PATHMUSTEXIST | OFN\_HIDEREADONLY |
OFN\_OVERWRITEPROMPT;
if(!GetSaveFileName(&ofn))
return FALSE;
}
else
{
ofn.Flags = OFN\_EXPLORER | OFN\_FILEMUSTEXIST | OFN\_HIDEREADONLY;
if(!GetOpenFileName(&ofn))
return FALSE;
}
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
MSG Msg;
WNDCLASSEX WndClassEx;
InitCommonControls();
g\_hInst = hInstance;
WndClassEx.cbSize = sizeof(WNDCLASSEX);
WndClassEx.style = CS\_HREDRAW | CS\_VREDRAW;
WndClassEx.lpfnWndProc = WndProc;
WndClassEx.cbClsExtra = 0;
WndClassEx.cbWndExtra = 0;
WndClassEx.hInstance = hInstance;
WndClassEx.hIcon = LoadIcon(NULL, IDI\_APPLICATION);
WndClassEx.hCursor = LoadCursor(NULL, IDC\_ARROW);
WndClassEx.hbrBackground = (HBRUSH)(COLOR\_3DSHADOW+1);
WndClassEx.lpszMenuName = "MAIN";
WndClassEx.lpszClassName = g\_szAppName;
WndClassEx.hIconSm = LoadIcon(NULL, IDI\_APPLICATION);
if(!RegisterClassEx(&WndClassEx))
{
MessageBox(0, "Could Not Register Window", "Oh Oh...",
MB\_ICONEXCLAMATION | MB\_OK);
return -1;
}
WndClassEx.lpfnWndProc = MDIChildWndProc;
WndClassEx.lpszMenuName = NULL;
WndClassEx.lpszClassName = g\_szChild;
WndClassEx.hbrBackground = (HBRUSH)(COLOR\_3DFACE+1);
if(!RegisterClassEx(&WndClassEx))
{
MessageBox(0, "Could Not Register Child Window", "Oh Oh...",
MB\_ICONEXCLAMATION | MB\_OK);
return -1;
}
g\_hMainWindow = CreateWindowEx(WS\_EX\_APPWINDOW, g\_szAppName,
"Wdl Creator", WS\_OVERLAPPEDWINDOW | WS\_CLIPCHILDREN,
CW\_USEDEFAULT, CW\_USEDEFAULT, CW\_USEDEFAULT, CW\_USEDEFAULT,
0, 0, hInstance, NULL);
if (g\_hMainWindow == NULL){
MessageBox(0, "No Window", "Oh Oh...", MB\_ICONEXCLAMATION | MB\_OK);
return -1;
}
ShowWindow(g\_hMainWindow, nCmdShow);
UpdateWindow(g\_hMainWindow);
while(GetMessage(&Msg, NULL, 0, 0))
{
if (!TranslateMDISysAccel(g\_hMDIClient, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM\_CREATE:
{
CLIENTCREATESTRUCT ccs;
int iStatusWidths[] = {200, 300, -1};
TBADDBITMAP tbab;
TBBUTTON tbb[9];
// Find window menu where children will be listed
ccs.hWindowMenu = GetSubMenu(GetMenu(hwnd), 3);
ccs.idFirstChild = ID\_MDI\_FIRSTCHILD;
g\_hMDIClient = CreateWindowEx(WS\_EX\_CLIENTEDGE, "mdiclient", NULL,
WS\_CHILD | WS\_CLIPCHILDREN | WS\_VSCROLL | WS\_HSCROLL,
CW\_USEDEFAULT, CW\_USEDEFAULT, CW\_USEDEFAULT, CW\_USEDEFAULT,
hwnd, (HMENU)ID\_MDI\_CLIENT, g\_hInst, (LPVOID)&ccs);
ShowWindow(g\_hMDIClient, SW\_SHOW);
g\_hStatusBar = CreateWindowEx(0, STATUSCLASSNAME, NULL,
WS\_CHILD | WS\_VISIBLE | SBARS\_SIZEGRIP, 0, 0, 0, 0,
hwnd, (HMENU)ID\_STATUSBAR, g\_hInst, NULL);
SendMessage(g\_hStatusBar, SB\_SETPARTS, 3, (LPARAM)iStatusWidths);
SendMessage(g\_hStatusBar, SB\_SETTEXT, 2, (LPARAM)"Wdl Creator by Extremegames");
g\_hToolBar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS\_CHILD | WS\_VISIBLE, 0, 0, 0, 0,
hwnd, (HMENU)ID\_TOOLBAR, g\_hInst, NULL);
// Send the TB\_BUTTONSTRUCTSIZE message, which is required for
// backward compatibility.
SendMessage(g\_hToolBar, TB\_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
tbab.hInst = HINST\_COMMCTRL;
tbab.nID = IDB\_STD\_SMALL\_COLOR;
SendMessage(g\_hToolBar, TB\_ADDBITMAP, 0, (LPARAM)&tbab);
ZeroMemory(tbb, sizeof(tbb));
tbb[0].iBitmap = STD\_FILENEW;
tbb[0].fsState = TBSTATE\_ENABLED;
tbb[0].fsStyle = TBSTYLE\_BUTTON;
tbb[0].idCommand = CM\_FILE\_NEW;
tbb[1].iBitmap = STD\_FILEOPEN;
tbb[1].fsState = TBSTATE\_ENABLED;
tbb[1].fsStyle = TBSTYLE\_BUTTON;
tbb[1].idCommand = CM\_FILE\_OPEN;
tbb[2].iBitmap = STD\_FILESAVE;
tbb[2].fsStyle = TBSTYLE\_BUTTON;
tbb[2].idCommand = CM\_FILE\_SAVE;
tbb[3].fsStyle = TBSTYLE\_SEP;
tbb[4].iBitmap = STD\_CUT;
tbb[4].fsStyle = TBSTYLE\_BUTTON;
tbb[4].idCommand = CM\_EDIT\_CUT;
tbb[5].iBitmap = STD\_COPY;
tbb[5].fsStyle = TBSTYLE\_BUTTON;
tbb[5].idCommand = CM\_EDIT\_COPY;
tbb[6].iBitmap = STD\_PASTE;
tbb[6].fsStyle = TBSTYLE\_BUTTON;
tbb[6].idCommand = CM\_EDIT\_PASTE;
tbb[7].fsStyle = TBSTYLE\_SEP;
tbb[8].iBitmap = STD\_UNDO;
tbb[8].fsStyle = TBSTYLE\_BUTTON;
tbb[8].idCommand = CM\_EDIT\_UNDO;
SendMessage(g\_hToolBar, TB\_ADDBUTTONS, 9, (LPARAM)&tbb);
return 0;
}
case WM\_COMMAND:
{
switch(LOWORD(wParam))
{
case CM\_FILE\_EXIT:
PostMessage(hwnd, WM\_CLOSE, 0, 0);
break;
case CM\_FILE\_NEW:
{
MDICREATESTRUCT mcs;
HWND hChild;
mcs.szTitle = "[Untitled]";
mcs.szClass = g\_szChild;
mcs.hOwner = g\_hInst;
mcs.x = mcs.cx = CW\_USEDEFAULT;
mcs.y = mcs.cy = CW\_USEDEFAULT;
mcs.style = MDIS\_ALLCHILDSTYLES;
hChild = (HWND)SendMessage(g\_hMDIClient, WM\_MDICREATE,
0, (LONG)&mcs);
if(!hChild)
{
MessageBox(hwnd, "MDI Child creation failed.", "Oh Oh...",
MB\_ICONEXCLAMATION | MB\_OK);
}
}
break;
case CM\_FILE\_OPEN:
{
MDICREATESTRUCT mcs;
HWND hChild;
char szFileName[MAX\_PATH];
if(!GetFileName(hwnd, szFileName, FALSE))
break;
mcs.szTitle = szFileName;
mcs.szClass = g\_szChild;
mcs.hOwner = g\_hInst;
mcs.x = mcs.cx = CW\_USEDEFAULT;
mcs.y = mcs.cy = CW\_USEDEFAULT;
mcs.style = MDIS\_ALLCHILDSTYLES;
hChild = (HWND)SendMessage(g\_hMDIClient, WM\_MDICREATE,
0, (LONG)&mcs);
if(!hChild)
{
MessageBox(hwnd, "MDI Child creation failed.", "Oh Oh...",
MB\_ICONEXCLAMATION | MB\_OK);
}
}
break;
case CM\_WINDOW\_TILEHORZ:
PostMessage(g\_hMDIClient, WM\_MDITILE, MDITILE\_HORIZONTAL, 0);
break;
case CM\_WINDOW\_TILEVERT:
PostMessage(g\_hMDIClient, WM\_MDITILE, MDITILE\_VERTICAL, 0);
break;
case CM\_WINDOW\_CASCADE:
PostMessage(g\_hMDIClient, WM\_MDICASCADE, 0, 0);
break;
case CM\_WINDOW\_ARRANGE:
PostMessage(g\_hMDIClient, WM\_MDIICONARRANGE, 0, 0);
break;
default:
{
if(LOWORD(wParam) \>= ID\_MDI\_FIRSTCHILD){
DefFrameProc(hwnd, g\_hMDIClient, Message, wParam, lParam);
}
else {
HWND hChild;
hChild = (HWND)SendMessage(g\_hMDIClient, WM\_MDIGETACTIVE,0,0);
if(hChild){
SendMessage(hChild, WM\_COMMAND, wParam, lParam);
}
}
}
}
}
break;
case WM\_SIZE:
{
RECT rectClient, rectStatus, rectTool;
UINT uToolHeight, uStatusHeight, uClientAlreaHeight;
SendMessage(g\_hToolBar, TB\_AUTOSIZE, 0, 0);
SendMessage(g\_hStatusBar, WM\_SIZE, 0, 0);
GetClientRect(hwnd, &rectClient);
GetWindowRect(g\_hStatusBar, &rectStatus);
GetWindowRect(g\_hToolBar, &rectTool);
uToolHeight = rectTool.bottom - rectTool.top;
uStatusHeight = rectStatus.bottom - rectStatus.top;
uClientAlreaHeight = rectClient.bottom;
MoveWindow(g\_hMDIClient, 0, uToolHeight, rectClient.right, uClientAlreaHeight - uStatusHeight - uToolHeight, TRUE);
}
break;
case WM\_CLOSE:
if(MessageBox(NULL, "Do you really want to quit?", "Message", MB\_YESNO) == IDYES)
{
DestroyWindow(hwnd);
}
break;
case WM\_DESTROY:
PostQuitMessage(0);
break;
default:
return DefFrameProc(hwnd, g\_hMDIClient, Message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK MDIChildWndProc(HWND hwnd, UINT Message, WPARAM wParam,
LPARAM lParam)
{
switch(Message)
{
case WM\_CREATE:
{
char szFileName[MAX\_PATH];
HWND hEdit;
hEdit = CreateWindowEx(WS\_EX\_CLIENTEDGE, "EDIT", "",
WS\_CHILD | WS\_VISIBLE | WS\_HSCROLL | WS\_VSCROLL | ES\_MULTILINE |
ES\_WANTRETURN,
CW\_USEDEFAULT, CW\_USEDEFAULT, CW\_USEDEFAULT, CW\_USEDEFAULT,
hwnd, (HMENU)IDC\_CHILD\_EDIT, g\_hInst, NULL);
SendMessage(hEdit, WM\_SETFONT,
(WPARAM)GetStockObject(DEFAULT\_GUI\_FONT), MAKELPARAM(TRUE, 0));
GetWindowText(hwnd, szFileName, MAX\_PATH);
if(\*szFileName != '[')
{
if(!LoadFile(hEdit, szFileName))
{
MessageBox(hwnd, "Couldn't Load File.", "Error.",
MB\_OK | MB\_ICONEXCLAMATION);
return -1; //cancel window creation
}
}
}
break;
case WM\_SIZE:
if(wParam != SIZE\_MINIMIZED)
MoveWindow(GetDlgItem(hwnd, IDC\_CHILD\_EDIT), 0, 0, LOWORD(lParam),
HIWORD(lParam), TRUE);
break;
case WM\_MDIACTIVATE:
{
HMENU hMenu, hFileMenu;
BOOL EnableFlag;
char szFileName[MAX\_PATH];
hMenu = GetMenu(g\_hMainWindow);
if(hwnd == (HWND)lParam){ //being activated
EnableFlag = TRUE;
}
else{
EnableFlag = FALSE; //being de-activated
}
EnableMenuItem(hMenu, 1, MF\_BYPOSITION | (EnableFlag ? MF\_ENABLED : MF\_GRAYED));
EnableMenuItem(hMenu, 2, MF\_BYPOSITION | (EnableFlag ? MF\_ENABLED : MF\_GRAYED));
EnableMenuItem(hMenu, 3, MF\_BYPOSITION | (EnableFlag ? MF\_ENABLED : MF\_GRAYED));
hFileMenu = GetSubMenu(hMenu, 0);
EnableMenuItem(hFileMenu, CM\_FILE\_SAVE, MF\_BYCOMMAND | (EnableFlag ? MF\_ENABLED : MF\_GRAYED));
EnableMenuItem(hFileMenu, CM\_FILE\_SAVEAS, MF\_BYCOMMAND | (EnableFlag ? MF\_ENABLED : MF\_GRAYED));
DrawMenuBar(g\_hMainWindow);
SendMessage(g\_hToolBar, TB\_ENABLEBUTTON, CM\_FILE\_SAVE, MAKELONG(EnableFlag, 0));
SendMessage(g\_hToolBar, TB\_ENABLEBUTTON, CM\_EDIT\_UNDO, MAKELONG(EnableFlag, 0));
SendMessage(g\_hToolBar, TB\_ENABLEBUTTON, CM\_EDIT\_CUT, MAKELONG(EnableFlag, 0));
SendMessage(g\_hToolBar, TB\_ENABLEBUTTON, CM\_EDIT\_COPY, MAKELONG(EnableFlag, 0));
SendMessage(g\_hToolBar, TB\_ENABLEBUTTON, CM\_EDIT\_PASTE, MAKELONG(EnableFlag, 0));
GetWindowText(hwnd, szFileName, MAX\_PATH);
SendMessage(g\_hStatusBar, SB\_SETTEXT, 0, (LPARAM)(EnableFlag ? szFileName : ""));
}
break;
case WM\_SETFOCUS:
SetFocus(GetDlgItem(hwnd, IDC\_CHILD\_EDIT));
break;
case WM\_COMMAND:
switch(LOWORD(wParam))
{
case CM\_FILE\_SAVE:
{
char szFileName[MAX\_PATH];
GetWindowText(hwnd, szFileName, MAX\_PATH);
if(\*szFileName != '[')
{
if(!SaveFile(GetDlgItem(hwnd, IDC\_CHILD\_EDIT), szFileName))
{
MessageBox(hwnd, "Couldn't Save File.", "Error.",
MB\_OK | MB\_ICONEXCLAMATION);
return 0;
}
}
else
{
PostMessage(hwnd, WM\_COMMAND,
MAKEWPARAM(CM\_FILE\_SAVEAS, 0), 0);
}
}
return 0;
case CM\_FILE\_SAVEAS:
{
char szFileName[MAX\_PATH];
if(GetFileName(hwnd, szFileName, TRUE))
{
if(!SaveFile(GetDlgItem(hwnd, IDC\_CHILD\_EDIT), szFileName))
{
MessageBox(hwnd, "Couldn't Save File.", "Error.",
MB\_OK | MB\_ICONEXCLAMATION);
return 0;
}
else
{
SetWindowText(hwnd, szFileName);
}
}
}
return 0;
case CM\_EDIT\_UNDO:
SendDlgItemMessage(hwnd, IDC\_CHILD\_EDIT, EM\_UNDO, 0, 0);
break;
case CM\_EDIT\_CUT:
SendDlgItemMessage(hwnd, IDC\_CHILD\_EDIT, WM\_CUT, 0, 0);
break;
case CM\_EDIT\_COPY:
SendDlgItemMessage(hwnd, IDC\_CHILD\_EDIT, WM\_COPY, 0, 0);
break;
case CM\_EDIT\_PASTE:
SendDlgItemMessage(hwnd, IDC\_CHILD\_EDIT, WM\_PASTE, 0, 0);
break;
case CM\_ADD\_VM86:
**//-----------\>Hier soll der Text in das aktuelle child window eingefügt werden**
break;
break;
}
return 0;
}
return DefMDIChildProc(hwnd, Message, wParam, lParam);
}
Und das ist die header .h Datei
#define CM\_WINDOW\_TILEVERT 9080
#define CM\_WINDOW\_TILEHORZ 9082
#define CM\_WINDOW\_ARRANGE 9081
#define CM\_WINDOW\_TILE 9080
#define CM\_WINDOW\_CASCADE 9076
#define CM\_EDIT\_PASTE 9079
#define CM\_EDIT\_COPY 9078
#define CM\_EDIT\_CUT 9077
#define CM\_EDIT\_REDO 9076
#define CM\_EDIT\_UNDO 9075
#define CM\_FILE\_SAVEAS 9074
#define CM\_FILE\_SAVE 9073
#define CM\_FILE\_OPEN 9072
#define CM\_HELP\_ABOUT 9072
#define CM\_FILE\_EXIT 9071
#define CM\_FILE\_NEW 9070
#define CM\_ADD\_VM86 10000
#define CM\_ADD\_VM17 10001
#define CM\_ADD\_VM11 10002