Solved

Using a VB ActiveX control in VC++

Posted on 2004-09-01
10
281 Views
Last Modified: 2010-04-24
Hello experts,

If the task below is possible to achieve and someone can give me some sample code and the procedure to add the control to the project, I will give him 100 points with grade A.

First, I have no knowledge of VC++ at all.
I want to use an ActiveX control (user control) that is developed in VB (Visual Basic), into VC++ (not VC++ .net). Is this possible?
If yes, can anyone give me some sample code (and how to add the control to the project) for using this Smart Print Control ( from http://www.vbgold.com ).
What I need is just to specify the document title and body, and the font name and size and call the PrintDoc method to print the document.
Can anyone help please?

Thank you.
0
Comment
Question by:BigBoss
  • 5
  • 5
10 Comments
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
Comment Utility
Well I'll try to explain it step-by-step:
First - create your VC++ project (MFC Application, Dialog based).Add your ActiveX control to the dialog (right click on the dialog and choose Insert ActiveX control).
Then right click again and select Class Wizard - and go to "Member Variables".In the control ID box select your control ID (probably IDC_SPRINTER1) and click Add variable. Name it m_Printer.
After adding it double click on the OK button in your dialog.There you should have code like:

void CPrintDlg::OnOK()
{
      m_Printer.SetDocText("Your text");
      m_Printer.SetDocTitle("Your title");
      m_Printer.PrintDoc("PrinterName");
}

And...that's all :)

Svetlin
0
 

Author Comment

by:BigBoss
Comment Utility
Svetlin_Panayotov...thank you for your help.
I did exactly what you said but I couldn't make it to print. Of course I changed the "PrinterName" to a valid one.
When I click on the OK button, nothing gets out of the printer!!
I tried to check if it does something, so I replaced the  m_Printer.PrintDoc("PrinterName");  with  m_Printer.About(); and it does show the About dialog when I click the button!
Did you checked whether it really prints or not in your VC++?
If it works for you, can you send me the project please?

Thank you.
0
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
Comment Utility
Sorry - my mistake here - the method PrintDoc() needs a parameter that's actually your printer's name - so instead
m_Printer.PrintDoc("Printer name");
you should have something like:
      CPrintDialog pr(FALSE);
      CString s = pr.GetDeviceName();
      int iResult = pr.DoModal();
                if (iResult == IDCANCEL)
                       return;
      m_Print.PrintDoc(s);

Svetlin

0
 

Author Comment

by:BigBoss
Comment Utility
Thank you Sveltin....but I gave the printer name hardcoded and it didn't print!
I used something like m_Print.PrintDoc("HP Deskjet xxx");
Does this work? or must I use your code?

Thank you.
0
 

Author Comment

by:BigBoss
Comment Utility
Sorry, I mean m_Printer.PrintDoc("HP Deskjet xxx");
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 6

Expert Comment

by:Svetlin_Panayotov
Comment Utility
Well - hardcoding your printer's name is generally not good idea - so it's better to use CPrintDialog
0
 

Author Comment

by:BigBoss
Comment Utility
OK...thanks Sveltin.

Sorry, but you didn't answer my previous question!
Did you test the control in your VC and got it to print?
It does not print here!!! :-(
Am I missing something? Or is this control incompatible with VC++?
If you've got it to print, can you send me a sample project please?

Thank you for your help.
0
 
LVL 6

Accepted Solution

by:
Svetlin_Panayotov earned 50 total points
Comment Utility
Yes - I tested it with VC6 and the code I sent you(with CPrintDialog) - and it wokrs fine.Here's the code
again:

void CTestDlg::OnOK()
{
      CPrintDialog pr(FALSE);
      int iResult = pr.DoModal();
      if (iResult == IDCANCEL)
            return;
      CString sPrinterName = pr.GetDeviceName();
      m_Print.SetDocText("Some text");
      m_Print.SetDocTitle("Title");
      m_Print.PrintDoc(sPrinterName);
}

just replace CTestDlg with the name of your dialog - or copy only the code from the method
Svetlin
0
 

Author Comment

by:BigBoss
Comment Utility
OK...thanks...it worked, but only the second part!

The first part (below) is not working!

     CPrintDialog pr(FALSE);
     int iResult = pr.DoModal();
     if (iResult == IDCANCEL)
          return;
     CString sPrinterName = pr.GetDeviceName();

I was getting errors on compilation!
0
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
Comment Utility
Well, can you please post the errors?
BTW this code works well for me.

Svetlin
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now