Click here to Skip to main content
15,902,896 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralWinSock ports Pin
prophets_lie16-Jan-05 18:05
prophets_lie16-Jan-05 18:05 
GeneralHowTo shut up Output messages Pin
Gammill15-Jan-05 13:49
Gammill15-Jan-05 13:49 
GeneralRe: HowTo shut up Output messages Pin
Gammill18-Jan-05 9:25
Gammill18-Jan-05 9:25 
GeneralTutorials on User Controls in MC++ Pin
harrykouk15-Jan-05 9:59
harrykouk15-Jan-05 9:59 
GeneralRe: Tutorials on User Controls in MC++ Pin
Gammill15-Jan-05 13:42
Gammill15-Jan-05 13:42 
Generalunmanaged template Pin
enouk14-Jan-05 8:19
enouk14-Jan-05 8:19 
GeneralCalling CDialog C++ code from C# Pin
gabnicu13-Jan-05 23:52
gabnicu13-Jan-05 23:52 
GeneralUsing a CWnd from a .NET System::Windows::Forms::UserControl Pin
lfmacias12-Jan-05 6:53
lfmacias12-Jan-05 6:53 
Hi everyone

First it all,I've created a Windows Control Libray (.NET) Control using C++.
second : There is a great library call SDL (simple Direct Layer)

Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. It is used by MPEG playback software, emulators, and many popular games, including the award winning Linux port of "Civilization: Call To Power."

SDL oftently is used for games

SDL supply C methods in order to able to create Windows a interact with them. when SDL starts always create a new Window where anything like show a game o graphics could happen.

SDL needs Initializing methods such as :

/* Initialize SDL */
SDL_Init(SDL_INIT_VIDEO)
/* Set the video mode */
SDL_SetVideoMode(SCREEN_X, SCREEN_Y, 0, SDL_SWSURFACE);

So when SD_SetVideoMode executes a new Wiwdow is created, but I don't want a new
emerging Wiwdow behing I want that the new SDL window created appears completely embedded inside my .NET control.

I Though the solution will would be, change the parent for the SDL Window to
Control, i couldn't do that.

SDL provides methods for getting the HANDLE for the new Window created :

HWND GetWindowHandle()
{
#ifdef WIN32
SDL_SysWMinfo wmi;
SDL_VERSION(&wmi.version);
if(SDL_GetWMInfo(&wmi) == 0)
{
return NULL;
}
else
{
return wmi.window;
}
#else
return NULL;
#endif
}

At this moment i have a component used in a Forms Application that used myControl, but when I exetute this the Windows Forms appears, my component appears too, but the SDL window appear behind.


Here is the code for the .H file


#pragma once

#include "SDL.h"
#include "SDL_syswm.h"
#include "SDL_events.h"
#include <stdio.h>
#include <limits.h>#include <stdlib.h>
//#include <afxwin.h>
#include <windows.h>




#define SCREEN_X 300
#define SCREEN_Y 200


using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


namespace cubecontrol
{
///
/// Summary for cubecontrolControl
///

///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
public __gc class cubecontrolControl : public System::Windows::Forms::UserControl
{
public:
cubecontrolControl(void)
{
InitializeComponent();
}

protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}

private:
///
/// Required designer variable.
///

System::ComponentModel::Container* components;

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

void InitializeComponent(void)
{

//
// cubecontrolControl
//
this->Name = S"cubecontrolControl";
this->Size = System::Drawing::Size(440, 288);


int done;
SDL_Event event;
/* Initialize SDL */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
//fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
//cout(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
//exit(1);
}

//atexit(SDL_Quit);

/* Set the video mode */
screen = SDL_SetVideoMode(SCREEN_X, SCREEN_Y, 0, SDL_SWSURFACE);
if ( screen == NULL ) {
//fprintf(stderr, "Couldn't set video mode: %s\n",SDL_GetError());
//exit(1);
}

//CWnd window;
//HWND h;
System::Windows::Forms::Control* c ;
System::Windows::Forms::Form* f;
/*window= */ /*CWnd::*///FromHandle(GetWindowHandle())->Parent=this;
c = FromHandle(GetWindowHandle());



}


HWND GetWindowHandle()
{
#ifdef WIN32
SDL_SysWMinfo wmi;
SDL_VERSION(&wmi.version);
if(SDL_GetWMInfo(&wmi) == 0)
{
return NULL;
}
else
{
return wmi.window;
}
#else
return NULL;
#endif
}


static SDL_Surface *screen;

};
}


Thanks in advance for any help someones could give me
Generaldelete question Pin
Yaakov Davis12-Jan-05 1:08
Yaakov Davis12-Jan-05 1:08 
GeneralRe: delete question Pin
Steve Maier1-Feb-05 10:18
professionalSteve Maier1-Feb-05 10:18 
GeneralFlash and MFC HELP! Pin
FayezElFar11-Jan-05 11:00
FayezElFar11-Jan-05 11:00 
GeneralRe: Flash and MFC HELP! Pin
Christian Graus11-Jan-05 14:35
protectorChristian Graus11-Jan-05 14:35 
GeneralRe: Flash and MFC HELP! Pin
Uwe Keim23-Jan-05 1:48
sitebuilderUwe Keim23-Jan-05 1:48 
GeneralRe: Flash and MFC HELP! Pin
Christian Graus23-Jan-05 9:58
protectorChristian Graus23-Jan-05 9:58 
GeneralObject disposed in Finalize method Pin
Member 134623511-Jan-05 6:24
Member 134623511-Jan-05 6:24 
GeneralAccessing Unmanaged C++ from C# Pin
jstedman11-Jan-05 5:54
jstedman11-Jan-05 5:54 
Generalrtf help Pin
Mohammad Daba'an10-Jan-05 22:28
Mohammad Daba'an10-Jan-05 22:28 
GeneralRe: rtf help Pin
Christian Graus11-Jan-05 14:37
protectorChristian Graus11-Jan-05 14:37 
Generaladding to integers together... help please!!! Pin
alexy2u8-Jan-05 8:44
alexy2u8-Jan-05 8:44 
GeneralRe: adding to integers together... help please!!! Pin
Christian Graus8-Jan-05 16:00
protectorChristian Graus8-Jan-05 16:00 
GeneralRe: adding to integers together... help please!!! Pin
FayezElFar11-Jan-05 11:04
FayezElFar11-Jan-05 11:04 
GeneralRe: adding to integers together... help please!!! Pin
prophets_lie16-Jan-05 18:17
prophets_lie16-Jan-05 18:17 
GeneralRe: adding to integers together... help please!!! Pin
Anders Dalvander29-Jan-05 1:25
Anders Dalvander29-Jan-05 1:25 
Generalsetup wizard Pin
Boniolopez8-Jan-05 4:48
Boniolopez8-Jan-05 4:48 
GeneralC++ arrays Pin
Ail6-Jan-05 9:19
Ail6-Jan-05 9:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.