Archived

This topic is now archived and is closed to further replies.

Metzler

Second RegisterClass for MDI is driving me nuts...

Recommended Posts

Hey Peops, I dont know what to do. I am now trying for several hours on one single problem : The second RegisterClass ALWAYS fails. I have tried 2 different online tutorials and the way, it is described in Charles Petzold book. I dont know, what the problem is, it just doesnt work. I hope, anybody out there may be able, to help me, else i will drop all Visual Studio off of my computer Dont bother with the header files, there are no functions in it, that are actually being called. THX for help or just reading this bunch of code #include <windows.h> #include <commdlg.h> #include <stdlib.h> #include <stdio.h> #include <ddraw.h> #include "structs.h" #include "dxstructs.h" #include "dxinit.h" #include <assert.h> #include "resource.h" #include "filedlg.h" #include "fileopsmap.h" #include "dxfunctions.h" #include "childwnd.h" LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); LRESULT CALLBACK PaletteProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); int WINAPI WinMain (HINSTANCE hinst, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASS winclass; MSG message; const char szclassname[] = "Abinator"; hInstance = hinst; HACCEL hAccel ; HWND hwndClient, hwnd; //Main Window Class winclass.style = CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinst; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE + 1); winclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); winclass.lpszClassName = "Abinator MAP"; if (!RegisterClass(&winclass)) MessageBox(NULL, "Window Init Failure", "Failure", MB_OK); winclass.style = CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = PaletteProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = sizeof(HANDLE); winclass.hInstance = hinst; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = g_szChildClassName; if (!RegisterClass(&winclass)) MessageBox(NULL, "MDI Window Init Failure", "Failure", MB_OK); hwnd = CreateWindow("Abinator MAP", TEXT ("Abinator Map Editor"), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hinst, NULL); hAccel = LoadAccelerators (hInstance, "Abinator MAP Editor 2.0") ; hwndClient = GetWindow (hwnd, GW_CHILD) ; ShowWindow (hwnd, ncmdshow) ; UpdateWindow (hwnd) ; // DX_Init_Display(hwnd); // Init_Map(); // load_map("karte.map"); while (GetMessage (&message, NULL, 0, 0)) { /* RECT rct; AdjustClient(hwnd, rct); int right = (rct.right-rct.left) / 40 + view_x; int bottom = (rct.bottom-rct.top) / 40 + view_y; render_map(view_x,view_y,right,bottom, rct);*/ // char buffer[150]; // long length = sprintf(buffer, "Mouse X : %d, Mouse Y : %d, Bottom : %d",Mouse_Move.x, Mouse_Move.y, rct.bottom); // TextOut(hdc,0,0,buffer,length); if (!TranslateMDISysAccel(hwndClient, &message) && !TranslateAccelerator (hwnd, hAccel, &message)) { TranslateMessage (&message) ; DispatchMessage (&message) ; } } return message.wParam ; } LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { static TCHAR szFileName[MAX_PATH], szTitleName[MAX_PATH]; static HWND hwndClient ; HMENU hMenu; HWND hwndChild; MDICREATESTRUCT mdicreate ; switch(message) { case WM_CREATE: { RECT Scroll_Window; AdjustClient(hwnd, Scroll_Window); OffsetRect(&Scroll_Window, -1*Window_Cords.x, -1*Window_Cords.y); scroll_x = Scroll_Window.right / 40; scroll_y = Scroll_Window.bottom / 40; scroll_x = feldx - scroll_x; scroll_y = feldy - scroll_y; SetScrollRange (hwnd, SB_VERT, 0, scroll_y, FALSE) ; SetScrollRange (hwnd, SB_HORZ, 0, scroll_x, FALSE) ; CLIENTCREATESTRUCT ccs; ccs.hWindowMenu = NULL; ccs.idFirstChild = IDM_FIRSTCHILD; hwndClient = CreateWindow(TEXT ("MDICLIENT"), NULL, WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE, 0,0,0,0, hwnd, NULL, hInstance, (PSTR)&ccs); }break; case WM_SIZE: { RECT Scroll_Window; AdjustClient(hwnd, Scroll_Window); OffsetRect(&Scroll_Window, -1*Window_Cords.x, -1*Window_Cords.y); scroll_x = Scroll_Window.right / 40; scroll_y = Scroll_Window.bottom / 40; scroll_x = feldx - scroll_x; scroll_y = feldy - scroll_y; SetScrollRange (hwnd, SB_VERT, 0, scroll_y, FALSE) ; SetScrollRange (hwnd, SB_HORZ, 0, scroll_x, FALSE) ; }break; case WM_COMMAND: { hMenu = GetMenu (hwnd); switch (LOWORD (wparam)) { case ID_DATEI_BEENDEN : { PostQuitMessage(0); }break; case ID_MENU_ABOUT : { MessageBox(hwnd, "Created by Wolf Fischer for Abinator, 2000 - 200X", "About : ", MB_OK); }break; case ID_ANSICHT_PALETTE : { mdicreate.szClass = g_szChildClassName; mdicreate.szTitle = TEXT ("Palette") ; mdicreate.hOwner = hInstance ; mdicreate.x = CW_USEDEFAULT ; mdicreate.y = CW_USEDEFAULT ; mdicreate.cx = CW_USEDEFAULT ; mdicreate.cy = CW_USEDEFAULT ; mdicreate.style = 0 ; mdicreate.lParam = 0 ; hwndChild = (HWND)SendMessage (hwndClient, WM_MDICREATE, 0, (LPARAM) (LPMDICREATESTRUCT) &mdicreate) ; }break; case ID_DATEI_OEFFNEN : { dialog_open_file(hwnd); }break; default : { hwndChild = (HWND) SendMessage (hwndClient, WM_MDIGETACTIVE, 0, 0) ; if (IsWindow (hwndChild)) SendMessage (hwndChild, WM_COMMAND, wparam, lparam) ; }break ; // ...und danach an DefFrameProc } } break; case WM_VSCROLL: { switch (LOWORD (wparam)) { case SB_LINEUP: view_y--; break; case SB_LINEDOWN: view_y++; break; case SB_PAGEUP: view_y = view_y - scroll_per_page; if (view_y < 0) view_y = 0; break; case SB_PAGEDOWN: view_y = view_y + scroll_per_page; if (view_y > feldy) view_y = feldy; break; case SB_THUMBPOSITION: view_y = HIWORD (wparam); break; default : break ; } if (view_y != GetScrollPos (hwnd, SB_VERT)) { if (view_y < 0) view_y = 0; if (view_y > scroll_y) view_y = scroll_y; SetScrollPos (hwnd, SB_VERT, view_y, TRUE) ; InvalidateRect (hwnd, NULL, TRUE) ; UpdateWindow (hwnd) ; } return 0 ; }break; case WM_HSCROLL: { switch(LOWORD(wparam)) { case SB_LINELEFT: view_x--; break; case SB_LINERIGHT: view_x++; break; case SB_PAGELEFT: view_x = view_x - scroll_per_page; if (view_x < 0) view_x = 0; break; case SB_PAGERIGHT: view_x = view_x + scroll_per_page; if (view_x > feldx) view_x = feldx; break; case SB_THUMBPOSITION: view_x = HIWORD(wparam); break; default:break; } if (view_x != GetScrollPos (hwnd, SB_HORZ)) { if (view_x < 0) view_x = 0; if (view_x > scroll_x) view_x = scroll_x; SetScrollPos (hwnd, SB_HORZ, view_x, TRUE) ; InvalidateRect (hwnd, NULL, TRUE) ; UpdateWindow (hwnd) ; } }break; case WM_DESTROY: { CleanUp(); PostQuitMessage(0); return(0); } break; case WM_TIMER: { MessageBeep (0) ; return 0 ; }break; case WM_MOUSEMOVE: { Mouse_Move.x = LOWORD(lparam); Mouse_Move.y = HIWORD(lparam); }break; default:return DefFrameProc(hwnd, hwndClient, message, wparam, lparam); } } LRESULT CALLBACK PaletteProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { static HWND hwndClient, hwndFrame ; switch (LOWORD(wparam)) { case WM_CREATE : { hwndClient = GetParent (hwnd) ; hwndFrame = GetParent (hwndClient) ; }break; case WM_COMMAND : { }break; case WM_MDIACTIVATE : { }break; default:break; } return DefMDIChildProc(hwnd, message, wparam, lparam); }

Share this post


Link to post
Share on other sites
Why not try using WNDCLASSEX, RegisterClassEx(), CreateWindowEx() and see what will happen? And remember to initialize the .cbSize member of your WNDCLASSEX.


er... what is the type and value of your g_szChildClassName? Better to have it a TCHAR* instead of char*.

... just a suggestion.

Share this post


Link to post
Share on other sites
THX for the answer.
I tried WNDCLASSEX, RegisterClassEx and CreateWindowEx several times, it didnt make a difference.
Even the g_szChildClassName hadnt any impact on the result.

Share this post


Link to post
Share on other sites