-2

我目前正在制作一个 win32 应用程序,由于某种原因,当我使用标头保护时,没有什么能像我编写控制台应用程序时那样工作。在我的类文件的顶部,我有一个#ifndef XXX #define XXXXX #endif,我被教导过这是避免多次包含文件所必需的。但是,这使得我的课程都看不到!

我什至不能在 .h 文件中声明一个类并在 .cpp 文件中定义它,.cpp 文件将无法找到类定义!这很奇怪,因为当我右键单击我在 .cpp 文件中编写的类的实例并单击“转到声明”时,它会将我带到正确的 .h 文件!视觉工作室如何带我去它却不知道它在哪里?

这是代码

    //ProgramWindows.h


#ifndef PROGRAMWINDOWS_H
#define PROGRAMWINDOWS_H


#include <Windows.h>
//#include "ProcMainMenu.h"
#include "ProgramDefines.h"



class ProgramWindows
{

private:
    WNDCLASSEX mainwindow;
    WNDCLASSEX doublependulum;
    WNDCLASSEX wavesim2d;
    WNDCLASSEX wavesim3d;
    WNDCLASSEX springsim;
    WNDCLASSEX trajectorysim;


public:
    ProgramWindows();
    WNDCLASSEX & getMainWindow();
    WNDCLASSEX & getDoublePendWindow();
    WNDCLASSEX & get2DWaveWindow();
    WNDCLASSEX & get3DWaveWindow();
    WNDCLASSEX & getSpringWindow();
    WNDCLASSEX & getTrajecWindow();



};



#endif




    //ProgramWindows.cpp
#include <Windows.h>
#include <commctrl.h>

#include "ProgramDefines.h"
#include "ProgramWindows.h"
#include "ProcMainMenu.h"



ProgramWindows::ProgramWindows()
{

    //TODO: initialize all of the window member variables to their respective values that will be used in the program.
     this->mainwindow.cbSize           = sizeof(WNDCLASSEX);
     this->mainwindow.lpfnWndProc      = (WNDPROC) ProcMainMenu;
     this->mainwindow.hInstance        = NULL;
     this->mainwindow.hbrBackground    = BACKGROUNDCOLOR;
     this->mainwindow.lpszClassName    = TEXT("WaveSimMain");

}

WNDCLASSEX & ProgramWindows::getMainWindow() 
{
    return this->mainwindow;
}

//.......... continued




    //ProcMainMenu.h
#ifndef PROCMAINMENU_H
#define PROCMAINMENU_H
/** This is the callback procedure for the main menu window of our program.
 *  From this window, the user is able to start any of the 5 sub-simulation programs
 *  contained in this project. This is basically the callback for the starting point of the
 *  program.
 */
#include <Windows.h>
#include <string>
#include <sstream>
#include <stdio.h>
#include <commctrl.h>


#include "ProgramDefines.h"
#include "ProgramWindows.h"



LRESULT CALLBACK ProcMainMenu( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{

     ProgramWindows *ptrWindows = new ProgramWindows();

    // switch on msg
    switch(msg)
    {



    case WM_CREATE:
        {
            //==========================
            // IMAGES FOR MAIN MENU BELOW
            //==========================

            //main menu title static box and image
            HWND MainMenuTitleBox = CreateWindowEx (NULL, L"STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_BITMAP, 80 , 0, 0, 0, hwnd, 0, NULL, NULL);
            HANDLE MainMenuTitleImage = LoadImage(NULL, L"C://Users//John//Documents//Visual Studio 2012//Projects//CS137 Project//CS137 Project//Pictures//MainMenu", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
            SendMessage(MainMenuTitleBox, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) MainMenuTitleImage);




        }break; //end case WM_CREATE

    case WM_DESTROY:
        {

            delete ptrWindows; // delete the pointer to the ProgramWindows object


        }
        break;// end case WM Destroy


}// end ProcMainMenu




#endif




    //ProgramDefines.h
#ifndef PROGRAMDEFINES_H
#define PROGRAMDEFINES_H

/** This file is used to define aliases for all of the UI elements used in our file.
* In Windows Forms Applications, all UI elements must be represented by a unique interger, to
* allow our code to still be readable, we will define the names of the UI elements here and assign them
* to a unique interger. I don't really like it either, but it's the reccomended way of writing Windows Forms Applications,
* and allows for consistant definitions across all windows in the program
*
*/
#include <Windows.h>
#include <commctrl.h>


//#include "ProgramWindows.h"
//#include "ProcMainMenu.h"



//=========================
//=== COLORS ============
//========================

HBRUSH BACKGROUNDCOLOR = CreateSolidBrush(RGB(0,0,102));// deep blue
HBRUSH TEXTCOLOR = CreateSolidBrush(RGB(255,255,255)); //white  



#endif
4

1 回答 1

2

对不起大家!我在我的一个函数上忘记了一个大括号。这导致一切崩溃,让我遇到可怕的错误

于 2013-10-29T02:26:08.830 回答