|
Right. Now I don't remember the wording, but its meaning is clear: An int shall be the fastest (natural) integral representation for the given target CPU (architecture).
As 64 bits is the natural integer size for a 64-bit CPU, I'd expect that 64-bit integer operations would be the fastest.
|
|
|
|
|
I'm trying to create a bitmap file from a memory device context but the only thing I create is a complete white bitmap.
Here my code:
MyFunction()
{
CClientDC dc(this);
CRect rectBF(0,0,450,450);
CBitmap bmp, *poldbmp;
CDC memdc;
bmp.CreateCompatibleBitmap(&dc, 450, 450);
memdc.CreateCompatibleDC( &dc );
poldbmp = memdc.SelectObject( &bmp );
</A>
m_ctlGraphWnd.DrawGraphToDC(&memdc, rectBF);
memdc.SelectObject(poldbmp);
CPalette palette;
if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE )
{
UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
pLP->palVersion = 0x300;
pLP->palNumEntries =
GetSystemPaletteEntries( dc, 0, 255, pLP->palPalEntry );
palette.CreatePalette( pLP );
delete[] pLP;
}
This code above works correctly. The graph was drawn in memdc.
HANDLE hDIB = DDBToDIB(bmp, BI_RGB, &palette);
if( hDIB == NULL )
return ;
WriteDIB(_T("graph.bmp"), hDIB);
GlobalFree( hDIB );
}
I don't know why but operations done on memdc aren't reflected in CBitmap bmp.
Thanks in advance!
|
|
|
|
|
Hi,
I have a Visual C++ 6.0 that uses a LictControl dialog, it works fine when I edit colums, rows on it! I also can print out its contents ... except:
a) I can not print the column titles
b) Somehow my fonts is very very small
PS: I do have a small zip project file ... I can not attach here. I can send to any one if I have the Email address!
- On the CNewDlg::OnInitDialog() ==> I insert colums titles and row text: OK!
- On the CNewDlg::OnBntPrint() ==> Please help in the // *********> actually do PRINTING here <******** (it locates at the end)
BOOL CNewDlg::OnInitDialog()
{
CDialog::OnInitDialog();
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
CString temp, strSQL;
LVCOLUMN column;
LVITEM item;
int i;
char* guestListCol[9] = {"Room#", "Status", "FirstName", "LastName",
"CheckIn", "Until", "ExtraDays", "Adults", "Children"};
column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
column.fmt = LVCFMT_LEFT;
temp = "CHECK-IN GUEST LIST REPORT FOR " + COleDateTime::GetCurrentTime().Format("%m/%d/%Y %H:%M:%S");
strSQL.Format ("SELECT * FROM CurrentGuestList WHERE GuestStatus = 'CheckIn'");
UpdateData (false);
for (i=0; i<9; i++)
{
column.cx = 75;
column.iSubItem = i;
column.pszText = guestListCol[i];
m_report.InsertColumn (i, &column);
}
m_report.DeleteAllItems();
item.mask = LVIF_TEXT;
item.iSubItem = 0;
i = 0;
item.iItem = i;
item.pszText = "dummy";
m_report.InsertItem (&item);
m_report.SetItemText (i, 0, "101");
m_report.SetItemText (i, 1, "Check-In");
m_report.SetItemText (i, 2, "John");
m_report.SetItemText (i, 3, "Senior");
m_report.SetItemText (i, 4, "May/20/2002");
m_report.SetItemText (i, 5, "May/22/2002");
m_report.SetItemText (i, 6, "1");
m_report.SetItemText (i, 7, "2");
m_report.SetItemText (i, 8, "4");
return TRUE;
}
void CNewDlg::OnBntPrint()
{
CPrintDialog dlg (FALSE);
if (dlg.DoModal() == IDOK)
{
HDC hdc = dlg.GetPrinterDC();
CDC dc;
DOCINFO docinfo;
memset(&docinfo, 0, sizeof(docinfo));
docinfo.cbSize = sizeof(docinfo);
docinfo.lpszDocName = _T("CDC::StartDoc() Code Fragment");
dc.Attach(hdc);
if (dc.StartDoc(&docinfo) < 0)
MessageBox(_T("Printer wouldn't initalize"));
else
{
if (dc.StartPage() < 0)
{
MessageBox(_T("Could not start page"));
dc.AbortDoc();
}
else
{
m_report.Print(&dc, PRF_NONCLIENT);
m_report.Print(&dc, PRF_CLIENT);
}
dc.EndPage();
dc.EndDoc();
}
}
}
I tried to do a lot of things but failed, can anyone help me?
Thanks
ATC
|
|
|
|
|
i am using this code to put every other letter in a Cstring into a CString variable.
CString mPWD;
CString szTemp;
BOOL bMakePass = TRUE;
CString m_cPwd;
m_cPwd = szPassword;
for (int i = 0; i < m_iPwdLength; i++)
{
if (bMakePass)
{
szTemp = mPWD;
mPWD.Format("%s", m_cPwd.GetAt(i));
szTemp += mPWD;
mPWD = szTemp;
bMakePass = FALSE;
}
else
bMakePass = TRUE;
}
return mPWD;
but it causes the app to crash.
==================================================
Homepage: www.onyeyiri.co.uk
Email: theeclypse@hotmail.com
"I'm not any old Eclypse, i'm TheEclypse..get it, got it, good!"
|
|
|
|
|
CString s = "Hello World from Nish";
CString t="";
for(int i=0;i<s.GetLength();i+=2)
t+=s[i];
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
While Nish gave you a solution that works more efficiently than the code you posted here, the reason you code gives you an error is because your
mPWD.Format("%s", ... statement is wrong. You are passing in a single character, not a string, so you should have used
mPWD.Format("%c", ... instead.
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
I need to convert a CString to a char.
Unless anyone know how to pick the 3rd character in on a CString.
==================================================
Homepage: www.onyeyiri.co.uk
Email: theeclypse@hotmail.com
"I'm not any old Eclypse, i'm TheEclypse..get it, got it, good!"
|
|
|
|
|
use GetAt()
for example if CString temp="test"
out=temp.GetAt(3);
!! Put it in a if statement to prevent a asertation error:
if temp.GetLength()>2{ // e.g. 3
out=temp.GetAt(3);
}
Hope that helped.
An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
|
|
|
|
|
You can do it just like it was a char string.
CString m_sTest;
char c;
c = m_sTest[2];
You could also use the Mid function on the CString.
Ed
|
|
|
|
|
The Eclypse wrote:
Unless anyone know how to pick the 3rd character in on a CString
I think this could work:
CString str;
str = "123";
if (str[2] == '3') {
TRACE("Hey, you've got it!\n");
}
|
|
|
|
|
Hiya,
Please halp me! I need some code to read & write registry keys in a particular place that already exists:
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
above is the location and then i need to write a new key & read a key. DWord and Edit. Is there a simple way to do this?
Thank you for your time.
An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
|
|
|
|
|
There is CRegKey class in the VC++ 6.0 installation somewhere, it is easy to use.
|
|
|
|
|
I dont understand (Sory) How do i get at / read that?
An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
|
|
|
|
|
This is declaration of that class:
class CRegKey
{
public:
CRegKey();
~CRegKey();
// Attributes
public:
operator HKEY() const;
HKEY m_hKey;
// Operations
public:
LONG SetValue(DWORD dwValue, LPCTSTR lpszValueName);
LONG QueryValue(DWORD& dwValue, LPCTSTR lpszValueName);
LONG QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount);
LONG QueryValue(BYTE *pbValue, LPCTSTR lpszValueName, DWORD* pdwCount);
LONG SetValue(LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
LONG SetValue(BYTE *pbValue, DWORD dwLength, LPCTSTR lpszValueName = NULL);
LONG SetKeyValue(LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
static LONG WINAPI SetValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass = REG_NONE, DWORD dwOptions = REG_OPTION_NON_VOLATILE, REGSAM samDesired = KEY_ALL_ACCESS, LPSECURITY_ATTRIBUTES lpSecAttr = NULL, LPDWORD lpdwDisposition = NULL);
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired = KEY_ALL_ACCESS);
LONG Close();
HKEY Detach();
void Attach(HKEY hKey);
LONG DeleteSubKey(LPCTSTR lpszSubKey);
LONG RecurseDeleteKey(LPCTSTR lpszKey);
LONG DeleteValue(LPCTSTR lpszValue);
};
and you can do this:
CRegKey reg;
reg.Open(HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Internet Settings");
and then
reg.QueryValue(...); //to read value
reg.SetValue(...) //to write value
|
|
|
|
|
I hope im not being a pain. I tryed this and it worked fine:
char* text;
//unsigned long* buffer;
DWORD* buffer;
unsigned long PerServer;
unsigned long Per1_0Server;
CRegKey reg;
reg.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
reg.QueryValue(PerServer,"MaxConnectionsPerServer");
but when i try to read a string (the windows version name) with:
reg.Open(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion");
reg.QueryValue(text,"ProductName",buffer);
i get an assertation error on the line "pdwCount!=null;" (in CRegKey) if i change buffer to anything using "buffer=(unsigned long*)999;" i dont get the error but i get no data.
Am i being stupid? I cant see where im going wrong.
An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
|
|
|
|
|
Lucky the code machine wrote:
Date:13:17 29 May '02
You had posted your answer to my message two minutes before I posted it.
|
|
|
|
|
Nice! Im in England so i guess something to do with that? Thanks a lot for that on registrys, i will try that. Looks good. Thanks
An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
|
|
|
|
|
I'm a fairly new Windows Programmer (C++). I was wondering if anyone had any good ideas on how saving of results work. For example, if I want to run a loop where a result is achieved every time, how could I save this data so that I could view and print all of the results together?
Trevor
|
|
|
|
|
Anonymous wrote:
For example, if I want to run a loop where a result is achieved every time, how could I save this data so that I could view and print all of the results together?
You can use an array. If your data is complicated, you can have an array of structs.
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
What I am trying to do may be considered mental mastrubation, but here is the question:
can I programmatically:
- count the number of items in a structure;
- get access to any of the items by its index (but not by its name) while presersing the names of these items.
The following example should make it clear:
I have a struct:
struct BBG_SECURITIES {
long nRecords; // Number of Entries
CStringArray sName; // Security Name
CStringArray sTicker; // Security Ticker
CStringArray sMarket; // Security Market
CStringArray sIssuer; // Issuer
CStringArray sCoupon; // Coupon
CStringArray sFrequency; // Frequency
CStringArray sMaturity; // Maturity Date
CStringArray sCurrency; // Currency
CStringArray sCountry; // Country
CStringArray sDBRS; // DBRS Bond Rating
CStringArray sSP; // S&P Bond Rating
CStringArray sMoody; // Moody's Bond Rating
CStringArray sBloomberg; // Bloomberg Composite Bond Rating
};
And I am lazy to write all of that each time:
m_strCurrentUniverse
.nRecords = NULL
.sName.SetSize(0)
.sTicker.SetSize(0)
.sMarket.SetSize(0)
.sIssuer.SetSize(0)
.sCoupon.SetSize(0)
.sFrequency.SetSize(0)
.sMaturity.SetSize(0)
.sCurrency.SetSize(0)
.sCoutry.SetSize(0)
.sDBRS.SetSize(0)
.sSP.SetSize(0)
.sMoody.SetSize(0)
.sBloomberg.SetSize(0);
What I want to set up some kind of a loop:
int nItems = GET ITEM COUNT IN THE STRUCT
for (i = 0; i < nItems; i++) {
xxx = GET STRUCT ITEM
xxx.SetSize(0);
}
Any thoughts?
Thank you.
|
|
|
|
|
Here are your options
1. Change to array
struct BBG_SECURITIES {
long nRecords; // Number of Entries
CStringArray* entries; // Security Name
BBG_SECURITIES()
{
entries = new CStringArray[13];
}
};
Looping then would be straight forward.
2. Unstructured and unsafe method
BBG_SECURITIES sec;
int nItems = (sizeof(BBG_SECURITIES) - sizeof(long))/sizeof(CStringArray);
CStringArray* pIter = (CStringArray*)&sec.sName;
for(int i = 0; i < nItems; i++)
{
pIter->SetSize(0);
pIter++;
}
|
|
|
|
|
Thanks for your reply:
* Wouldn't this fail if the structure is NOT empty (e.g., I have 5 elements in each CStringArray):
int nItems = (sizeof(BBG_SECURITIES) - sizeof(long))/sizeof(CStringArray);
* I am not quite sure what you are doing here:
CStringArray* pIter = (char*)&sec.sName;
sName is supoposed to be unknown.
* Any other reasons for calling this an unsafe method?
Thanks
|
|
|
|
|
Anton A. Loukine wrote:
CStringArray* pIter = (char*)&sec.sName;
Sorry a typo it should be,
CStringArray* pIter = &sec.sName;
|
|
|
|
|
Actually best thing for you would be to write a devstudio macro.
|
|
|
|
|
Can you elaborate on this a little bit. I am not familiar with macros and how they affect performance
|
|
|
|
|