C++ (WIN32)使用头保护程序正在使我的程序崩溃

C++ (WIN32)使用头保护程序正在使我的程序崩溃,c++,winapi,C++,Winapi,我目前正在制作一个win32应用程序,由于某些原因,当我使用头保护时,没有任何东西能像我编写控制台应用程序时那样工作。 在我的类文件的顶部,我有一个#ifndef XXX#define XXXXX#endif,我被教导要避免多次包含文件。然而,这使得我的课都看不见了 我甚至不能在.h文件中声明类并在.cpp文件中定义它,.cpp文件将无法找到类定义!这很奇怪,因为当我右键单击在.cpp文件中编写的类的实例并单击“go to declaration”时,它会将我带到右侧的.h文件!VisualSt

我目前正在制作一个win32应用程序,由于某些原因,当我使用头保护时,没有任何东西能像我编写控制台应用程序时那样工作。 在我的类文件的顶部,我有一个#ifndef XXX#define XXXXX#endif,我被教导要避免多次包含文件。然而,这使得我的课都看不见了

我甚至不能在.h文件中声明类并在.cpp文件中定义它,.cpp文件将无法找到类定义!这很奇怪,因为当我右键单击在.cpp文件中编写的类的实例并单击“go to declaration”时,它会将我带到右侧的.h文件!VisualStudio如何带我去它,但不知道它在哪里

这是代码

    //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
//ProgramWindows.h
#ifndef程序Windows\u H
#定义程序窗口
#包括
//#包括“ProcMainMenu.h”
#包括“ProgramDefines.h”
类程序窗口
{
私人:
WNDCLASSEX主窗口;
WNDCLASSEX双摆;
WNDCLASSEX wavesim2d;
WNDCLASSEX wavesim3d;
WNDCLASSEX springsim;
WNDCLASSEX TRACTORYSIM;
公众:
编程窗口();
WNDCLASSEX&getMainWindow();
WNDCLASSEX&getDoublePendWindow();
WNDCLASSEX&get2DWaveWindow();
WNDCLASSEX&get3DWaveWindow();
WNDCLASSEX&getSpringWindow();
WNDCLASSEX&getTrajecWindow();
};
#恩迪夫
//ProgramWindows.cpp
#包括
#包括
#包括“ProgramDefines.h”
#包括“ProgramWindows.h”
#包括“ProcMainMenu.h”
ProgramWindows::ProgramWindows()
{
//TODO:将所有窗口成员变量初始化为程序中将使用的各自值。
此->mainwindow.cbSize=sizeof(WNDCLASSEX);
此->mainwindow.lpfnWndProc=(WNDPROC)ProcMain菜单;
此->mainwindow.hInstance=NULL;
此->mainwindow.hbrBackground=背景颜色;
此->mainwindow.lpszClassName=文本(“WaveSimMain”);
}
WNDCLASSEX&ProgramWindows::getMainWindow()
{
返回此->主窗口;
}
//.......... 继续的
//ProcMainMenu.h
#ifndef PROCMAIN菜单
#定义procmain菜单
/**这是我们程序主菜单窗口的回调过程。
*从该窗口,用户可以启动5个子模拟程序中的任何一个
*包含在本项目中。这基本上是对
*节目。
*/
#包括
#包括
#包括
#包括
#包括
#包括“ProgramDefines.h”
#包括“ProgramWindows.h”
LRESULT回调程序主菜单(HWND HWND,UINT msg,WPARAM WPARAM,LPARAM LPARAM)
{
ProgramWindows*ptrWindows=新的ProgramWindows();
//打开味精
开关(msg)
{
案例WM_创建:
{
//==========================
//下面是主菜单的图片
//==========================
//主菜单标题静态框和图像
HWND MainMenuTitleBox=CreateWindowEx(NULL,L“静态”,NULL,WS|U子对象| WS|U可见| SS|U位图,80,0,0,0,HWND,0,NULL,NULL);
HANDLE MainMenuTitleImage=LoadImage(NULL,L“C://Users//John//Documents//Visual Studio 2012//Project//CS137 Project//Pictures//MainMenu”,图像\位图,0,0,LR\ U LOADFROMFILE);
发送消息(MainMenuTitleBox、STM_SETIMAGE、IMAGE_位图、(LPRAM)MainMenuTitleImage);
}break;//结束案例WM\u CREATE
案例WM_销毁:
{
delete ptrWindows;//删除指向ProgramWindows对象的指针
}
break;//结束情况WM Destroy
}//结束程序主菜单
#恩迪夫
//程序定义.h
#ifndef程序定义
#定义程序定义
/**此文件用于为文件中使用的所有UI元素定义别名。
*在Windows窗体应用程序中,所有UI元素都必须由唯一的整数表示,以便
*允许我们的代码仍然可读,我们将在这里定义UI元素的名称并分配它们
*我也不太喜欢它,但这是一种新的编写Windows窗体应用程序的方式,
*并允许程序中所有窗口的定义保持一致
*
*/
#包括
#包括
//#包括“ProgramWindows.h”
//#包括“ProcMainMenu.h”
//=========================
//==颜色============
//========================
HBRUSH BACKGROUNDCOLOR=CreateSolidBrush(RGB(0,0102));//深蓝色
HBRUSH TEXTCOLOR=CreateSolidBrush(RGB(255255255));//白色
#恩迪夫

对不起,伙计们!我的一个函数上忘记了一个括号。这导致了所有东西都崩溃,并且让我得到了可怕的错误

都德-向我们展示一个“不工作”的防护装置。您应该能够在头文件(.h)中定义类。只有.h文件有防护装置。源文件(.cpp)文件#include是标题。它应该都“正常工作”。我怀疑问题可能是您的.h中的语法。听起来您可能在每个标头中使用了相同的include-guard。除了包含的第一个标头之外,所有代码都可能被ifdef。我肯定在.h文件中只使用了#ifndef、#define、#endif,并且我肯定在每个标头gaurd中使用了不同的名称。我以为我在做cyclin包括但我没有,我得到了一些该死的神秘错误你没有错误地使用ifdef,是吗?:)绝对没有使用ifdef