|
hi everyone.. I have written a program where I want to return three user defined data types to the another main() function (here i have not mentioned that main). I want to return {Pa,c1,c2} from this program. Please help me out.
#include <cstdlib>
#include <iostream>
#include <vector>
using std:: cout;
using std:: cin;
using std:: endl;
using namespace std;
#include <math.h>
#include "FiniteFieldElement.hpp"
namespace Cryptography
{
template<int P>
class EllipticCurve
{
public:
typedef FiniteFieldElement<P> ffe_t;
class Point
{
friend class EllipticCurve<P>;
typedef FiniteFieldElement<P> ffe_t;
ffe_t x_;
ffe_t y_;
EllipticCurve *ec_;
void addDouble(int m, Point& acc)
{
if ( m > 0 )
{
Point r = acc;
for ( int n=0; n < m; ++n )
{
r += r;
}
acc = r;
}
}
Point scalarMultiply(int k, const Point& a)
{
Point acc = a;
Point res = Point(0,0,*ec_);
int i = 0, j = 0;
int b = k;
while( b )
{
if ( b & 1 )
{
addDouble(i-j,acc);
res += acc;
j = i;
}
b >>= 1;
++i;
}
return res;
}
void add(ffe_t x1, ffe_t y1, ffe_t x2, ffe_t y2, ffe_t & xR, ffe_t & yR) const
{
if ( x1 == 0 && y1 == 0 )
{
xR = x2;
yR = y2;
return;
}
if ( x2 == 0 && y2 == 0 )
{
xR = x1;
yR = y1;
return;
}
if ( y1 == -y2 )
{
xR = yR = 0;
return;
}
ffe_t s;
if ( x1 == x2 && y1 == y2 )
{
s = (3*(x1.i()*x1.i()) + ec_->a()) / (2*y1);
xR = ((s*s) - 2*x1);
}
else
{
s = (y1 - y2) / (x1 - x2);
xR = ((s*s) - x1 - x2);
}
if ( s != 0 )
{
yR = (-y1 + s*(x1 - xR));
}
else
{
xR = yR = 0;
}
}
Point(int x, int y)
: x_(x),
y_(y),
ec_(0)
{}
Point(int x, int y, EllipticCurve<P> & EllipticCurve)
: x_(x),
y_(y),
ec_(&EllipticCurve)
{}
Point(const ffe_t& x, const ffe_t& y, EllipticCurve<P> & EllipticCurve)
: x_(x),
y_(y),
ec_(&EllipticCurve)
{}
public:
static Point ONE;
Point(const Point& rhs)
{
x_ = rhs.x_;
y_ = rhs.y_;
ec_ = rhs.ec_;
}
Point& operator=(const Point& rhs)
{
x_ = rhs.x_;
y_ = rhs.y_;
ec_ = rhs.ec_;
return *this;
}
ffe_t x() const { return x_; }
ffe_t y() const { return y_; }
unsigned int Order(unsigned int maxPeriod = ~0) const
{
Point r = *this;
unsigned int n = 0;
while( r.x_ != 0 && r.y_ != 0 )
{
++n;
r += *this;
if ( n > maxPeriod ) break;
}
return n;
}
Point operator-()
{
return Point(x_,-y_);
}
friend bool operator==(const Point& lhs, const Point& rhs)
{
return (lhs.ec_ == rhs.ec_) && (lhs.x_ == rhs.x_) && (lhs.y_ == rhs.y_);
}
friend bool operator!=(const Point& lhs, const Point& rhs)
{
return (lhs.ec_ != rhs.ec_) || (lhs.x_ != rhs.x_) || (lhs.y_ != rhs.y_);
}
friend Point operator+(const Point& lhs, const Point& rhs)
{
ffe_t xR, yR;
lhs.add(lhs.x_,lhs.y_,rhs.x_,rhs.y_,xR,yR);
return Point(xR,yR,*lhs.ec_);
}
friend Point operator*(int k, const Point& rhs)
{
return Point(rhs).operator*=(k);
}
Point& operator+=(const Point& rhs)
{
add(x_,y_,rhs.x_,rhs.y_,x_,y_);
return *this;
}
Point& operator*=(int k)
{
return (*this = scalarMultiply(k,*this));
}
friend ostream& operator <<(ostream& os, const Point& p)
{
return (os << "(" << p.x_ << ", " << p.y_ << ")");
}
};
typedef EllipticCurve<P> this_t;
typedef class EllipticCurve<P>::Point point_t;
EllipticCurve(int a, int b)
: a_(a),
b_(b),
m_table_(),
table_filled_(false)
{
}
void CalculatePoints()
{
int x_val[P];
int y_val[P];
for ( int n = 0; n < P; ++n )
{
int nsq = n*n;
x_val[n] = ((n*nsq) + a_.i() * n + b_.i()) % P;
y_val[n] = nsq % P;
}
for ( int n = 0; n < P; ++n )
{
for ( int m = 0; m < P; ++m )
{
if ( x_val[n] == y_val[m] )
{
m_table_.push_back(Point(n,m,*this));
}
}
}
table_filled_ = true;
}
Point operator[](int n)
{
if ( !table_filled_ )
{
CalculatePoints();
}
return m_table_[n];
}
size_t Size() const { return m_table_.size(); }
int Degree() const { return P; }
FiniteFieldElement<P> a() const { return a_; }
FiniteFieldElement<P> b() const { return b_; }
template<int T>
friend ostream& operator <<(ostream& os, const EllipticCurve<T>& EllipticCurve);
ostream& PrintTable(ostream &os, int columns=4);
private:
typedef std::vector<Point> m_table_t;
m_table_t m_table_;
FiniteFieldElement<P> a_;
FiniteFieldElement<P> b_;
bool table_filled_;
};
template<int T>
typename EllipticCurve<T>::Point EllipticCurve<T>::Point::ONE(0,0);
template<int T>
ostream& operator <<(ostream& os, const EllipticCurve<T>& EllipticCurve)
{
os << "y^2 mod " << T << " = (x^3" << showpos;
if ( EllipticCurve.a_ != 0 )
{
os << EllipticCurve.a_ << "x";
}
if ( EllipticCurve.b_.i() != 0 )
{
os << EllipticCurve.b_;
}
os << noshowpos << ") mod " << T;
return os;
}
template<int P>
ostream& EllipticCurve<P>::PrintTable(ostream &os, int columns)
{
if ( table_filled_ )
{
int col = 0;
typename EllipticCurve<P>::m_table_t::iterator iter = m_table_.begin();
for ( ; iter!=m_table_.end(); ++iter )
{
os << "(" << (*iter).x_.i() << ", " << (*iter).y_.i() << ") ";
if ( ++col > columns )
{
os << "\n";
col = 0;
}
}
}
else
{
os << "EllipticCurve, F_" << P;
}
return os;
}
}
namespace utils
{
float frand()
{
static float norm = 1.0f / (float)RAND_MAX;
return (float)rand()*norm;
}
int irand(int min, int max)
{
return min+(int)(frand()*(float)(max-min));
}
}
using namespace Cryptography;
using namespace utils;
int main(int argc, char *argv[])
{
typedef EllipticCurve<263> ec_t;
ec_t myEllipticCurve(1,1);
cout << "A little Elliptic Curve cryptography example\nby Jarl Ostensen, 2007\n\n";
cout << "The elliptic curve: " << myEllipticCurve << "\n";
myEllipticCurve.CalculatePoints();
cout << "\nPoints on the curve (i.e. the group elements):\n";
myEllipticCurve.PrintTable(cout,5);
cout << "\n\n";
ec_t::Point P = myEllipticCurve[2];
cout << "some point P = " << P << ", 2P = " << (P+P) << "\n";
ec_t::Point Q = myEllipticCurve[3];
cout << "some point Q = " << Q << ", P+Q = " << (P+Q) << "\n";
ec_t::Point R = P;
R += Q;
cout << "P += Q = " << R << "\n";
R = P;
R += R;
cout << "P += P = 2P = " << R << "\n";
cout << "\nEC message encryption example\n===============================================\n\n";
ec_t::Point G = myEllipticCurve[0];
while( (G.y() == 0 || G.x() == 0) || (G.Order()<2) )
{
int n = (int)(frand()*myEllipticCurve.Size());
G = myEllipticCurve[n];
}
cout << "G = " << G << ", order(G) is " << G.Order() << "\n";
int a = irand(1,myEllipticCurve.Degree()-1);
ec_t::Point Pa = a*G;
cout << "Alice' public key Pa = " << a << "*" << G << " = " << Pa << endl;
int b = irand(1,myEllipticCurve.Degree()-1);;
ec_t::Point Pb = b*G;
cout << "Bob's public key Pb = " << b << "*" << G << " = " << Pb << endl;
int j = irand(1,myEllipticCurve.Degree()-1);;
ec_t::Point Pj = j*G;
cout << "Jane's public key Pj = " << j << "*" << G << " = " << Pj << endl;
cout << "\n\n";
int m1,m2;
cout << "Enter two message\n"<< endl;
cin >> m1;
cin >> m2;
cout << "Plain text message from Alice to Bob: (" << m1 << ", " << m2 << ")\n";
ec_t::Point Pk = a*Pb;
ec_t::ffe_t c1( m1*Pk.x() );
ec_t::ffe_t c2( m2*Pk.y() );
cout << "Encrypted message from Alice to Bob = {Pa,c1,c2} = {" << Pa << ", " << c1 << ", " << c2 << "}\n\n";
Pk = b*Pa;
ec_t::ffe_t m1d = c1/Pk.x();
ec_t::ffe_t m2d = c2/Pk.y();
cout << "\tBob's decrypted message from Alice = (" << m1d << ", " << m2d << ")" << endl;
Pk = j*Pa;
m1d = c1/Pk.x();
m2d = c2/Pk.y();
cout << "\nJane's decrypted message from Alice = (" << m1d << ", " << m2d << ")" << endl;
cout << endl;
}
|
|
|
|
|
hi everyone.. I have written a program where I want to return three user defined data types to the another main() function (here i have not mentioned that main). I want to return {Pa,c1,c2} from this program. Please help me out.
#include <cstdlib>
#include <iostream>
#include <vector>
using std:: cout;
using std:: cin;
using std:: endl;
using namespace std;
#include <math.h>
#include "FiniteFieldElement.hpp"
namespace Cryptography
{
template<int P>
class EllipticCurve
{
public:
typedef FiniteFieldElement<P> ffe_t;
class Point
{
friend class EllipticCurve<P>;
typedef FiniteFieldElement<P> ffe_t;
ffe_t x_;
ffe_t y_;
EllipticCurve *ec_;
void addDouble(int m, Point& acc)
{
if ( m > 0 )
{
Point r = acc;
for ( int n=0; n < m; ++n )
{
r += r;
}
acc = r;
}
}
Point scalarMultiply(int k, const Point& a)
{
Point acc = a;
Point res = Point(0,0,*ec_);
int i = 0, j = 0;
int b = k;
while( b )
{
if ( b & 1 )
{
addDouble(i-j,acc);
res += acc;
j = i;
}
b >>= 1;
++i;
}
return res;
}
void add(ffe_t x1, ffe_t y1, ffe_t x2, ffe_t y2, ffe_t & xR, ffe_t & yR) const
{
if ( x1 == 0 && y1 == 0 )
{
xR = x2;
yR = y2;
return;
}
if ( x2 == 0 && y2 == 0 )
{
xR = x1;
yR = y1;
return;
}
if ( y1 == -y2 )
{
xR = yR = 0;
return;
}
ffe_t s;
if ( x1 == x2 && y1 == y2 )
{
s = (3*(x1.i()*x1.i()) + ec_->a()) / (2*y1);
xR = ((s*s) - 2*x1);
}
else
{
s = (y1 - y2) / (x1 - x2);
xR = ((s*s) - x1 - x2);
}
if ( s != 0 )
{
yR = (-y1 + s*(x1 - xR));
}
else
{
xR = yR = 0;
}
}
Point(int x, int y)
: x_(x),
y_(y),
ec_(0)
{}
Point(int x, int y, EllipticCurve<P> & EllipticCurve)
: x_(x),
y_(y),
ec_(&EllipticCurve)
{}
Point(const ffe_t& x, const ffe_t& y, EllipticCurve<P> & EllipticCurve)
: x_(x),
y_(y),
ec_(&EllipticCurve)
{}
public:
static Point ONE;
Point(const Point& rhs)
{
x_ = rhs.x_;
y_ = rhs.y_;
ec_ = rhs.ec_;
}
Point& operator=(const Point& rhs)
{
x_ = rhs.x_;
y_ = rhs.y_;
ec_ = rhs.ec_;
return *this;
}
ffe_t x() const { return x_; }
ffe_t y() const { return y_; }
unsigned int Order(unsigned int maxPeriod = ~0) const
{
Point r = *this;
unsigned int n = 0;
while( r.x_ != 0 && r.y_ != 0 )
{
++n;
r += *this;
if ( n > maxPeriod ) break;
}
return n;
}
Point operator-()
{
return Point(x_,-y_);
}
friend bool operator==(const Point& lhs, const Point& rhs)
{
return (lhs.ec_ == rhs.ec_) && (lhs.x_ == rhs.x_) && (lhs.y_ == rhs.y_);
}
friend bool operator!=(const Point& lhs, const Point& rhs)
{
return (lhs.ec_ != rhs.ec_) || (lhs.x_ != rhs.x_) || (lhs.y_ != rhs.y_);
}
friend Point operator+(const Point& lhs, const Point& rhs)
{
ffe_t xR, yR;
lhs.add(lhs.x_,lhs.y_,rhs.x_,rhs.y_,xR,yR);
return Point(xR,yR,*lhs.ec_);
}
friend Point operator*(int k, const Point& rhs)
{
return Point(rhs).operator*=(k);
}
Point& operator+=(const Point& rhs)
{
add(x_,y_,rhs.x_,rhs.y_,x_,y_);
return *this;
}
Point& operator*=(int k)
{
return (*this = scalarMultiply(k,*this));
}
friend ostream& operator <<(ostream& os, const Point& p)
{
return (os << "(" << p.x_ << ", " << p.y_ << ")");
}
};
typedef EllipticCurve<P> this_t;
typedef class EllipticCurve<P>::Point point_t;
EllipticCurve(int a, int b)
: a_(a),
b_(b),
m_table_(),
table_filled_(false)
{
}
void CalculatePoints()
{
int x_val[P];
int y_val[P];
for ( int n = 0; n < P; ++n )
{
int nsq = n*n;
x_val[n] = ((n*nsq) + a_.i() * n + b_.i()) % P;
y_val[n] = nsq % P;
}
for ( int n = 0; n < P; ++n )
{
for ( int m = 0; m < P; ++m )
{
if ( x_val[n] == y_val[m] )
{
m_table_.push_back(Point(n,m,*this));
}
}
}
table_filled_ = true;
}
Point operator[](int n)
{
if ( !table_filled_ )
{
CalculatePoints();
}
return m_table_[n];
}
size_t Size() const { return m_table_.size(); }
int Degree() const { return P; }
FiniteFieldElement<P> a() const { return a_; }
FiniteFieldElement<P> b() const { return b_; }
template<int T>
friend ostream& operator <<(ostream& os, const EllipticCurve<T>& EllipticCurve);
ostream& PrintTable(ostream &os, int columns=4);
private:
typedef std::vector<Point> m_table_t;
m_table_t m_table_;
FiniteFieldElement<P> a_;
FiniteFieldElement<P> b_;
bool table_filled_;
};
template<int T>
typename EllipticCurve<T>::Point EllipticCurve<T>::Point::ONE(0,0);
template<int T>
ostream& operator <<(ostream& os, const EllipticCurve<T>& EllipticCurve)
{
os << "y^2 mod " << T << " = (x^3" << showpos;
if ( EllipticCurve.a_ != 0 )
{
os << EllipticCurve.a_ << "x";
}
if ( EllipticCurve.b_.i() != 0 )
{
os << EllipticCurve.b_;
}
os << noshowpos << ") mod " << T;
return os;
}
template<int P>
ostream& EllipticCurve<P>::PrintTable(ostream &os, int columns)
{
if ( table_filled_ )
{
int col = 0;
typename EllipticCurve<P>::m_table_t::iterator iter = m_table_.begin();
for ( ; iter!=m_table_.end(); ++iter )
{
os << "(" << (*iter).x_.i() << ", " << (*iter).y_.i() << ") ";
if ( ++col > columns )
{
os << "\n";
col = 0;
}
}
}
else
{
os << "EllipticCurve, F_" << P;
}
return os;
}
}
namespace utils
{
float frand()
{
static float norm = 1.0f / (float)RAND_MAX;
return (float)rand()*norm;
}
int irand(int min, int max)
{
return min+(int)(frand()*(float)(max-min));
}
}
using namespace Cryptography;
using namespace utils;
int main(int argc, char *argv[])
{
typedef EllipticCurve<263> ec_t;
ec_t myEllipticCurve(1,1);
cout << "A little Elliptic Curve cryptography example\nby Jarl Ostensen, 2007\n\n";
cout << "The elliptic curve: " << myEllipticCurve << "\n";
myEllipticCurve.CalculatePoints();
cout << "\nPoints on the curve (i.e. the group elements):\n";
myEllipticCurve.PrintTable(cout,5);
cout << "\n\n";
ec_t::Point P = myEllipticCurve[2];
cout << "some point P = " << P << ", 2P = " << (P+P) << "\n";
ec_t::Point Q = myEllipticCurve[3];
cout << "some point Q = " << Q << ", P+Q = " << (P+Q) << "\n";
ec_t::Point R = P;
R += Q;
cout << "P += Q = " << R << "\n";
R = P;
R += R;
cout << "P += P = 2P = " << R << "\n";
cout << "\nEC message encryption example\n===============================================\n\n";
ec_t::Point G = myEllipticCurve[0];
while( (G.y() == 0 || G.x() == 0) || (G.Order()<2) )
{
int n = (int)(frand()*myEllipticCurve.Size());
G = myEllipticCurve[n];
}
cout << "G = " << G << ", order(G) is " << G.Order() << "\n";
int a = irand(1,myEllipticCurve.Degree()-1);
ec_t::Point Pa = a*G;
cout << "Alice' public key Pa = " << a << "*" << G << " = " << Pa << endl;
int b = irand(1,myEllipticCurve.Degree()-1);;
ec_t::Point Pb = b*G;
cout << "Bob's public key Pb = " << b << "*" << G << " = " << Pb << endl;
int j = irand(1,myEllipticCurve.Degree()-1);;
ec_t::Point Pj = j*G;
cout << "Jane's public key Pj = " << j << "*" << G << " = " << Pj << endl;
cout << "\n\n";
int m1,m2;
cout << "Enter two message\n"<< endl;
cin >> m1;
cin >> m2;
cout << "Plain text message from Alice to Bob: (" << m1 << ", " << m2 << ")\n";
ec_t::Point Pk = a*Pb;
ec_t::ffe_t c1( m1*Pk.x() );
ec_t::ffe_t c2( m2*Pk.y() );
cout << "Encrypted message from Alice to Bob = {Pa,c1,c2} = {" << Pa << ", " << c1 << ", " << c2 << "}\n\n";
Pk = b*Pa;
ec_t::ffe_t m1d = c1/Pk.x();
ec_t::ffe_t m2d = c2/Pk.y();
cout << "\tBob's decrypted message from Alice = (" << m1d << ", " << m2d << ")" << endl;
Pk = j*Pa;
m1d = c1/Pk.x();
m2d = c2/Pk.y();
cout << "\nJane's decrypted message from Alice = (" << m1d << ", " << m2d << ")" << endl;
cout << endl;
}
|
|
|
|
|
Return it to where, and where and what are these variables?
Please also delete your duplicate of this post.
Use the best guess
|
|
|
|
|
Both threads are copies from here
|
|
|
|
|
How to get the process's DLL module address?
And How to get process imagebase?
|
|
|
|
|
It's not clear exactly what your problem is but you may want to start with GetModuleHandleEx() [^].
Use the best guess
|
|
|
|
|
Enumerating all modules in a process can be done by EnumProcessModules().
Here is an example of enumerating all modules in a process and displaying its names.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682621(v=vs.85).aspx
Load address of each modules can be retrieved by calling GetModuleInformation() for each modules.
lpBaseOfDll of MODULEINFO holds the load address of the corresponding module.
BOOL WINAPI GetModuleInformation(
__in HANDLE hProcess,
__in HMODULE hModule,
__out LPMODULEINFO lpmodinfo,
__in DWORD cb
);
|
|
|
|
|
HMODULE hMod = LoadLibrary("mydll.dll");
if (hMod) {
void (*)() myfn = (void (*)())GetProcAddress(hMod, "myfn");
if (myfn) myfn();
FreeLibrary(hMod);
}
EDIT:
Wasn't exactly sure what you're asking...
|
|
|
|
|
I have a list view with ownerdata and custom draw. when i do listview_update it updates the list but what If I want to update a specific column instead of all cols?
-----------------------
| col1 | col2 | col3 |
-----------------------
just col1 i is that possible?
|
|
|
|
|
Why not update the data that is used to populate the list? Then when the list is refreshed, the new values will be shown.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I have decided to simplify my database using plain text files.
So this is my first usage of MFC CFile and I am wondering why CFile → Read reads only up to the first comma it finds in the text file irregardless how many bytes it suppose to read.
Is that by design or did I missed something?
Thanks for you help.
Cheers
Vaclav
|
|
|
|
|
I am pretty sure you are doing something wrong, perhaps you can share some of your code with us. CFile is for generic, binary file handling and does not care which characters you read and write.
You might consider using CStdioFile instead - it operates on files in text mode and provides a ReadString()[^] method, which makes it simple to read a text file line-by-line.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Soren, thanks for your help.
Here is the read code.
I did add \n after the comma to the write text.
The file as around 230 bytes, ten string entries (sample "WS2EEE,\n") and even with the iReadBytes set to 250 it get only the first string with comma attached.
I am also having some problems with using Seek to next "record", but I can work on that later.
I was hoping to read the entire file and than process it , but I'll try the CStdioFile and read one line instead.
char pbuf[1000];
UINT nBytesRead;
UINT iRunningTotal = 0;
CString strField, strExcluded;
int iReadBytes = 250;
do
{
nBytesRead = pFile->Read( pbuf, iReadBytes );
TRACE("\nBuffer %s", pbuf);
// extract to delimiting comma
strField = pbuf; // kluge need to learn how to use CString buffer
strExcluded = strField .SpanExcluding( ";,.- :");
int iLenght = strExcluded.GetLength();
iReadBytes = iLenght + 2;
pFile->Seek(iLenght +1 ,CFile::current);
iRunningTotal += nBytesRead;
}while ( iRunningTotal < dwFileLength);
|
|
|
|
|
Change your loop to:
CString strLine;
while (file.ReadString(strLine))
{
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Sorry for the delay Vaclav, it has been one of those days.
I think you should do this with CStdioFile and get the text parsing all straightened out first. Follow David's advice for the read loop.
If you still want to do some testing with your current code, you need to clean up some things. You say you hope to read the whole file in and then process it. Well, then that is what you should do instead of doing both reading and processing in the loop.
I will recommend you use a CByteArray for the read buffer (I like its flexibility). Use CFile to check the size of the file, call SetSize() on the CByteArray object with that value, read the file in a single call (for now let's just assume your files will not be too large for that) and close the file. Then you use the loop to go through the buffer without doing anymore file handling.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Does anyone know a documented way to retrieve the command line of another process?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
documented ? by whom ?? - good luck
I know of no 100% foolproof way - the one way I do know of, is itself dangerous and uses CreateRemoteThread() (yes, its c++), and injects code into the running process.
The last time I needed to do this, I ended up writing a stub program with the same name of the exe I was trying to figure out (because the 3rd party involved themselves didnt know the some parameters they were passing into it dynamically, it was legacy code) - so my stub simply dumped the parameters to a log file - at least I had enough access to the system to be able to replace their exe temporarily
please let us know if you find something Richard
'g'
|
|
|
|
|
Thanks for your answer. I was afraid of that.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
See if this helps.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
That's a big help, thanks.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
What I am up to is resizing the bitmap from the clipboard then re send it to clipborad so it's kinda easy in VB take a look
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
My.Computer.Clipboard.SetImage(New Bitmap(bmp, CInt(bmp.Width / 2), CInt(bmp.Height / 2)))
End Sub
No how to do this under C?
So i can send the bitmap to the clipboard with these instructions
OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_BITMAP, Hbitmap);
CloseClipboard();
OpenClipboard(NULL);
and for bringing it
HBITMAP hbitmap = (HBITMAP)getclipboardData(CF_BITMAP)
and i know that I should use
StretchBlt() but i do not know how to accomplice that?
|
|
|
|
|
Assume you have a HBITMAP hbitmap which already contains your clipboard data. Then you can StretchBlt that data to a destination HDC hdc as below:
1. Create a compatible HDC in memory with your destination hdc
HDC memDC= CreateCompatibleDC(hdc);
2. Select your hbitmap into the memory DC
HBITMAP hOldBmp = (HBITMAP)SelectObject(memDC, hbitmap);
3. Use StretchBlt to resize it
StretchBlt(hdc, 0, 0, new_Width, new_Height, memDC, 0, 0, org_Width, org_Height, SRCCOPY);
4. Restore the old bitmap and free memory
SelectObject(memDC, hOldBmp);
DeleteDC(memDC);
Hope it helps
|
|
|
|
|
Thanks it helped me
|
|
|
|
|
You may use the CopyImage()[^] function:
BITMAP bm;
GetObject(hBitmap, sizeof(bm), &bm);
HBITMAP hCopy = (HBITMAP)CopyImage(hBitmap, IMAGE_BITMAP,
bm.bmWidth / 2, bm.bmHeight / 2,
LR_COPYDELETEORG);
SetClipboardData(CF_BITMAP, hCopy);
|
|
|
|
|