Click here to Skip to main content
15,890,973 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Sending bytes in a time window Pin
Rage20-Feb-06 22:50
professionalRage20-Feb-06 22:50 
QuestionDataSets & TableAdapters Pin
monrobot1320-Feb-06 12:57
monrobot1320-Feb-06 12:57 
QuestionQuestion about console windows Pin
nachilau20-Feb-06 10:34
nachilau20-Feb-06 10:34 
AnswerRe: Question about console windows Pin
Rage20-Feb-06 22:49
professionalRage20-Feb-06 22:49 
GeneralRe: Question about console windows Pin
nachilau21-Feb-06 19:52
nachilau21-Feb-06 19:52 
QuestionData and graphs Pin
thierrypp20-Feb-06 10:29
thierrypp20-Feb-06 10:29 
AnswerRe: Data and graphs Pin
Rage20-Feb-06 22:48
professionalRage20-Feb-06 22:48 
QuestionVC++ Managed Code and OnPaint Problem Pin
syedfasih20-Feb-06 9:36
syedfasih20-Feb-06 9:36 
Smile | :) I am developing VC++ Application using Managed Extensions in visual Studio .NET 2003. I have selected the .NET Console Application Template for this and included the necessary namespaces and dll files. Th problem I am being facing is: OnPaint Event Handler is not working (!unresolved link externals). How do I resolve this? I am pasting the code below.

#include "stdafx.h"

#using <mscorlib.dll>
using namespace System;

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#using <system.dll>
#using <system.drawing.dll>
#using <system.windows.forms.dll>

using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System::Drawing::Imaging;

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Managed class subjected to Garbage Collector indicated by __gc keyword
__gc class MyForm:public Form
{
public:
//Constructor
MyForm();

protected:
//When the form is to be re-painted the OnPaint() event handler will be invoked
void OnPaint(PaintEventArgs *e);

private:
//To display graphic file on the we must use Bitmap Class object like:
Bitmap *m_Bitmap;

// Event handlers for the Menu Commands
void OnMnuOpen(Object* sender, EventArgs *e);
void OnMnuSave(Object* sender, EventArgs *e);
void OnMnuExit(Object* sender, EventArgs *e);
};

//Constructor
MyForm::MyForm()
{
//Creating Menu for the form (Object of MainMenu type)
MainMenu *mnu = new MainMenu();

//Creating Menu Items (Object of MenuItem type)
MenuItem *item = mnu->MenuItems->Add("File");

/*
Creating the options that appear under the File menu and add them to
File MenuItem
*/
item->MenuItems->Add("Open",new EventHandler(this,&MyForm::OnMnuOpen));
item->MenuItems->Add("SaveAs",new EventHandler(this,&MyForm::OnMnuSave));
item->MenuItems->Add("Exit",new EventHandler(this,&MyForm::OnMnuExit));

/*
The entire menu has been created but it will will be visible only when its
reference is passed to the menu property of the form, which is done by the
line of code below i.e. this->Menu = mnu;
*/
this->Menu = mnu;
}
void MyForm::OnMnuOpen(Object* sender, EventArgs *e)
{
//using Windows Open Dialog Box
OpenFileDialog *Odlg = new OpenFileDialog();
Odlg->Filter = Odlg->Filter->Concat((String *)"Image Files(JPEG, GIF, BMP, etc.)|*.jpg; *.gif; *.bmp; *.tif; *.tiff; *.png");
Odlg->Filter = Odlg->Filter->Concat(Odlg->Filter,"|JPEG Files (*.jpg; *.jpeg)| *.jpg; *.jpeg");
Odlg->Filter = Odlg->Filter->Concat(Odlg->Filter,"|GIF Files (*.gif)|*.gif");
Odlg->Filter = Odlg->Filter->Concat(Odlg->Filter,"|BMP Files (*.bmp)|*.bmp");
Odlg->Filter = Odlg->Filter->Concat(Odlg->Filter,"|TIFF Files (*.tif; *.tiff)| *.tif; *.tiff");
Odlg->Filter = Odlg->Filter->Concat(Odlg->Filter,"|PNG Files (*.png)|*.png");
Odlg->Filter = Odlg->Filter->Concat(Odlg->Filter,"|All Files (*.*)|*.*");

Odlg->FilterIndex = 3;

// Handling the click OK of the Dialog
if((Odlg->ShowDialog()) == DialogResult::OK)
{
String *fileName = Odlg->FileName;
if(fileName->Length != 0)
{
try
{
m_Bitmap = new Bitmap(fileName);
AutoScroll = true;
AutoScrollMinSize = m_Bitmap->Size;
Invalidate();
}
catch(Exception *e)
{
MessageBox::Show("Invalid image format", "ERROR");
}
}
}
}

void MyForm::OnMnuSave(Object* sender, EventArgs *e)
{
SaveFileDialog *Sdlg = new SaveFileDialog();
Sdlg->Filter = "JPEG Files(*.jpg; *.jpeg)|*.jpg; *.jpeg |GIFF Files(*.gif)|*.gif|BMP Files(*.bmp)|*.bmp|TIFF Files(*.tif; *.tiff)|*.tif; *.tiff";
if(Sdlg->ShowDialog() == DialogResult::OK)
{
String *SaveStr;
/*
FilterIndex refers to the index of the file types in the filter string
that is currently selected by the user
*/
//Getting the Index of the selected file type in the filter
int index = Sdlg->FilterIndex;

//Getting the File name typed by the user
SaveStr = Sdlg->FileName;

switch(index)
{
case 1:
m_Bitmap->Save(SaveStr,ImageFormat::Jpeg);
break;
case 2:
m_Bitmap->Save(SaveStr,ImageFormat::Gif);
break;
case 3:
m_Bitmap->Save(SaveStr,ImageFormat::Bmp);
break;
case 4:
m_Bitmap->Save(SaveStr,ImageFormat::Tiff);
break;
}
}
}

void MyForm::OnMnuExit(Object* sender,EventArgs *e)
{
this->Close();
}

int _tmain()
{
Application::Run(new MyForm());
return 0;
}

Syed Fasih
AnswerRe: VC++ Managed Code and OnPaint Problem Pin
Maximilien20-Feb-06 10:26
Maximilien20-Feb-06 10:26 
GeneralRe: VC++ Managed Code and OnPaint Problem Pin
syedfasih21-Feb-06 11:30
syedfasih21-Feb-06 11:30 
QuestionAccessing Office Functions from user defined applications Pin
zeeshan fahim20-Feb-06 8:46
zeeshan fahim20-Feb-06 8:46 
QuestionRe: Accessing Office Functions from user defined applications Pin
David Crow20-Feb-06 8:57
David Crow20-Feb-06 8:57 
AnswerRe: Accessing Office Functions from user defined applications Pin
chetanprakash20-Feb-06 19:19
chetanprakash20-Feb-06 19:19 
GeneralRe: Accessing Office Functions from user defined applications Pin
David Crow21-Feb-06 2:41
David Crow21-Feb-06 2:41 
QuestionSaving Data to File Pin
BeakX20-Feb-06 7:57
BeakX20-Feb-06 7:57 
AnswerRe: Saving Data to File Pin
David Crow20-Feb-06 8:09
David Crow20-Feb-06 8:09 
GeneralRe: Saving Data to File Pin
georgeraafat20-Feb-06 9:03
georgeraafat20-Feb-06 9:03 
GeneralRe: Saving Data to File Pin
David Crow20-Feb-06 9:14
David Crow20-Feb-06 9:14 
GeneralRe: Saving Data to File Pin
Aqueel20-Feb-06 17:19
Aqueel20-Feb-06 17:19 
GeneralRe: Saving Data to File Pin
David Crow21-Feb-06 2:27
David Crow21-Feb-06 2:27 
AnswerRe: Saving Data to File Pin
ThatsAlok20-Feb-06 18:28
ThatsAlok20-Feb-06 18:28 
QuestionEditor Pin
haba-baba20-Feb-06 5:47
haba-baba20-Feb-06 5:47 
AnswerRe: Editor Pin
Rage20-Feb-06 5:52
professionalRage20-Feb-06 5:52 
GeneralRe: Editor Pin
haba-baba20-Feb-06 9:11
haba-baba20-Feb-06 9:11 
AnswerRe: Editor Pin
James Brown20-Feb-06 7:31
James Brown20-Feb-06 7:31 

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.