Thread: Menu problems

  1. #1
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Menu problems

    Just when I thought I was beginning to understand...

    Another problem from this tutorial, http://sunlightd.virtualave.net/Windows/GUI/

    I don't understand why I'm having trouble with the Menu
    I did a search here and found this link: http://www.praxis1.vic.edu.au/home/dcola/teeeee.zip but my browser can't navigate to it. Site problems maybe?


    How can these following errors say 'undeclared identifier'.

    Don't I have it entered right?

    Anyway here are the errors I'd really appreciate any pointers:

    c:\programming\tutorials\sunlight tutorial\win apps\complete app\complete app.cpp(109) : error C2065: 'ID_OPEN' : undeclared identifier
    c:\programming\tutorials\sunlight tutorial\win apps\complete app\complete app.cpp(109) : error C2051: case expression not constant
    c:\programming\tutorials\sunlight tutorial\win apps\complete app\complete app.cpp(120) : error C2065: 'ID_EXIT' : undeclared identifier
    c:\programming\tutorials\sunlight tutorial\win apps\complete app\complete app.cpp(120) : error C2051: case expression not constant
    c:\programming\tutorials\sunlight tutorial\win apps\complete app\complete app.cpp(123) : warning C4060: switch statement contains no 'case' or 'default' labels
    c:\programming\tutorials\sunlight tutorial\win apps\complete app\complete app.cpp(166) : error C2065: 'IDR_MAIN' : undeclared identifier

    Error executing cl.exe.
    Complete App.exe - 5 error(s), 1 warning(s)




    and this is my Resource.h file

    //{{NO_DEPENDENCIES}}
    // Microsoft Developer Studio generated include file.
    // Used by ResourceCompleteApp.rc
    //
    #define IDD_DIALOG1 101
    #define IDR_MAIN 102
    #define IDC_FILE 1000
    #define IDC_BROWSE 1001
    #define IDC_VIEW 1002
    #define ID_EXIT 40002
    #define ID_OPEN 40004

    // Next default values for new objects
    //
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE 104
    #define _APS_NEXT_COMMAND_VALUE 40005
    #define _APS_NEXT_CONTROL_VALUE 1003
    #define _APS_NEXT_SYMED_VALUE 101
    #endif
    #endif


    'code snippet' all include it all if you like.

    Code:
    BOOL MainWindow_OnCommand(HWND hWnd, WORD wCommand, 
    
    WORD wNotify, HWND hControl)
    {
    	switch (wCommand)
    	{
    	case ID_OPEN:
    
    		if (hBitmap != NULL)
    			DeleteObject(hBitmap);
    
    		GetBitmapFileName(szBitmapFilename, sizeof(szBitmapFilename) / sizeof(TCHAR), hWnd);
    		hBitmap = LoadBitmapFile(szBitmapFilename);
    		RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
    		break;
    
    	case ID_EXIT:
    		DestroyWindow(hWnd);
    		break;
    	}
    	return TRUE;
    }

  2. #2
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Cannot open include file: 'resource.h': No such file or directory

    I've fixed several problems in my code. Now my only error is: Cannot open include file: 'resource.h': No such file or directory
    Error executing cl.exe.

    Any Ideas?

    MSVC++6, Win XP.

    Code:
    // Bit Map Viewer
    #include <windows.h>
    #include <tchar.h>
    #include <stdio.h>
    
    #include "resource.h"
    
    TCHAR	szBitmapFilename[_MAX_PATH];
    HBITMAP	hBitmap;
    HWND hWndMain;
    
    ///////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////			Function Prototypes			///////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////
    
    void RegisterWindowClass();
    BOOL GetBitmapFileName(TCHAR *filename, int len, HWND hWnd);
    HBITMAP LoadBitmapFile(const TCHAR *filename);
    BOOL MainWindow_OnCommand(HWND hWnd, WORD wCommand, WORD wNotify, HWND hControl);
    void MainWindow_OnPaint(HWND hWnd, HDC hDC);
    //BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    //LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    
    
    ///////////////////////////////////////////////////////////////////////////////////////
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) 
    {
    	MSG	msg;
    
    	RegisterWindowClass();
    
    	hWndMain = CreateWindowEx(WS_EX_APPWINDOW,
    		"SampleWindowClass", _T("Bitmap Viewer II"), WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
    		NULL, NULL, hInstance, NULL);
    	
    	ShowWindow(hWndMain, SW_SHOW);
    
    	while (GetMessage(&msg, NULL, 0, 0))
    		DispatchMessage(&msg);
    
    	return 0;
    }
    
    ///////////////////////////////////////////////////////////////////////////////////////
    
    BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	PAINTSTRUCT	ps;
    	HDC		hDC;
    
    	switch (uMsg)
    	{
    		case WM_COMMAND:
    		return MainDialog_OnCommand(hWnd, LOWORD(wParam),
    			HIWORD(wParam), (HWND)lParam);
    
    		case WM_PAINT:
    			hDC = BeginPaint(hWnd, &ps);
    			MainDialog_OnPaint(hWnd, hDC);
    			EndPaint(hWnd, &ps);
    			return TRUE;
    
    		case IDCANCEL:
    			DestroyWindow(hWnd);
    			break;
    
    
    		case WM_CLOSE:
    			DestroyWindow(hWnd);
    			return TRUE;
    	}
    	return FALSE;
    }
    
    ///////////////////////////////////////////////////////////////////////////////////////
    
    BOOL GetBitmapFileName(TCHAR *filename, int len, HWND hWnd)
    {
    	OPENFILENAME	ofn;
    
    	ZeroMemory(&ofn, sizeof(OPENFILENAME));
    	ofn.lStructSize = sizeof(OPENFILENAME);
    	ofn.hwndOwner = hWnd;
    	ofn.lpstrFilter = _T("Bitmap Files (*.bmp)\0*.bmp\0All Files (*.*)\0*.*\0\0");
    	ofn.lpstrFile = filename;
    	ofn.nMaxFile = len;
    	ofn.lpstrTitle = _T("Browse");
    	ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    	return GetOpenFileName(&ofn);
    }
    
    ///////////////////////////////////////////////////////////////////////////////////////
    
    HBITMAP LoadBitmapFile(const TCHAR *filename)
    {
    	return (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    }
    
    ///////////////////////////////////////////////////////////////////////////////////////
    
    LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	PAINTSTRUCT	ps;
    	HDC		hDC;
    
    	switch (uMsg)
    	{
    	case WM_COMMAND:
    		MainWindow_OnCommand(hWnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam);
    		return 0;
    
    	case WM_PAINT:
    		hDC = BeginPaint(hWnd, &ps);
    		MainWindow_OnPaint(hWnd, hDC);
    		EndPaint(hWnd, &ps);
    		return 0;
    
    	case WM_CLOSE:
    		DestroyWindow(hWnd);
    		return 0;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    	}
    	return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    
    //////////////////////////////////////////////////////////////////////////////////////
    
    void MainWindow_OnPaint(HWND hWnd, HDC hDC)
    {
    	if (hBitmap == NULL)
    		return;
    
    	DrawState(hDC, NULL, NULL, (LPARAM)hBitmap, 0, 0, 0, 0, 0, DST_BITMAP | DSS_NORMAL);
    }
    
    //////////////////////////////////////////////////////////////////////////////////////
    
    void RegisterWindowClass()
    {
    	WNDCLASSEX	wcx;
    
    	ZeroMemory(&wcx, sizeof(WNDCLASSEX));
    	wcx.cbSize = sizeof(WNDCLASSEX);
    	wcx.lpfnWndProc = MainWindowProc;
    	wcx.hInstance = GetModuleHandle(NULL);
    	wcx.hIcon = LoadIcon(wcx.hInstance, MAKEINTRESOURCE(IDR_MAIN));
    	wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    	wcx.lpszClassName = "SampleWindowClass";
    	wcx.lpszMenuName = MAKEINTRESOURCE(IDR_MAIN);
    	RegisterClassEx(&wcx);
    }
    
    //////////////////////////////////////////////////////////////////////////////////////
    
    BOOL MainWindow_OnCommand(HWND hWnd, WORD wCommand, WORD wNotify, HWND hControl)
    {
    	switch (wCommand)
    	{
    	case ID_OPEN:
    
    		if (hBitmap != NULL)
    			DeleteObject(hBitmap);
    
    		GetBitmapFileName(szBitmapFilename, 
    			sizeof(szBitmapFilename) / sizeof(TCHAR), hWnd);
    		hBitmap = LoadBitmapFile(szBitmapFilename);
    		RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
    		break;
    
    	case ID_EXIT:
    		DestroyWindow(hWnd);
    		break;
    	}
    	return TRUE;
    }

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Try checking the working folder settings

    Project -> Settings

    Click the Debug tab,

    ensure the folder containing 'resource.h' is the one listed in the 'working directory' edit (not the 'executable for debug session' edit)

    repeat for the release.

    or

    supply the full path to the file in the #include
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Just a thought. Did you try to remove resource.h from the project then re-add it? Sometimes i would have this problem with VC6 but it stoped that when I finally downloaded SP5.

  5. #5
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    I am so frustrated!

    Nope, I still am having problems. Oh well I'll keep trying. You guys have any other ideas?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a menu that reads input via an array?
    By Nalif in forum C Programming
    Replies: 6
    Last Post: 09-29-2006, 09:21 PM
  2. menu - options Problems
    By wakish in forum C Programming
    Replies: 3
    Last Post: 07-05-2006, 03:23 AM
  3. Problems with a menu
    By L_U_K_E in forum C++ Programming
    Replies: 27
    Last Post: 04-28-2006, 10:45 AM
  4. Problems with my menu
    By Olidivera in forum Windows Programming
    Replies: 2
    Last Post: 07-07-2005, 12:44 PM
  5. Menu stuff
    By Shadow in forum C Programming
    Replies: 10
    Last Post: 04-28-2002, 09:05 AM