Quantcast
Channel: CodeGuru Forums
Viewing all 12179 articles
Browse latest View live

How to Print an ASP.NET Local Report RDLC without Preview or Printer Dialog

$
0
0
How to Print an ASP.NET Local Report RDLC without Preview or Printer Dialog

In this walkthrough, you'll learn how to print a Local Report (RDLC) from an ASP.NET website to the client printer without previewing the report through Visual Studio ReportViewer control. In fact, you'll be able to print the RDLC report without displaying any Printer Dialog at all! And one important thing... it works with any browser on Windows OS like IE (6 or later), Chrome, Firefox, Opera & Safari!

http://www.neodynamic.com/articles/h...int-dialog.jpg
Print RDLC Local Report without Preview or Print Dialog

The sample report is a Local Report RDLC designed to print a product list of the classic and famous MS Northwind Traders database. In a simple ASP.NET webpage, we provide a preview of such report (just for you to know what to expect after printing) and all the needed code in C# and VB to print the report without previewing or displaying any printer dialog by using WebClientPrint for ASP.NET solution

You can print the RDLC local report to the Default client printer as well as to any other installed printer at the client machine.

Requirements
- WebClientPrint 2.0 for ASP.NET (or greater)
- ASP.NET 3.5 (or greater)
- Visual Studio 2010 / VWD 2010 (or greater)
- jQuery 1.4.1 (or greater)
- WebClientPrint Processor 2.0 for Windows & Adobe Reader need to be installed at the client machine

NOTE: In this guide we used VS 2010 and ASP.NET 3.5 but the same code & concept can be applied to VS 2005/2008 and ASP.NET 2.0 as well as VS 2012 and ASP.NET 4.x

Follow up these steps
- Download and install WebClientPrint for ASP.NET
- Open Visual Studio and create a new ASP.NET 3.5 Website naming it PrintRDLCReport
- Add a reference to Neodynamic.SDK.WebClientPrint.dll to your project
- Open your web.config file and add the following entries:

<system.web>
<httpHandlers>
<add verb="*" path="wcp.axd" type="Neodynamic.SDK.Web.WebClientPrint, Neodynamic.SDK.WebClientPrint"/>
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="WCP" verb="*" path="wcp.axd" type="Neodynamic.SDK.Web.WebClientPrint, Neodynamic.SDK.WebClientPrint"/>
</handlers>
</system.webServer>

- Open the default.aspx page and paste the following markup. The task of this page is to try to detect the WCPP and ask the user to install it if it's missing.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
body{font: 13px 'Segoe UI', Tahoma, Arial, Helvetica, sans-serif;}
</style>

<%-- WCPP-detection meta tag for IE10 --%>
<%= Neodynamic.SDK.Web.WebClientPrint.GetWcppDetectionMetaTag() %>
</head>
<body>
<form id="form1" runat="server">
<div id="msgInProgress">
<div id="mySpinner" style="width:32px;height:32px"></div>
<br />
Detecting WCPP utility at client side...
<br />
Please wait a few seconds...
<br />
</div>
<div id="msgInstallWCPP" style="display:none;">
<h3>#1 Install WebClientPrint Processor (WCPP)!</h3>
<p>
<strong>WCPP is a native Windows app (without any dependencies!)</strong> that handles all print jobs
generated by the <strong>WebClientPrint ASP.NET component</strong> at the server side. The WCPP
is in charge of the whole printing process and can be
installed on Windows 98, 2000, Me, XP, Vista, Windows 7 and Windows 8 (Desk-mode). It can print to Serial Port RS232 (e.g. COM1),
Parallel Port (e.g. LPT1), your Windows-Installed Printers (USB) and Network/IP Ethernet printers.
</p>
<p>
The <strong>WCPP</strong> utility <strong>is digitally-signed with a Windows Authenticode</strong> issued by <a href="http://www.digicert.com">DigiCert, Inc.</a>. <strong>Install WCPP only if the <u>Publisher is Neodynamic SRL</u></strong>, otherwise do not proceed. <br /><br />
<a href="http://www.neodynamic.com/downloads/wcpp20-installer.exe" target="_blank">Download and Install WCPP from Neodynamic website</a><br />
</p>
<h3>#2 After installing WCPP...</h3>
<p>
<a href="PrintRDLC.aspx">You can go and test WebClientPrint for ASP.NET</a>
</p>
</div>
</form>
<%-- Add Reference to jQuery at Google CDN --%>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<%-- Add Reference to spin.js (an animated spinner) --%>
<script src="http://fgnass.github.io/spin.js/dist/spin.min.js"></script>
<script type="text/javascript">
var wcppPingDelay_ms = 10000;

function wcppDetectOnSuccess(){
<%-- WCPP utility is installed at the client side
redirect to WebClientPrint sample page --%>
<%-- get WCPP version --%>
var wcppVer = arguments[0];
if(wcppVer == "2.0.0.0")
window.location.href = "PrintRDLC.aspx";
else //force to install WCPP v2.0
wcppDetectOnFailure();
}

function wcppDetectOnFailure() {
<%-- It seems WCPP is not installed at the client side
ask the user to install it --%>
$('#msgInProgress').hide();
$('#msgInstallWCPP').show();
}

$(document).ready(function () {
<%-- Create the Spinner with options (http://fgnass.github.io/spin.js/) --%>
var spinner = new Spinner({
lines: 12,
length: 7,
width: 3,
radius: 10,
color: '#336699',
speed: 1,
trail: 60
}).spin($('#mySpinner')[0]);
});

</script>

<%-- WCPP detection script --%>
<%= Neodynamic.SDK.Web.WebClientPrint.CreateWcppDetectionScript() %>

</body>
</html>

The Local Report RDLC we've created for this sample is a simple product list for MS Northwind Traders database and it has an XML data source. The report looks like the following figure.

http://www.neodynamic.com/articles/h...nd-traders.jpg
Sample RDLC report featuring Northwind Traders product list

- Download and copy both MyReport.rdlc & NorthwindProducts.xml files to your website root folder
- Finally, add a new ASPX page and name it PrintRDLC.aspx (be sure to UNSELECT the "Place code in separate file" checkbox)

This page allows your user to print the RDLC report to local printers. It basically converts the report to PDF format and then passes it to the WCPP utility to print it to the specified printer. The user is required to have Adobe Reader installed to get this code working.

Please paste the following markup and code depending on your preferred language i.e. C# or VB on your PrintRDLC.aspx file.

VB
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Neodynamic.SDK.Web" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Init(sender As Object, e As System.EventArgs)
'Print report???
If (WebClientPrint.ProcessPrintJob(Request)) Then
'create PDF version of RDLC report
Dim myReport As New LocalReport()
myReport.ReportPath = "MyReport.rdlc"
Dim ds As New DataSet()
ds.ReadXml(Server.MapPath("~/NorthwindProducts.xml"))
myReport.DataSources.Add(New ReportDataSource("Products", ds.Tables(0)))

'Export to PDF. Get binary content.
Dim pdfContent As Byte() = myReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

'Now send this file to the client side for printing
'IMPORTANT: Adobe Reader needs to be installed at the client side

Dim useDefaultPrinter As Boolean = (Request("useDefaultPrinter") = "checked")
Dim printerName As String = Server.UrlDecode(Request("printerName"))

'create a temp file name for our PDF report...
Dim fileName As String = Guid.NewGuid().ToString("N") + ".pdf"

'Create a PrintFile object with the pdf report
Dim file As New PrintFile(pdfContent, fileName)
'Create a ClientPrintJob and send it back to the client!
Dim cpj As New ClientPrintJob()
'set file to print...
cpj.PrintFile = file
'set client printer...
If (useDefaultPrinter OrElse printerName = "null") Then
cpj.ClientPrinter = New DefaultPrinter()
Else
cpj.ClientPrinter = New InstalledPrinter(printerName)
End If
'send it...
cpj.SendToClient(Response)
End If
End Sub

Protected Sub Page_Load(sender As Object, e As System.EventArgs)
If (IsPostBack = False) Then
'load report in case user want to preview it
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = "MyReport.rdlc"
Dim ds As New DataSet()
ds.ReadXml(Server.MapPath("~/NorthwindProducts.xml"))
ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Products", ds.Tables(0)))
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Print Local Report RDLC without Previewing nor Print Dialog!</title>
<style>
body{font: 13px 'Segoe UI', Tahoma, Arial, Helvetica, sans-serif;background:#ddd;color:#333;margin:0;}
h1{background:#333;color:#fff;padding:10px;font: 29px 'Segoe UI Light', 'Tahoma Light', 'Arial Light', 'Helvetica Light', sans-serif;}
.myRow{width:auto;padding:0 20px 0 20px;height:auto;}
.myMenu{float:left;margin:0 20px 0 0;padding:2px;color:#333;}
.cBlue{border-bottom: 5px solid #6B89B7;}
.cYellow{border-bottom: 5px solid #FCAA25;}
.cSand{border-bottom: 5px solid #CCCC66;}
</style>
</head>
<body>
<%-- Store User's SessionId --%>
<input type="hidden" id="sid" name="sid" value="<%=Session.SessionID%>" />

<form id="form1" runat="server">
<h1>Print Local Report RDLC without Previewing nor Print Dialog!</h1>
<div class="myRow">
<a href="#" onclick="DisplayPanel(0);">
<div class="myMenu cBlue">
<h2>Print Report</h2>
<p>Print the report without previewing it!</p>
</div>
</a>
<a href="#" onclick="DisplayPanel(1);">
<div class="myMenu cYellow">
<h2>Preview Report</h2>
<p>Display the report that will be printed</p>
</div>
</a>

<a href="http://www.neodynamic.com/products/printing/raw-data/aspnet-mvc/" target="_blank">
<div class="myMenu cSand">
<h2>About WebClientPrint</h2>
<p>Know more about WebClientPrint for ASP.NET</p>
</div>
</a>
</div>
<div class="myRow" style="clear:both" id="pnlReport">
<br /><br />
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="450px" Width="790px">
</rsweb:ReportViewer>
</div>
<div class="myRow" style="clear:both;background-color:#e3e3e3;" id="pnlPrintSettings">
<br />
<h3>Print the RDLC sample report.</h3>
<label class="checkbox">
<input type="checkbox" id="useDefaultPrinter"> <strong>Use default printer</strong> or...
</label>
<div id="loadPrinters">
<br />
WebClientPrint can detect the installed printers in your machine.
<br />
<input type="button" onclick="javascript:jsWebClientPrint.getPrinters();" value="Load installed printers..." />
<br /><br />
</div>
<div id="installedPrinters" style="visibility:hidden">
<br />
<label for="installedPrinterName">Select an installed Printer:</label>
<select name="installedPrinterName" id="installedPrinterName"></select>
</div>
<br /><br />

<input type="button" style="font-size:18px" onclick="javascript:jsWebClientPrint.print('useDefaultPrinter=' + $('#useDefaultPrinter').attr('checked') + '&printerName=' + $('#installedPrinterName').val());" value="Print Report..." />

<script type="text/javascript">
var wcppGetPrintersDelay_ms = 5000; //5 sec
function wcpGetPrintersOnSuccess(){
<%-- Display client installed printers --%>
if(arguments[0].length > 0){
var p=arguments[0].split("|");
var options = '';
for (var i = 0; i < p.length; i++) {
options += '<option>' + p[i] + '</option>';
}

$('#installedPrinters').css('visibility','visible');
$('#installedPrinterName').html(options);
$('#installedPrinterName').focus();
$('#loadPrinters').hide();
}else{
alert("No printers are installed in your system.");
}
}

function wcpGetPrintersOnFailure() {
<%-- Do something if printers cannot be got from the client --%>
alert("No printers are installed in your system.");

}
</script>
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</form>
<%-- Add Reference to jQuery at Google CDN --%>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<%-- Register the WebClientPrint script code --%>
<%=Neodynamic.SDK.Web.WebClientPrint.CreateScript()%>
<script type="text/javascript">
$(document).ready(function () {
$('#pnlReport').hide();
});
function DisplayPanel() {
$('#pnlReport').hide();
$('#pnlPrintSettings').hide();
if (arguments[0] == 0) {
$('#pnlPrintSettings').show();
} else if (arguments[0] == 1) {
$('#pnlReport').show();
}
}
</script>
</body>
</html>


- That's it! Run your website and test it. Click on Print Report to print the RDLC report without preview. You can print it to the Default client printer or you can get a list of the installed printers available at the client machine and select one for printing the report.

Links:
This Demos
Demos
Download WebClientPrint for ASP.NET
More Information about Neodynamic WebClientPrint for ASP.NET

Neodynamic
NET Components & Controls
http://www.neodynamic.com

Ignore negative number

$
0
0
Hey I need help with ignoring negative numbers when I am trying to add up only positive numbers.


SAMPLE:
if (num>=0) {
sum= sum + num;
}
else


how would the else in this case being a negative number not be included in the sum

THANKS!

Link time errors for static members

$
0
0
Code:

    class NavMeshLoader
    {
    public:
            NavMeshLoader()
            {
                    m_navMesh = loadAll("all_tiles_navmesh.bin");
                    m_navQuery->init(m_navMesh, 2048);
            }
    public:
            dtNavMesh *loadAll(const std::string& path)
            {
                    FILE* fp = fopen(path.c_str(), "rb");
                    if (!fp) return 0;
         
                    // Read header.
                    NavMeshSetHeader header;
                    fread(&header, sizeof(NavMeshSetHeader), 1, fp);
                    if (header.magic != NAVMESHSET_MAGIC)
                    {
                            fclose(fp);
                            return 0;
                    }
                    if (header.version != NAVMESHSET_VERSION)
                    {
                            fclose(fp);
                            return 0;
                    }
         
                    dtNavMesh* mesh = dtAllocNavMesh();
                    if (!mesh)
                    {
                            fclose(fp);
                            return 0;
                    }
                    dtStatus status = mesh->init(&header.params);
                    if (dtStatusFailed(status))
                    {
                            fclose(fp);
                            return 0;
                    }
                 
                    // Read tiles.
                    for (int i = 0; i < header.numTiles; ++i)
                    {
                            NavMeshTileHeader tileHeader;
                            fread(&tileHeader, sizeof(tileHeader), 1, fp);
                            if (!tileHeader.tileRef || !tileHeader.dataSize)
                                    break;

                            unsigned char* data = (unsigned char*)dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM);
                            if (!data) break;
                            memset(data, 0, tileHeader.dataSize);
                            fread(data, tileHeader.dataSize, 1, fp);
                 
                            mesh->addTile(data, tileHeader.dataSize, DT_TILE_FREE_DATA, tileHeader.tileRef, 0);
                    }
         
                    fclose(fp);
         
                    return mesh;
            }

    private:
            // By reference only, no memory consumption
            static dtNavMesh *m_navMesh;
                     
            static dtNavMeshQuery* m_navQuery;

            static dtQueryFilter m_filter;

            static dtStatus m_pathFindStatus;
    };

Error 3 error LNK2001: unresolved external symbol "private: static class dtNavMesh * NavMeshLoader::m_navMesh" (?m_navMesh@NavMeshLoader@@0PAVdtNavMesh@@A) D:\Jacky\Documents\Visual Studio 2010\Projects\PerfectSim\PerfectSim\PerfectSim\main.obj PerfectSim
Error 2 error LNK2001: unresolved external symbol "private: static class dtNavMeshQuery * NavMeshLoader::m_navQuery" (?m_navQuery@NavMeshLoader@@0PAVdtNavMeshQuery@@A) D:\Jacky\Documents\Visual Studio 2010\Projects\PerfectSim\PerfectSim\PerfectSim\main.obj PerfectSim

Code hangs on using sendmail command of smtp ?

$
0
0
Hi,
I m trying to send a mail via c++ code. I downloaded EASendMail component installer in ma system.

Then using this i wrote a code in vc++. I m sending a mail using a gmail id.I m able to send the mail correctly.
The issue i m facing is that the code hangs for the time it takes to send the mail.when i get a notification tat the mail is sent , den the cursor becomes active.I send the receiver address to the function i m calling.

<code>
using namespace EASendMailObjLib;
using namespace std;

int SendMail(LPTSTR RecieverID)
{
::CoInitialize( NULL );

IMailPtr oSmtp = NULL;
oSmtp.CreateInstance( "EASendMailObj.Mail");
oSmtp->LicenseCode = L"TryIt";

// Set your gmail email address
oSmtp->FromAddr = L"mygmailid@gmail.com";


// Add recipient email address

oSmtp->AddRecipientEx( RecieverID, 0 );

// Set email subject
oSmtp->Subject = L"simple email from Visual C++ with gmail account";

oSmtp->BodyText = L"Hi :)";


//adds attachment from local disk
if(oSmtp->AddAttachment( L"images/imagename.bmp") != 0)
{
printf("Failed to add attachment with error: %s\r\n", (const TCHAR*)oSmtp->GetLastErrDescription());

}


// Gmail SMTP server address
oSmtp->ServerAddr = L"smtp.gmail.com";

// If you want to use direct SSL 465 port,
// Please add this line, otherwise TLS will be used.
// oSmtp->ServerPort = 465;

// detect SSL/TLS automatically
oSmtp->SSL_init();

// Gmail user authentication should use your
// Gmail email address as the user name.
oSmtp->UserName = L"mygmailid@gmail.com";
oSmtp->Password =L"passowrd123";
printf("Start to send email via gmail account ...\r\n" );

if( oSmtp->SendMail() == 0 )
{ printf("email was sent successfully!\r\n");

}
else
{ printf("failed to send email with the following error: %s\r\n",(const TCHAR*)oSmtp->GetLastErrDescription());
}

if( oSmtp != NULL )
oSmtp.Release();

return 0;
}
</code>


I want the control to be active so that I can continue with other processes while the sending the mail happens on the background.
Can anyone pls help me in this !!!
Thankx a ton in advance.....

Regards,
Sandhya.

Problem about file handling!!!

$
0
0
Every time I write in file using ofstream it works fine except for one thing that when the file is re-opened after writing something and we try to add more data then previously added data is removed how to get rid of this.

<code>


struct abc
{
char name[100];
int a;
};


int main()
{


ofstream file;
file.open("text.dat", ios::out | ios::binary);


abc x;



x.a = 2;
cout<<"Enter name ";
cin>>x.name;



file.write((char*)&x,sizeof(struct abc));
file.close();

getch();
return 0;
}

</code>

Javac is not compiling correctly ... Please help

$
0
0
Hi Team,

I have installed jdk1.7.0_21 in my windows xp as well as windows 8 Systems.

When i try to compile a Simple Java program. Im getting the following error.

My code :

public class hello

{

public static void main(string[] args)

{

system.out.println("hello world");

}


}


Error :


C:\Java>javac hello.java
hello.java:5: error: cannot find symbol
public static void main(string[] args)
^
symbol: class string
location: class hello
hello.java:9: error: package system does not exist
system.out.println("hello world");
^
2 errors

I have added the path to environment variable (both Class path and Path). Here is my Path

Class path c:\sybase\ASEP_Win32\3pclass.zip;c:\sybase\ASEP_Win32\monclass.zip;C:\Program Files\Java\jdk1.7.0_21\bin\

C:\Java>path
PATH=c:\sybase\OLEDB;c:\sybase\ODBC;c:\sybase\ASEP_Win32;c:\sybase\OCS-12_5\dll;
c:\sybase\OCS-12_5\lib3p;c:\sybase\OCS-12_5\bin;C:\Program Files\Reflection;C:\W
INDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\system32\nls;C:\W
INDOWS\system32\nls\ENGLISH;C:\Program Files\IFFtools;C:\Program Files\IBM\Direc
tor\bin;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Sym
antec\pcAnywhere\;C:\Program Files\Common Files\Hitachi ID\;C:\Program Files\Jav
a\jdk1.7.0_21\bin\;C:\TCWIN45\BIN;C:\Program Files\Java\jdk1.7.0_21\bin\


Why am i not able to compile my program. Im really confused. please help.

Resizing a RichTextBox

$
0
0
Hi

I have placed a richtextbox on a form and I would like its size to be the size of the form, so I set the dock property to fill. My problem is that when I added a menubar and a toolbar at the top of the form, the first few lines of the rtb are now hidden. On the other hand if I set the dock property to none, when I resize the form, the rtb size remains fixed.

Is there a way to make the rtb start exactly under the toolbar but when I resize the form it will be resized accordingly?

Thank you in advance.

Creating a Property (Get/Set) Class

$
0
0
Hi there,

I've just recently moved from Visual Basic 6 over to C++ and decided that I would try and write a class to mimic the Get/Set behavior seen in a variety of other programming languages. So instead of just using an overloaded function, i.e:
Code:

class NoProp
{
    LPCWSTR m_Title;
public:
    void Title(LPCWSTR NewValue) {m_Title = NewValue;};
    LPCWSTR Title() {return m_Title;};
};

// ...

instNoProp->Title(L"New title!");  // Set

MessageBox(NULL, instNoProp->Title(), NULL, 0);  // Get

I could just write the following:
Code:

instProp->Title = L"New title!";  // Set

MessageBox(NULL, instProp->Title, NULL, 0);  // Get

After about a week of playing around I came up with the following Property class, and another class named InitProp as a helper.
Code:

#include <windows.h>

template <class tParent, class tProperty>class Property;

template <class tParent, class tProperty>
class InitProp
{
        typedef tProperty (tParent::*GET_PROP)(tParent*);
        typedef void (tParent::*SET_PROP)(tParent*, tProperty);

public:
        InitProp(tParent *cParent,
                        Property<tParent, tProperty> *cProperty,
                        tProperty *&tVariable,
                        GET_PROP Get_Property,
                        SET_PROP Set_Property)
        {
                cProperty->m_Property = new tProperty;
                *cProperty->m_Property = NULL;

                tVariable = cProperty->m_Property;

                cProperty->m_Parent = cParent;
                cProperty->m_Copy = 0;
                cProperty->m_Get_Property = Get_Property;
                cProperty->m_Set_Property = Set_Property;
        };
};

template <class tParent, class tProperty>
class Property
{
        typedef tProperty (tParent::*GET_PROP)(tParent*);
        typedef void (tParent::*SET_PROP)(tParent*, tProperty);

public:
        friend class InitProp<tParent, tProperty>;

        Property()
        {
                m_Parent = NULL;
                m_Set_Property = NULL;
                m_Get_Property = NULL;
        };

        ~Property()
        {
                if (m_Copy-- == 0)
                        delete m_Property;
        };

        Property operator= (tProperty NewValue)
        {
                if (m_Set_Property != NULL)
                        (m_Parent->*m_Set_Property)(m_Parent, NewValue);
               
                return *this;
        }

        Property(const Property& Prop)
        {
                ++m_Copy;
        };

        operator tProperty()
        {
                if (m_Get_Property != NULL)
                        return (m_Parent->*m_Get_Property)(m_Parent);
                else
                        return NULL;
        };

private:
        int m_Copy;
        tParent *m_Parent;
        tProperty *m_Property;
        GET_PROP m_Get_Property;
        SET_PROP m_Set_Property;
};

class Form
{
public:
        Property<Form, LPCWSTR> Title;

        Form()
        {
                InitProp<Form, LPCWSTR> pTitle(this, &Title, m_Title, &Form::g_Title, &Form::s_Title);
        };

private:
        LPCWSTR *m_Title;

        LPCWSTR g_Title(Form *Sender)
        {
                // User called Form.Title

                return *Sender->m_Title;
        };

        void s_Title(Form *Sender, LPCWSTR NewValue)
        {
                // User set Form.Title =

                *Sender->m_Title = NewValue;
        };

};

int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
        Form *frmMain;
        frmMain = new Form;

        frmMain->Title = L"This is just a test!";

        MessageBox(NULL, frmMain->Title, NULL, 0);

        delete frmMain;

        return 0;
}

So far this code only works with the LPCWSTR type (const wchar_t*). Unfortunately I got to this stage using only that type, and now when I try another type, such as int, it fails. When using the int type I believe it creates an error because the constructor of InitProp expects a type of pointer to be parsed. When I try using it with int* type (the private variable then becoming int **m_Variable) it compiles, thought I cannot access the property like a normal int.

My best guess from here is that I probably have to overload the InitProp constructor in a way that it can setup the Property classes for base-types and pointer-types, and then also modify the Property class to handle both.

I'd appreciate any suggestions and input as I'm becoming lost in template->pointer-land.

Thanks!

[RESOLVED] Windows Form - Create Method with parameters

$
0
0
I am wanting to separate the logic from the visual, but I'm having problems when calling the method that controls the actions of the progress bar timer.

Code:


ifndef PROGRESS_BAR
define PROGRESS_BAR



class Progress_bar{

public:

       
              void set_Progress(ToolStripStatusLabel^ label,Timer^ time){


                  toolStripProgressBar1 = label;
                  timer1 = time;


                  // Increment the value of the ProgressBar a value of one each time.

                        this->toolStripProgressBar1->Increment(10);

                        // Display the textual value of the ProgressBar in the StatusBar control's first panel.
     
                        toolStripStatusLabel1->Text = String::Concat( toolStripProgressBar1->Value, "% Loading" );

                        if ( toolStripProgressBar1->Value == toolStripProgressBar1->Maximum ){

          // Stop the timer.

            toolStripStatusLabel1->Text = "Completed";

                    timer1->Stop();

                        }


        }


          private: System::Windows::Forms::ToolStripProgressBar^  toolStripProgressBar1;
          private: System::Windows::Forms::Timer^  timer1;


};


# endif

Code:


the way that i´m calling this method on Form1.h

void set_Progress(toolStripStatusLabel1 ,timer1);

errors:

Code:


Error        1        error C2182: 'set_Progress' : illegal use of type 'void'        h:\cry_dev\programming\c++\school_media\school_media\Form1.h        277
Error        2        error C2078: too many initializers        h:\cry_dev\programming\c++\school_media\school_media\Form1.h        277
Error        3        error C2440: 'initializing' : cannot convert from 'System::Windows::Forms::Timer ^' to 'int'        h:\cry_dev\programming\c++\school_media\school_media\Form1.h        277

[RESOLVED] Creating Method with parameters

$
0
0
I am wanting to separate the logic from the visual, but I'm having problems when calling the method that controls the actions of the progress bar timer.

Code:


ifndef PROGRESS_BAR
define PROGRESS_BAR



class Progress_bar{

public:

       
              void set_Progress(ToolStripProgressBar^ progress_bar,
                                        ToolStripStatusLabel^ label,
                                                        Timer^ time){

                  toolStripProgressBar1 = progress_bar;
                  toolStripStatusLabel1 = label;
                  timer1 = time;

                  // Increment the value of the ProgressBar a value of one each time.

                        this->toolStripProgressBar1->Increment(10);

                        // Display the textual value of the ProgressBar in the StatusBar control's first panel.
     
                        toolStripStatusLabel1->Text = String::Concat( toolStripProgressBar1->Value, "% Loading" );

                        if ( toolStripProgressBar1->Value == toolStripProgressBar1->Maximum ){

          // Stop the timer.

            toolStripStatusLabel1->Text = "Completed";

                    timer1->Stop();

                        }


        }


          private: System::Windows::Forms::ToolStripProgressBar^  toolStripProgressBar1;
                                        System::Windows::Forms::ToolStripStatusLabel^  toolStripStatusLabel1;
                    System::Windows::Forms::Timer^  timer1;


};


# endif

Code:


the way that i´m calling this method on Form1.h

void set_Progress( toolStripProgressBar1, toolStripStatusLabel1 ,timer1);

errors:

Code:


Error        1        error C2182: 'set_Progress' : illegal use of type 'void'        h:\cry_dev\programming\c++\school_media\school_media\Form1.h        277
Error        2        error C2078: too many initializers        h:\cry_dev\programming\c++\school_media\school_media\Form1.h        277
Error        3        error C2440: 'initializing' : cannot convert from 'System::Windows::Forms::Timer ^' to 'int'        h:\cry_dev\programming\c++\school_media\school_media\Form1.h        277

winsock... binding to WRONG IP byte order WORKS!

$
0
0
I was updating a wrapper 32 bit windows DLL on an old winsock utilities library, to allow for the case where I need to specifically bind() my sockets to one or another IP addresses, on a multi homed system. I'm working with Visual studio 2008, on XP pro if it matters.

Anyway, previously I just would not bother doing a bind, just allowing winsock to choose an appropriate IP. But now I was doing something like the below. (Assume dwMyIP is a ULONG containing a known good IP, in host order.)


Code:

struct sockaddr_in sock_bind_addr;
 
sock_bind_addr.sin_family = AF_INET; 
sock_bind_addr.sin_addr.S_un.S_addr = htonl(dwMyIp);
sock_bind_addr.sin_port = 0;  // 0 allows winsock to pick a port.
 
if (bind(*pSockToStartWith, (struct sockaddr *)(&sock_bind_addr), sizeof(struct sockaddr_in)) == SOCKET_ERROR) {

... (Houston, we have a problem)'
 return -1;
}

So anyway, the bind would fail, and on a whim I decided to
remove the htonl() call, and store the 32 bit address in host order in the sockaddr_in structure. It WORKED!

Now I know everyone will jump to tell me that obviously I was missing something, and that my address was already in network order. Well consider this... the network IP in question was "192.168.0.190" Single step debugging though the code reveals that at this point in the program, dwMyIp = 0xBE00A8C0, which as an IP address is nothing like mine (makes sense... since I'm on an intel/windows machine). If, however I run my dwMyIP through htonl(), I get 0xC0A800BE, which indeed equates to 192.168.0.190. But that won't work, and I get an error (error 10049). :mad:

Further, after completing the bind the "wrong" way (with my host order IP), I can connect to a test application on another machine, which does indeed report the incoming connection from 192.168.0.190. Now I repeated this test with the ULONG equivalent of every available IP IP I'm set up on my system and the result is the same. I can bind to any valid address as long as I store it in host order, not network order.

OK...getting something to work the WRONG way and ignoring the problem is a prescription for a disaster sooner or later. So I'm about to make a hidden configuration variable for this to take care of both cases. But can anyone tell me why this is happening? Is there a known problem with the winsock (winsock 2 if it matters) bind() function? I can tell you from using the TCP/IP server variation, where I DO have to specify a port to connect to, that the expected behavior there is correct (meaning, if I want a client to connect to me at port 1234, I *DO* have to bind my listening socket to htons(1234).

As far as my server goes, its currently bound to IP_ANY, which in windows equates to 0. I have not yet tested to to see how it responds to a host format (little endian) IP, and I'll do that next. But I thought it was a good stopping point and a good time to ask.

Thanks for any help!

Trouble with GetDIBits()

$
0
0
Hello guys, I'm new to C++ and I couldn't figure out the proper way to store pixel data of a device context into an array using GetDIBits(). Currently I am trying to get the RGB values of a single pixel of a bitmap file:

Code:

#include <windows.h>
#include <iostream>
using namespace std;
int main() {HDC MemDC=CreateCompatibleDC(NULL);
        SelectObject(MemDC,(HBITMAP)LoadImage(NULL,(LPCTSTR)"F:\\gBit.bmp",IMAGE_BITMAP,1366,768,LR_LOADFROMFILE));
        HBITMAP hBit=(HBITMAP)LoadImage(NULL,(LPCTSTR)"F:\\gBit.bmp",IMAGE_BITMAP,1366,768,LR_LOADFROMFILE);
        BITMAPINFO bmi;
        BYTE p[3];


        bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
        bmi.bmiHeader.biWidth=1;
        bmi.bmiHeader.biHeight=-1;
        bmi.bmiHeader.biPlanes=1;
        bmi.bmiHeader.biBitCount=24;
        bmi.bmiHeader.biCompression=BI_RGB;
        bmi.bmiHeader.biSizeImage=0;
        bmi.bmiHeader.biXPelsPerMeter=0;
        bmi.bmiHeader.biYPelsPerMeter=0;
        bmi.bmiHeader.biClrUsed=0;
        bmi.bmiHeader.biClrImportant=0;


        GetDIBits(MemDC,hBit,0,0,p,&bmi,DIB_RGB_COLORS);
        cout<<p[0]<<endl<<p[1]<<endl<<p[2];
        ReleaseDC(NULL,MemDC); DeleteDC(MemDC);
        DeleteObject(hBit); while (1) {}
}

gBit.bmp, the bitmap file selected into MemDC, is an entirely white 24-bit bitmap image, so I thought cout should display 255, but for some reason it displays some weird characters. Most probably p is not initialized since the same values are returned when I remove the line containing GetDIBits(). Am I using this function properly? What could I possibly be doing wrong here?

Searching a vector of objects for pairs

$
0
0
Hello all,

Say I have a vector of objects and I want to return an object based on a pair of strings. The strings can be in either order Ie; A B==B A.

In general, what do you think is the best way to do this?

Thanks,
T.

Typemock CEO: Software Development Without Unit Testing is Reckless

$
0
0
Tel-Aviv, May 16, 2013 – Typemock, (http://www.typemock.com/) the leading provider and pioneer of automated unit testing solutions held a corporate event to celebrate eight years since its founding. CEO Eli Lopian addressed the gathering and laid out his thoughts on the necessity of unit testing in software development: “Any software programmer that does not do unit testing is a reckless coder”, declared Lopian. “Unit testing is an essential part of any software development process. It allows you to deliver working code, with fewer bugs, faster. Typemock has made huge advances with its automated unit testing tools in the past eight years. The old arguments that unit testing is too hard no longer apply!”

Lopian noted that Agile Software Development has become widely accepted in recent years, but that some programmers still insist that unit testing is not an integral part of the Agile process. Lopian argues this point: “Without unit testing you may think you are Agile, you may be running fast but you are not healthy, you won’t be able to keep up to speed. Sooner or later, you, or even worse: your customers, will start finding bugs which will compel you to introduce changes to what is now legacy code - without any tests to show you what you’ve done wrong. In today’s hyper-competitive market, corporations cannot afford the resource and time drain of having to re-write their entire code every few years due to code decay.”

Lopian predicted that in the coming years all software will be developed with unit testing. He hopes the change will come from industry-made regulations similar to ISO, so that “software safety standards” will be in place. “As a developer myself, I have a dream”, Lopian ended, “that programmers will take the leap and become agile – really agile! This means not being afraid of legacy code, this means being proud of the software they've created, and this means building usable and sustainable code for millions of users. All this is within everyone's reach right now – with unit testing”.

About Eli Lopian

Eli founded Typemock in 2004 and serves as its CEO. A well-known figure in the agile and test driven development (TDD) arenas, Eli has over 17 years of R&D experience at large companies such as AMDOCS (NYSE:DOX) and Digital Equipment Corporation (DEC). In his previous roles, prior to founding Typemock, Eli was responsible for optimizing the development process and led the transformation of the development environment to support efficient processes and tools.

About Typemock

Typemock was conceived in 2004 to help programmers become agile through easy unit testing. Since the launch of the first version of Typemock Isolator in 2006, thousands of companies around the world use Typemock tools to make automated unit testing easy and to prevent bugs. Typemock users are developers from a wide range of sectors – such as defense, medical, and finance – that demand exceptionally high standards of quality and minimum bugs.

Typemock is a privately funded company.
See www.typemock.com

Media Contact:
Lazer Cohen
NCSM Strategic Marketing
T: +972-584192917
Lazer@ncsm.co.il
www.ncsm.co.il

adding bftsmart package

$
0
0
I downloaded the bftsmart-v0.8 . I have tried to follow the instructions from google code. but I don't know
how to get the bftsmart.tom.ServiceProxy to into my eclipse application. just writing import bftsmart.tom.ServiceProxy does not work. please help I am new in java programming

VB6 Compile Errors due to .dsr files

$
0
0
This thread is related to another called "Project Load errors in VB6". I thought this was different enough to justify a new thread.

I get vb6 pro compile errors of the type "variablename variable not found". In the corresponding log file, it has "variablename.dsr could not be loaded". DSR files, along with .dca and sometimes .dcx files, are generated by the MS Report Designer which I thought was installed on my VB6 Pro. However, if I select Project>Add Data Report, I get "Class Not Registered" with only a clsid listed. I have no idea what class is being referred to. If I select Add-Ins from the toolbar of my project, then Report Designer, it takes me to Crystal Reports which I don't want to use.

Any assistance would be greatly appreciated.

00h00 ngày 18/5, Mersin Idman Yurdu vs Gaziantepspor - Tipkeo.com

$
0
0
Dịch vụ card Tip Bóng Đá (Tipkeo.com)

1. Giới thiệu:
- Để nâng cao tính tiện lợi, hiệu quả và chất lượng TIP BONG DA của TipKeo.com. Chúng tôi xin giới thiệu dịch vụ CARD TIP thanh toán nhanh chóng, gọn nhẹ thanh toán bằng thẻ cào điện thoại.
- Với tiêu trí ngày càng nâng cao chất lượng Tip Bóng Đá tốt hơn nữa, nay chúng tôi đưa ra gói nhận định Tip chất lượng 4 Sao với tỷ lệ chiến thắng từ 90%.
- Hàng ngày chúng tôi lọc ra các trận có tỷ lệ thắng cao nhất để làm Tip, và làm có chọn lọc để đảm bảo quý khách luôn thắng khi đặt niềm tin vào TipKeo.Com
2. Chi Phí cho các gói CARD TIP:
- Card 50.000 đ cho 1 TIP

3. Cách thức thanh toán và mua TIP:
- Quý khách thanh toán bằng mã số thẻ cào
- Quý khách có thể nạp nhiều lần cho đủ gói CARD TIP BÓNG ĐÁ
- Vui lòng điền đầy đủ thông tin vào phần "Nhập thông tin giao dịch" bên dưới để có thể tiến hành mua TIP một cách thuận lợi
- Cách thức điền vào phần "Nhập thông tin giao dịch":
+ Điện thoại: Số điện thoại quý khách muốn nhận TIP
+ Loại thẻ: Chọn loại thẻ trùng khớp với loại thẻ quý khách dùng để thanh toán gói CARD TIP
+ Mã thẻ: Nhập vào mã thẻ cào
+ Seri thẻ: Nhập vào seri thẻ cào
- Khi thành công sẽ cấp bạn một mật khẩu và user là số điện thoại của bạn.
- Liên hệ: 0906 875 40
- yahoo: hotro.tipkeo

Thân mời quý độc giả ghé thăm:
- Dịch vụ TIP BÓNG ĐÁ : http://tipkeo.com/tip-bong-da
- Tin tức tổng hợp, lịch tip, dự đoán tỷ số, TRANG CHỦ: http://tipkeo.com/
- Tỷ lệ keo bong da, phương pháp soi kèo: http://tipkeo.com/keo-bong-da
- nhan dinh bong da sớm nhất: http://tipkeo.com/du-lieu-bong-da/nhan-dinh-bong-da
- Danh sách tip free của Tip kèo( thường lúc 16h chiều hàng ngày): http://tipkeo.com/free-tip
- Kết Quả bóng đá trực tuyến: http://tipkeo.com/ket-qua-bong-da
- Xem bóng đá Online link sopcast: http://tipkeo.com/xem-bong-da-online

Thật đáng tiếc khi Mersin Idman Yurdu phải xuống hạng trong lúc NHM kỳ vọng nhất, nhưng như người ta vẫn nói “thất bại là mẹ thành công” và đội chủ nhà sẽ phải làm lại ở mùa giải tới.

TIP BÓNG ĐÁ UY TÍN CHẤT LƯỢNG SỐ 1 VIỆT NAM http://tipbongda.tipkeo.com


Vòng đấu cuối thật nặng nề với các cầu thủ Mersin Idman Yurdu và CĐV của họ khi đây sẽ là trận đấu cuối cùng của họ ở Super Lig. Sớm nhất thì cũng phải 1 năm nữa họ mới có cơ hội trở lại đấu trường cao nhất của bóng đá Thổ Nhĩ Kỳ. Càng đau đớn hơn khi biết rằng BLĐ “Qủy đỏ” đang ấp ủ một kế hoạch lớn.

Đội bóng bên bờ Đông biển Địa Trung Hải vừa mới khánh thành SVĐ mới, “nhà mới” của Mersin là một trong những sân bóng đẹp và hiện đại nhất ở Thổ Nhĩ Kỳ hiện nay và sức chứa của nó cũng gấp tới 3 lần “nhà cũ” của CLB. Rõ ràng đó là kế hoạch dài hơn và rất có tầm nhìn của BLĐ đội bóng áo đỏ nhưng tiếc rằng mùa tới họ sẽ phải xuống chơi ở giải Hạng Hai.


Mersin (áo đỏ) cần chiến thắng để lấy lại danh dự

Nhưng bóng đá cũng giống như cuộc sống vậy, có thất bại thì mới có thành công, Mersin sẽ phải làm lại từ đầu ở mùa giải tới. Không ai “giết chết” giấc mơ của thầy trò HLV Kutlu cả và họ sẽ phải tự thay đổi để hiện thực hóa giấc mơ “ông lớn” ở bóng đá Thổ Nhĩ Kỳ. Tuy nhiên trước khi nghĩ tới mùa bóng kế tiếp thì đội chủ nhà hãy lấy lại niềm tin của NHM trong trận đấu cuối cùng vào đêm nay đã.

Cơ hội cho Mersin giành được chiến thắng “rửa mặt” là khá cao khi họ chỉ phải gặp đội bóng đã hết động lực là Gaziantepspor. Đội khách đã hoàn thành chỉ tiêu trụ hạng trong những vòng đấu cuối và giờ đây thầy trò HLV Bülent Uygun hoàn toàn thoải mái về tinh thần. Không loại trừ khả năng đội bóng thành Gaziantep sẽ buông xuôi ở vòng đấu này.

Hai đội đã hết mục tiêu phấn đấu, nhưng động lực của đội chủ nhà là khá cao khi họ cần 1 chiến thắng để lấy lại niềm tin từ NHM. Với quyết tâm cao và ưu thế trong các lần tiếp đón Gaziantepspor, Mersin hoàn toàn có thể nghĩ tới 3 điểm đáng giá về mặt tinh thần vào đêm nay.

Đội hình dự kiến:

Mersin Idman Yurdu: Usak, S. Yanik, T. Kayhan, M. Mitrović, E. Culio, B. Eser, J. Gosso, R. Lawal, Mert Nobre, N. Ozukwo, E. Tozlu.

Gaziantepspor: Bezgin, S. Kurtulus, S. Can, I. Kecojević, H. Medunjanin, B. Has, G. Binya, D. 0ernas, S. Ozbayraktar, C. Tosun, D. Kouemaha.

Dự đoán: 1-0



WebSite: http://tipkeo.com/

App developers needed! Want to win €2500? Join the 24green App Contest!

$
0
0
24green is a Dutch company what is focused on creating new and smart solutions in automation for the horticulture and agriculture. We are searching for app developers who could participate to our app contest. As an innovative company we would like to use the talent of developers. Our app contest entries will have the chance to win great prizes. View the following flyer:

http://us4.campaign-archive1.com/?u=...c&e=ccc8cbac16

For more information about the app contest:

http://24green.com/appcontest/

Thanks for your support!

Regards,

24green
info@24green.com
+31 (0)10 460 81 45
http://www.24green.com

GetDIBits() returns wrong BGR values:

$
0
0
GetDIBits() was not passing the correct BGR values to a COLORREF array:

Code:

#include <windows.h>
#include <iostream>
using namespace std;

int main() {int i; HBITMAP hBit; HDC bdc; BITMAPINFO bmpInfo; COLORREF pixel[100];


    hBit=(HBITMAP)LoadImage(NULL,(LPCTSTR)"F:\\bitmap.bmp",IMAGE_BITMAP,10,10,LR_LOADFROMFILE);
    bdc=CreateCompatibleDC(NULL);
    SelectObject(bdc,hBit);


    bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFO);
    bmpInfo.bmiHeader.biWidth=10;
    bmpInfo.bmiHeader.biHeight=-10;
    bmpInfo.bmiHeader.biPlanes=1;
    bmpInfo.bmiHeader.biBitCount=24;
    bmpInfo.bmiHeader.biCompression=BI_RGB;
    bmpInfo.bmiHeader.biSizeImage=0;


    GetDIBits(bdc,hBit,0,10,pixel,&bmpInfo,DIB_RGB_COLORS);


    for (i=0; i<100; i++) {
        cout<<GetBValue(pixel[i]);
        cout<<GetGValue(pixel[i]);
        cout<<GetRValue(pixel[i]);
        cout<<endl;
    }


    ReleaseDC(NULL,bdc);
    DeleteDC(bdc);
    DeleteObject(hBit);
    free(pixel);
    while (1) {}
}

bitmap.bmp is an entirely blue (RGB(0,0,255)) 10x10 24-bit bitmap file. The first few lines of the output look like:

0
0
255

255
0
0

0
255
0

0
0
255

And it's not only the order of the values that changes; some color values are 0 when they shouldn't be. The last few COLORREF values are RGB(0,0,0). What could be the problem with the code?

Convert PDF to other formats, Add Floating Boxes in New or Existence PDF Files

$
0
0
The latest version of Aspose.Pdf for .NET (8.0.0) has been released. This release includes better support for existing file manipulation. This new release has specific improvements for PDF printing, PDF to DOC, XPS and various image format conversions. We have also focused on watermarking, text extraction, PDF compression and bookmarking functionalities. Please note that we recently introduced an Examples dashboard which contains code examples for Aspose.Total for .NET products. From this release, the Examples dashboard is part of the product installer. So once you have installed this new version, you can find the Examples dashboard in the Examples folder in Aspose.Pdf for .NET’s product installation directory. This release includes plenty of new and improved features as listed below

• Disable paging in PDF document
• Update Validate(..) method to take Stream object as an argument
• Examples dashboard with Aspose.Pdf for .NET
• Cell Text Wrapping issue in Table Row is fixed
• PDF to PNG conversion issue is resolved
• Complete text is now extracted from PDF file
• Using unicode characters in TOC
• Unable to extract/get page number information regarding bookmarks
• Pdf printing now working printing images
• PDF to PNG: Conversion process hanging is fixed
• Image rendered as black while converting Pdf to JPG is fixed
• Printing halting is resolved for indefinite time
• While printing using PdfViewer, data missing in footer is fixed
• Opacity property of FreeTextAnnotation is now working
• PDF to XPS: resultant file is now corrected
• PDF to DOC: Bullets and frame container missing is fixed
• OptimizeResources(), error message is fixed when viewing resultant PDF
• FreeTextAnnotation contains multiline international characters, result is broken
• Multi-page table rendering properly is fixed
• Error fixed while concatenating PDF files
• Watermark is now being added to PDF document
• Checkboxes appearanceis fixed on first page footer and remaining pages
• All output PDFs are of the same size as input PDF
• How to embed and extract blank data in XMP
• While filling a richtextbox field, line break tag in XML not working
• Unable to clear Keywords property is now fixed
• Process hanging is fixed while converting Pdf to Tiff
• Aspose.PDF 7.8 is showing missing dependency error is now fixed
• PDF concatenation, bookmarks are now being included in resultant file
• Concatenate attached Pdf files is now fixed
• Assemblies referenced in Aspose.Pdf for .Net 7.8.0 but missing in build is fixed
• Multiline TexboxField now honor new line
• Textfragment now implementing Bold and italic fontstyles simultaneously
• Different footer on last page of PDF file is resolved

Other most recent bug fixes are also included in this release.
Viewing all 12179 articles
Browse latest View live