Solved

Using a VB ActiveX control in VC++

Posted on 2004-09-01
10
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 11960619
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
ID: 11962364
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
ID: 11962912
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:BigBoss
ID: 11963432
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
ID: 11963443
Sorry, I mean m_Printer.PrintDoc("HP Deskjet xxx");
0
 
LVL 6

Expert Comment

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

Author Comment

by:BigBoss
ID: 11971005
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
ID: 11971646
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
ID: 12097666
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
ID: 12100017
Well, can you please post the errors?
BTW this code works well for me.

Svetlin
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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