Hi its me again with a WIN32 question
now my program compiles beatifully without giving any errors at comile time & run time
but the thing is , I dont get to see any window.. it just runs and inmediately after the program closes by itself returning me to the compiler
heres the code
//---------------------------------------------
//cApplication.h
//Creates and register main application window
//
//Armando Alva@2005
//---------------------------------------------
#ifndef _CAPPLICATION_H__
#define _CAPPLICATION_H__
#include <windows.h>
class cApplication
{
public:
// WIN32 API Variables - Made Public for easy access
HWND hWnd;
HINSTANCE hInstance;
MSG msg;
WNDCLASSEX wcex;
cApplication();
~cApplication();
// Class Methods
void RegisterApp();
void CreateApp();
void ShowError(char*);
private:
// Nothing
};
#endif _CAPPLICATION_H__
//---------------------------------------------
//cApplication.cpp
//Class Implementation File
//
//Armando Alva@2005
//---------------------------------------------
#include "cApplication.h"
//
LRESULT CALLBACK MsgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
//
// Constructor //
cApplication::cApplication()
{
RegisterApp();
CreateApp();
}
// Destructor //
cApplication::~cApplication()
{
// Do Nothing (for now)
}
//---------------------------------------------
// RegisterApp()
// registers main window settings
//---------------------------------------------
void cApplication::RegisterApp()
{
// Register Window class
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = 0;
wcex.lpfnWndProc = MsgProc; //POINTS TO THE MESSAGE PROCEDURE FUNCTION VERY IMPORTANT DO NOT FORGET
wcex.cbWndExtra = 0;
wcex.cbClsExtra = 0;
wcex.hInstance = hInstance; //GetModuleHandle(NULL); // Must be related with WinMain HINSTANCE var
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "Game Class";
// check for registration errors
if(!RegisterClassEx(&wcex)) //RegisterCLassEx if failed returns 0
{
ShowError("Window Registration Error!");
//return 0;
}
}
//---------------------------------------------
// CreateApp()
// creates already registered window
//---------------------------------------------
void cApplication::CreateApp()
{
hWnd = CreateWindowEx(NULL, "Game Class", "Double Dragon Clone",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
NULL, NULL, wcex.hInstance, NULL);
// check for creation errors
if(hWnd == NULL)
{
ShowError("Window Creation Error!");
//return 0;
}
//return 0;
}
//---------------------------------------------
// ShowError(*char)
// Shows Messagebox with desired text
//---------------------------------------------
void cApplication::ShowError(char* error)
{
MessageBox(NULL, error, "Error!", MB_OK);
}
// WinMain Test
#include <windows.h>
#include "cApplication.h"
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
cApplication testwin;
return 0;
}