Menu like file, edit, help, etc...

This is a discussion on Menu like file, edit, help, etc... within the Windows Programming forums, part of the Platform Specific Boards category; Hi, i'm building a Program like Notepad or something. I just can't get it work. Everything works except the menu, ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    188

    Menu like file, edit, help, etc...

    Hi, i'm building a Program like Notepad or something. I just can't get it work. Everything works except the menu, can you fixa the menu thing?

    Here is everything you need:
    http://www.livijnproductions.se/Jinky.rar
    The menu is in the .rc and the rest of the code is in the .o and .h

    It's not a big file so you maybe should figure out whats wrong and tell me!

    Thank you!


    CODES

    main.c
    Code:
    #include <windows.h>
    #include <commctrl.h>
    #include "resource.h"
    
    
    const char g_szClassName[] = "myWindowClass";
    const char g_szChildClassName[] = "myMDIChildWindowClass";
    
    #define IDC_MAIN_MDI	101
    #define IDC_MAIN_TOOL	102
    #define IDC_MAIN_STATUS	103
    #define IDC_CHILD_EDIT	101
    #define ID_MDI_FIRSTCHILD 50000
    
    HWND g_hMDIClient = NULL;
    HWND g_hMainWindow = NULL;
    
    BOOL LoadTextFileToEdit(HWND hEdit, LPCTSTR pszFileName)
    {
    	HANDLE hFile;
    	BOOL bSuccess = FALSE;
    
    	hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
    		OPEN_EXISTING, 0, NULL);
    	if(hFile != INVALID_HANDLE_VALUE)
    	{
    		DWORD dwFileSize;
    
    		dwFileSize = GetFileSize(hFile, NULL);
    		if(dwFileSize != 0xFFFFFFFF)
    		{
    			LPSTR pszFileText;
    
    			pszFileText = GlobalAlloc(GPTR, dwFileSize + 1);
    			if(pszFileText != NULL)
    			{
    				DWORD dwRead;
    
    				if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
    				{
    					pszFileText[dwFileSize] = 0; // Add null terminator
    					if(SetWindowText(hEdit, pszFileText))
    						bSuccess = TRUE; // It worked!
    				}
    				GlobalFree(pszFileText);
    			}
    		}
    		CloseHandle(hFile);
    	}
    	return bSuccess;
    }
    
    BOOL SaveTextFileFromEdit(HWND hEdit, LPCTSTR pszFileName)
    {
    	HANDLE hFile;
    	BOOL bSuccess = FALSE;
    
    	hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, NULL,
    		CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    	if(hFile != INVALID_HANDLE_VALUE)
    	{
    		DWORD dwTextLength;
    
    		dwTextLength = GetWindowTextLength(hEdit);
    		// No need to bother if there's no text.
    		if(dwTextLength > 0)
    		{
    			LPSTR pszText;
    			DWORD dwBufferSize = dwTextLength + 1;
    
    			pszText = GlobalAlloc(GPTR, dwBufferSize);
    			if(pszText != NULL)
    			{
    				if(GetWindowText(hEdit, pszText, dwBufferSize))
    				{
    					DWORD dwWritten;
    
    					if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
    						bSuccess = TRUE;
    				}
    				GlobalFree(pszText);
    			}
    		}
    		CloseHandle(hFile);
    	}
    	return bSuccess;
    }
    
    void DoFileOpen(HWND hwnd)
    {
    	OPENFILENAME ofn;
    	char szFileName[MAX_PATH] = "";
    
    	ZeroMemory(&ofn, sizeof(ofn));
    
    	ofn.lStructSize = sizeof(ofn);
    	ofn.hwndOwner = hwnd;
    	ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
    	ofn.lpstrFile = szFileName;
    	ofn.nMaxFile = MAX_PATH;
    	ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    	ofn.lpstrDefExt = "txt";
    
    	if(GetOpenFileName(&ofn))
    	{
    		HWND hEdit = GetDlgItem(hwnd, IDC_CHILD_EDIT);
    		if(LoadTextFileToEdit(hEdit, szFileName))
    		{
    			SendDlgItemMessage(g_hMainWindow, IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM)"Opened...");
    			SendDlgItemMessage(g_hMainWindow, IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName);
    
    			SetWindowText(hwnd, szFileName);
    		}
    	}
    }
    
    void DoFileSave(HWND hwnd)
    {
    	OPENFILENAME ofn;
    	char szFileName[MAX_PATH] = "";
    
    	ZeroMemory(&ofn, sizeof(ofn));
    
    	ofn.lStructSize = sizeof(ofn);
    	ofn.hwndOwner = hwnd;
    	ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
    	ofn.lpstrFile = szFileName;
    	ofn.nMaxFile = MAX_PATH;
    	ofn.lpstrDefExt = "txt";
    	ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
    
    	if(GetSaveFileName(&ofn))
    	{
    		HWND hEdit = GetDlgItem(hwnd, IDC_CHILD_EDIT);
    		if(SaveTextFileFromEdit(hEdit, szFileName))
    		{
    			SendDlgItemMessage(g_hMainWindow, IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM)"Saved...");
    			SendDlgItemMessage(g_hMainWindow, IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName);
    
    			SetWindowText(hwnd, szFileName);
    		}
    	}
    }
    
    HWND CreateNewMDIChild(HWND hMDIClient)
    {
    	MDICREATESTRUCT mcs;
    	HWND hChild;
    
    	mcs.szTitle = "[Untitled document]";
    	mcs.szClass = g_szChildClassName;
    	mcs.hOwner  = GetModuleHandle(NULL);
    	mcs.x = mcs.cx = CW_USEDEFAULT;
    	mcs.y = mcs.cy = CW_USEDEFAULT;
    	mcs.style = MDIS_ALLCHILDSTYLES;
    
    	hChild = (HWND)SendMessage(hMDIClient, WM_MDICREATE, 0, (LONG)&mcs);
    	if(!hChild)
    	{
    		MessageBox(hMDIClient, "MDI Child creation failed.", "Oh Oh...",
    			MB_ICONEXCLAMATION | MB_OK);
    	}
    	return hChild;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
    		case WM_CREATE:
    		{
    			HWND hTool;
    			TBBUTTON tbb[3];
    			TBADDBITMAP tbab;
    
    			HWND hStatus;
    			int statwidths[] = {100, -1};
    
    			CLIENTCREATESTRUCT ccs;
    
    			// Create MDI Client
    
    			// Find window menu where children will be listed
    			ccs.hWindowMenu  = GetSubMenu(GetMenu(hwnd), 2);
    			ccs.idFirstChild = ID_MDI_FIRSTCHILD;
    
    			g_hMDIClient = CreateWindowEx(WS_EX_CLIENTEDGE, "mdiclient", NULL,
    				WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
    				CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
    				hwnd, (HMENU)IDC_MAIN_MDI, GetModuleHandle(NULL), (LPVOID)&ccs);
    
    			if(g_hMDIClient == NULL)
    				MessageBox(hwnd, "Could not create MDI client.", "Error", MB_OK | MB_ICONERROR);
    
    			// Create Toolbar
    
    			hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
    				hwnd, (HMENU)IDC_MAIN_TOOL, GetModuleHandle(NULL), NULL);
    			if(hTool == NULL)
    				MessageBox(hwnd, "Could not create tool bar.", "Error", MB_OK | MB_ICONERROR);
    
    			// Send the TB_BUTTONSTRUCTSIZE message, which is required for
    			// backward compatibility.
    			SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
    			
    			tbab.hInst = HINST_COMMCTRL;
    			tbab.nID = IDB_STD_SMALL_COLOR;
    			SendMessage(hTool, 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 = ID_FILE_NEW;
    
    			tbb[1].iBitmap = STD_FILEOPEN;
    			tbb[1].fsState = TBSTATE_ENABLED;
    			tbb[1].fsStyle = TBSTYLE_BUTTON;
    			tbb[1].idCommand = ID_FILE_OPEN;
    
    			tbb[2].iBitmap = STD_FILESAVE;
    			tbb[2].fsState = TBSTATE_ENABLED;
    			tbb[2].fsStyle = TBSTYLE_BUTTON;
    			tbb[2].idCommand = ID_FILE_SAVEAS;
    
    			SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
    
    			// Create Status bar
    
    			hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
    				WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0,
    				hwnd, (HMENU)IDC_MAIN_STATUS, GetModuleHandle(NULL), NULL);
    
    			SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
    			SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Jinky");
    		}
    		break;
    		case WM_SIZE:
    		{
    			HWND hTool;
    			RECT rcTool;
    			int iToolHeight;
    
    			HWND hStatus;
    			RECT rcStatus;
    			int iStatusHeight;
    
    			HWND hMDI;
    			int iMDIHeight;
    			RECT rcClient;
    
    			// Size toolbar and get height
    
    			hTool = GetDlgItem(hwnd, IDC_MAIN_TOOL);
    			SendMessage(hTool, TB_AUTOSIZE, 0, 0);
    
    			GetWindowRect(hTool, &rcTool);
    			iToolHeight = rcTool.bottom - rcTool.top;
    
    			// Size status bar and get height
    
    			hStatus = GetDlgItem(hwnd, IDC_MAIN_STATUS);
    			SendMessage(hStatus, WM_SIZE, 0, 0);
    
    			GetWindowRect(hStatus, &rcStatus);
    			iStatusHeight = rcStatus.bottom - rcStatus.top;
    
    			// Calculate remaining height and size edit
    
    			GetClientRect(hwnd, &rcClient);
    
    			iMDIHeight = rcClient.bottom - iToolHeight - iStatusHeight;
    
    			hMDI = GetDlgItem(hwnd, IDC_MAIN_MDI);
    			SetWindowPos(hMDI, NULL, 0, iToolHeight, rcClient.right, iMDIHeight, SWP_NOZORDER);
    		}
    		break;
    		case WM_CLOSE:
    			DestroyWindow(hwnd);
    		break;
    		case WM_DESTROY:
    			PostQuitMessage(0);
    		break;
    		case WM_COMMAND:
    			switch(LOWORD(wParam))
    			{
    				case ID_FILE_EXIT:
    					PostMessage(hwnd, WM_CLOSE, 0, 0);
    				break;
    				case ID_FILE_NEW:
    					CreateNewMDIChild(g_hMDIClient);
    				break;
    				case ID_FILE_OPEN:
    				{
    					HWND hChild = CreateNewMDIChild(g_hMDIClient);
    					if(hChild)
    					{
    						DoFileOpen(hChild);	
    					}
    				}
    				break;
    				case ID_FILE_CLOSE:
    				{
    					HWND hChild = (HWND)SendMessage(g_hMDIClient, WM_MDIGETACTIVE,0,0);
    					if(hChild)
    					{
    						SendMessage(hChild, WM_CLOSE, 0, 0);
    					}
    				}
    				break;
    				case ID_WINDOW_TILE:
    					SendMessage(g_hMDIClient, WM_MDITILE, 0, 0);
    				break;
    				case ID_WINDOW_CASCADE:
    					SendMessage(g_hMDIClient, WM_MDICASCADE, 0, 0);
    				break;
    				default:
    				{
    					if(LOWORD(wParam) >= ID_MDI_FIRSTCHILD)
    					{
    						DefFrameProc(hwnd, g_hMDIClient, WM_COMMAND, wParam, lParam);
    					}
    					else 
    					{
    						HWND hChild = (HWND)SendMessage(g_hMDIClient, WM_MDIGETACTIVE,0,0);
    						if(hChild)
    						{
    							SendMessage(hChild, WM_COMMAND, wParam, lParam);
    						}
    					}
    				}
    			}
    		break;
    		default:
    			return DefFrameProc(hwnd, g_hMDIClient, msg, wParam, lParam);
    	}
    	return 0;
    }
    
    LRESULT CALLBACK MDIChildWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
    		case WM_CREATE:
    		{
    			HFONT hfDefault;
    			HWND hEdit;
    
    			// Create Edit Control
    
    			hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
    				WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 
    				0, 0, 100, 100, hwnd, (HMENU)IDC_CHILD_EDIT, GetModuleHandle(NULL), NULL);
    			if(hEdit == NULL)
    				MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
    
    			hfDefault = GetStockObject(DEFAULT_GUI_FONT);
    			SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
    		}
    		break;
    		case WM_MDIACTIVATE:
    		{
    			HMENU hMenu, hFileMenu;
    			UINT EnableFlag;
    
    			hMenu = GetMenu(g_hMainWindow);
    			if(hwnd == (HWND)lParam)
    			{	   //being activated, enable the menus
    				EnableFlag = MF_ENABLED;
    			}
    			else
    			{						   //being de-activated, gray the menus
    				EnableFlag = MF_GRAYED;
    			}
    
    			EnableMenuItem(hMenu, 1, MF_BYPOSITION | EnableFlag);
    			EnableMenuItem(hMenu, 2, MF_BYPOSITION | EnableFlag);
    
    			hFileMenu = GetSubMenu(hMenu, 0);
    			EnableMenuItem(hFileMenu, ID_FILE_SAVEAS, MF_BYCOMMAND | EnableFlag);
    
    			EnableMenuItem(hFileMenu, ID_FILE_CLOSE, MF_BYCOMMAND | EnableFlag);
    			EnableMenuItem(hFileMenu, ID_FILE_CLOSEALL, MF_BYCOMMAND | EnableFlag);
    
    			DrawMenuBar(g_hMainWindow);
    		}
    		break;
    		case WM_COMMAND:
    			switch(LOWORD(wParam))
    			{
    				case ID_FILE_OPEN:
    					DoFileOpen(hwnd);
    				break;
    				case ID_FILE_SAVEAS:
    					DoFileSave(hwnd);
    				break;
    				case ID_EDIT_CUT:
    					SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, WM_CUT, 0, 0);
    				break;
    				case ID_EDIT_COPY:
    					SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, WM_COPY, 0, 0);
    				break;
    				case ID_EDIT_PASTE:
    					SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, WM_PASTE, 0, 0);
    				break;
    			}
    		break;
    		case WM_SIZE:
    		{
    			HWND hEdit;
    			RECT rcClient;
    
    			// Calculate remaining height and size edit
    
    			GetClientRect(hwnd, &rcClient);
    
    			hEdit = GetDlgItem(hwnd, IDC_CHILD_EDIT);
    			SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
    		}
    		return DefMDIChildProc(hwnd, msg, wParam, lParam);
    		default:
    			return DefMDIChildProc(hwnd, msg, wParam, lParam);
    	
    	}
    	return 0;
    }
    
    BOOL SetUpMDIChildWindowClass(HINSTANCE hInstance)
    {
    	WNDCLASSEX wc;
    
    	wc.cbSize		 = sizeof(WNDCLASSEX);
    	wc.style		 = CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc	 = MDIChildWndProc;
    	wc.cbClsExtra	 = 0;
    	wc.cbWndExtra	 = 0;
    	wc.hInstance	 = hInstance;
    	wc.hIcon		 = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hCursor		 = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
    	wc.lpszMenuName  = NULL;
    	wc.lpszClassName = g_szChildClassName;
    	wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION);
    
    	if(!RegisterClassEx(&wc))
    	{
    		MessageBox(0, "Could Not Register Child Window", "Oh Oh...",
    			MB_ICONEXCLAMATION | MB_OK);
    		return FALSE;
    	}
    	else
    		return TRUE;
    }
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine, int nCmdShow)
    {
        InitCommonControls();
        
    	WNDCLASSEX wc;
    	HWND hwnd;
    	MSG Msg;
    
    	
    
    	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);
    	wc.hCursor		 = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    	wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MAINMENU);
    	wc.lpszClassName = g_szClassName;
    	wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION);
    
    	if(!RegisterClassEx(&wc))
    	{
    		MessageBox(NULL, "Window Registration Failed!", "Error!",
    			MB_ICONEXCLAMATION | MB_OK);
    		return 0;
    	}
    
    	if(!SetUpMDIChildWindowClass(hInstance))
    		return 0;
    
    	hwnd = CreateWindowEx(
    		0,
    		g_szClassName,
    		"Jinky - Livijnproductions.se",
    		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
    		CW_USEDEFAULT, CW_USEDEFAULT, 480, 320,
    		NULL, NULL, hInstance, NULL);
    
    	if(hwnd == NULL)
    	{
    		MessageBox(NULL, "Window Creation Failed!", "Error!",
    			MB_ICONEXCLAMATION | MB_OK);
    		return 0;
    	}
    
    	g_hMainWindow = hwnd;
    
    	ShowWindow(hwnd, nCmdShow);
    	UpdateWindow(hwnd);
    
    	while(GetMessage(&Msg, NULL, 0, 0) > 0)
    	{
    		if (!TranslateMDISysAccel(g_hMDIClient, &Msg))
    		{
    			TranslateMessage(&Msg);
    			DispatchMessage(&Msg);
    		}
    	}
    	return Msg.wParam;
    }
    resource.h
    Code:
    //{{NO_DEPENDENCIES}}
    // Microsoft Developer Studio generated include file.
    // Used by app_four.rc
    //
    #define IDR_MAINMENU                    102
    #define ID_FILE_EXIT                    40001
    #define ID_FILE_NEW                     40002
    #define ID_FILE_OPEN                    40003
    #define ID_FILE_SAVEAS                  40005
    #define ID_WINDOW_CASCADE               40008
    #define ID_WINDOW_TILE                  40009
    #define ID_FILE_CLOSE                   40010
    #define ID_FILE_CLOSEALL                40011
    #define ID_EDIT_CUT                     40015
    #define ID_EDIT_COPY                    40016
    #define ID_EDIT_PASTE                   40017
    
    // Next default values for new objects
    // 
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE        101
    #define _APS_NEXT_COMMAND_VALUE         40020
    #define _APS_NEXT_CONTROL_VALUE         1000
    #define _APS_NEXT_SYMED_VALUE           101
    #endif
    #endif
    app_four.rc
    Code:
    //Microsoft Developer Studio generated resource script.
    //
    #include "resource.h"
    
    #define APSTUDIO_READONLY_SYMBOLS
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 2 resource.
    //
    #ifndef __BORLANDC__
    #include "winres.h"
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    #undef APSTUDIO_READONLY_SYMBOLS
    
    /////////////////////////////////////////////////////////////////////////////
    // English (Canada) resources
    
    #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENC)
    #ifdef _WIN32
    LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_CAN
    #pragma code_page(1252)
    #endif //_WIN32
    
    #ifdef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // TEXTINCLUDE
    //
    
    1 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "resource.h\0"
    END
    
    2 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "#ifndef __BORLANDC__\r\n"
        "#include ""winres.h""\r\n"
        "#endif\r\n"
        "\0"
    END
    
    3 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "\r\n"
        "\0"
    END
    
    #endif    // APSTUDIO_INVOKED
    
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // Menu
    //
    
    IDR_MAINMENU MENU DISCARDABLE 
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "&New",                        ID_FILE_NEW
            MENUITEM "&Open...",                    ID_FILE_OPEN
            MENUITEM "Save &As...",                 ID_FILE_SAVEAS, GRAYED
            MENUITEM SEPARATOR
            MENUITEM "&Close",                      ID_FILE_CLOSE, GRAYED
            MENUITEM SEPARATOR
            MENUITEM "E&xit",                       ID_FILE_EXIT
        END
        POPUP "&Edit", GRAYED
        BEGIN
            MENUITEM "C&ut",                        ID_EDIT_CUT
            MENUITEM "&Copy",                       ID_EDIT_COPY
            MENUITEM "&Paste",                      ID_EDIT_PASTE
        END
        POPUP "&Window", GRAYED
        BEGIN
            MENUITEM "&Tile",                       ID_WINDOW_TILE
            MENUITEM "&Cascade",                    ID_WINDOW_CASCADE
        END
    END
    
    #endif    // English (Canada) resources
    /////////////////////////////////////////////////////////////////////////////
    
    
    
    #ifndef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 3 resource.
    //
    
    
    /////////////////////////////////////////////////////////////////////////////
    #endif    // not APSTUDIO_INVOKED

  2. #2
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    PLEASE! IT'S URGENT! I can't get it...

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Don't double post. Don't say your problem is urgent. I find it rude. I also find it rude that you plageurize [relatively popular] code from the internet.

    Now, I see that you have tried to add a menu by using the WNDCLASS::lpszMenuName element. I can't see why that would not work, but there are other methods of applying a menu to your window. You can use the HMENU parameter of CreateWindowEx, and the SetMenu function. See if those work.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    Ok, sorry for being rude. I'm a total newbie, so i thought that i could learn from this project, but it have to work off course. If it doesn't, i'm learning the wrong thing.

    Where should i put mu CreateWindowEx then? And what should i remove from the code?

  5. #5
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    If your a total newbie, then you shouldn't be working with win32 code. If you have no prior C++ experience, you will not understand the code, and not learn.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    i read a bit and maybe i should change
    Code:
    hwnd = CreateWindowEx(
    		0,
    		g_szClassName,
    		"Jinky - Livijnproductions.se",
    		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
    		CW_USEDEFAULT, CW_USEDEFAULT, 480, 320,
    		NULL, NULL, hInstance, NULL);
    I just don't know to what, i tested to set the 2nd NULL, the on before hInstance, to hMenu and HMENU but i just get errors. What am i doing wrong? I still use the same code as above.

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    Quote Originally Posted by Sentral
    If your a total newbie, then you shouldn't be working with win32 code. If you have no prior C++ experience, you will not understand the code, and not learn.
    i hate when people say that. Help me instead, i know i can learn from programs. I did with PHP, and some people say that PHP is harder than C++...

  8. #8
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Quote Originally Posted by Livijn
    i hate when people say that. Help me instead, i know i can learn from programs. I did with PHP, and some people say that PHP is harder than C++...
    Others have already suggested ways for you to fix your code. You don't even know where to look in the code to change it! Also, you cross-posted. PHP is not harder then C++. If you don't want to take the time to learn something correctly, don't expect success.

    Perhaps, you should listen to advice if it's given to you more than once?
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  9. #9
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    Yeah, but i just want to finish this one. I'm trying, right? How should i know which code is worng, etc. It would be fun if someone could help me, nice and slow. With some code...

    I've searched for SetMeny and CreateWindowEx but i haven't got a good result. If you have a good tutorial, please, post it. Or you can just tell me what to do...

  10. #10
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  11. #11
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    I ment about menus...

  12. #12
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    i think i know the problem, i have to link the .rc file...
    but i can only link .lib and .o ...

  13. #13
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    when i have a project in Dev-C++ with these three documents i posted, and i try to compile. It doesn't work. Don't know why, a new document creates by Dev-C++ and it sais:
    Code:
    /* THIS FILE WILL BE OVERWRITTEN BY DEV-C++ */
    /* DO NOT EDIT! */
    
    #include "app.rc"
    Is that the problem? Because if it is, i've got Visual Studio too. But i can't compile with Visual Studio. Only create solution. Annoying...

  14. #14
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    First, Sentral is right. Do console programming first. Second, have you looked at the tutorial links at the top of this board? I think not. Third, have you googled? I think not.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  15. #15
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I'd say both of you guys should just go away if you don't have anything but discouragement to contribute. The definition of your menu resource is within a conditional (#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENC), can't see why that would not evaluate to true but whatever) and full of a bunch of trash. I know I got it to work for me by just using:

    Code:
    #include "resource.h"
    
    
    IDR_MAINMENU MENU DISCARDABLE 
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "&New",                        ID_FILE_NEW
            MENUITEM "&Open...",                    ID_FILE_OPEN
            MENUITEM "Save &As...",                 ID_FILE_SAVEAS, GRAYED
            MENUITEM SEPARATOR
            MENUITEM "&Close",                      ID_FILE_CLOSE, GRAYED
            MENUITEM SEPARATOR
            MENUITEM "E&xit",                       ID_FILE_EXIT
        END
        POPUP "&Edit", GRAYED
        BEGIN
            MENUITEM "C&ut",                        ID_EDIT_CUT
            MENUITEM "&Copy",                       ID_EDIT_COPY
            MENUITEM "&Paste",                      ID_EDIT_PASTE
        END
        POPUP "&Window", GRAYED
        BEGIN
            MENUITEM "&Tile",                       ID_WINDOW_TILE
            MENUITEM "&Cascade",                    ID_WINDOW_CASCADE
        END
    END
    Last edited by Tonto; 01-18-2007 at 06:58 PM.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 04:53 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 01:36 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM
  5. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 04:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21