|
Larry Mills Sr wrote: David, the first (1) picker has an assigned varable of m_cDate...if I use CString str = m_cDate.GetTime() will it return a str with the value in the picker?
No, it "returns" a SYSTEMTIME pointer, a COleDateTime object, or a CTime object.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Simply put; how do I get the value the User has selected in the picker into a CString? simple code plese!
A C++ programming language novice, but striving to learn
|
|
|
|
|
Did you look at any of the three objects I referenced?
Use one of those along with CString::Format() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
If you are talking about this: "No, it "returns" a SYSTEMTIME pointer, a COleDateTime object, or a CTime object."
I still don't understand how what the User selects will be relayed to the instance of one of these " "returns" a SYSTEMTIME pointer, a COleDateTime object, or a CTime object."
when You initialize the m_cDatew or m_cTime varables with one of those; how will it also retrieve the User's response? Wouldn't you receive back the same initialization you inputed to the varables?
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: I still don't understand how what the User selects will be relayed to the instance of one of these " "returns" a SYSTEMTIME pointer, a COleDateTime object, or a CTime object."
By using the GetTime() method. It comes in three different flavors depending on what type of object you want in return.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hello everybody,
I've got a console project generating 6 elements combinations of strings(6 out of 10)for example:
ia11,ia72,ia190,ia21,ia102,ia180
ia11,ia72,ia167,ia64,ia102,ia178
etc...
(altogether 210 combinations)
I've also got a map:
typedef map<string,vector<int> >container;
container::iterator it;
container map;
map.insert(make_pair("ia11", via11));
map.insert(make_pair("ia34", via34));
map.insert(make_pair("ia72", via72));
map.insert(make_pair("ia167", via167));
map.insert(make_pair("ia190", via190));
map.insert(make_pair("ia21", via21));
map.insert(make_pair("ia64", via64));
map.insert(make_pair("ia102", via102));
map.insert(make_pair("ia178", via178));
map.insert(make_pair("ia180", via180));
The map has also string keys(the same as in the console output in order to make comparison possible).
That's because I want to populate the console output with integer values from the map vectors.
In other words the map is the source of data for the output. To put it in other way: when we've got ia21 in the output, the programme should compare it to the map and find a string key in the map (which is ia21 too) and after that insert values of integer from the vector(value in the map)into the string output.
What is the simpliest way to do it? What classes, compare functions or bool operators should I use?
I would be grateful for any kind of help!
|
|
|
|
|
Use map::find[^] to search for the string in the map.
It will return an iterator which will be equal to map::end[^] if the string is not found.
The iterator has a parameter called second which will be the vector of integers.
Use second to get an iterator to a vector of integers and iterate from vector::begin till vector::end to read all the integers.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Dear Superman,
I have thought out what you said last night and tried to take your advice practically, but somehow it doesn't work. (I also came to a conclusion how little I know about iterators. I promise to learn more about them.)The code map::find consists of two parts. And to be honest I'm not interested in finding one or two vectors in the map (this is in the first part of the code). My task is to find all the vectors matching the string output keys.(if I understood it correctly, this would be the second part about using a dereferenced iterator, but I'm not sure). The fact is I got completely lost in those damn iterators!
Here's what I wrote with header files to compile and run it.
cpp. first-
#include "IndexCombination.h"
using namespace stdcomb;
void CIdxComb::Init( unsigned int SetSize, unsigned int CombSize )
{
// Assign CombSize
////////////////////////
if( CombSize == 0 )
CombSize = 1;
m_ArrSize = CombSize;
m_LastIdx = CombSize - 1;
// Assign SetSize
////////////////////////
if( SetSize == 0 )
SetSize = 2;
if( CombSize > SetSize )
CombSize = SetSize;
m_SetSize = SetSize;
m_LastSetIdx = SetSize - 1;
}
bool CIdxComb::SetSizes( unsigned int SetSize, unsigned int CombSize )
{
if( SetSize == 0 )
return false;
if( CombSize == 0 )
return false;
if( CombSize > SetSize )
return false;
m_ArrSize = CombSize;
m_LastIdx = CombSize - 1;
m_SetSize = SetSize;
m_LastSetIdx = SetSize - 1;
return true;
}
bool CIdxComb::GetNextComb( std::vector<unsigned int> &vi )
{
// Check if the last element is at the end
if( vi[m_LastIdx] == m_LastSetIdx )
{
if( m_ArrSize == 1 ) // Completed
return false;
// Check if the subsequent elements(counted from back)
// is also at their subsequent positions
//////////////////////////////////////////////////////
bool Completed = true;
// Incomplete Index, init value not used
unsigned int IncompIdx = m_LastIdx - 1;
bool FirstIdx = false;
unsigned int ArrIdx = m_LastIdx - 1;
unsigned int SetIdx = m_LastSetIdx - 1;
while( !FirstIdx )
{
if( vi[ArrIdx] != SetIdx )
{
Completed = false;
IncompIdx = vi[ArrIdx] + 1;
break;
}
if( SetIdx )
--SetIdx;
if( !ArrIdx )
FirstIdx = true;
else
--ArrIdx;
}
if( Completed )
return false;
else
{
for( unsigned int i=ArrIdx; i<=m_LastIdx; ++i, ++IncompIdx )
{
vi[i] = IncompIdx;
}
}
}
else if ( vi[m_LastIdx] < m_LastSetIdx )
{
(vi[m_LastIdx])++;
}
else // bigger than the m_LastIdx! Impossible!
{
return false;
}
return true;
}
h.next-
//Index Combination.h
#include <vector>
#ifndef _INDEXCOMBINATION_H_
#define _INDEXCOMBINATION_H_
namespace stdcomb
{
class CIdxComb
{
public:
// Constructor
CIdxComb()
{
Init( 2, 1 );
};
CIdxComb( unsigned int SetSize, unsigned int CombSize )
{
Init( SetSize, CombSize );
};
// Destructor
~CIdxComb() {};
void Init( unsigned int SetSize, unsigned int CombSize );
bool SetSizes( unsigned int SetSize, unsigned int CombSize );
bool GetNextComb( std::vector<unsigned int> &vi );
protected:
unsigned int m_ArrSize;
unsigned int m_LastIdx;
unsigned int m_SetSize;
unsigned int m_LastSetIdx;
};
}
#endif // _INDEXCOMBINATION_H_
#include <vector>
and finally what I tried to do-
// IntComb.cpp : Defines the entry point for the console application.
#include "IndexCombination.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <map>
#include <sstream>
#include <utility>
#include <list>
using namespace std;
using namespace stdcomb;
template <class K, class V>
class key_equals {
private:
K key;
public:
// constructor (initialize key to compare with)
key_equals (const K& k)
: key(k) {
}
// comparison
bool operator() (pair<const K, V> elem) {
return elem.first == key;
}
};
int main(int argc, char* argv[])
{
int ia11[30] = {3,9,17,21,24,31,33,36,42,49,
4,8,19,22,28,30,34,39,43,47,
2,6,10,13,14,25,29,37,38,46};
int ia34[30] ={1,6,12,15,22,27,31,32,41,42
,4,7,14,17,23,30,33,36,45,48
,2,9,13,18,21,26,34,39,44,49};
int ia72[30] = {3,8,11,18,22,25,36,37,43,46
,1,6,16,17,23,28,35,40,41,44
,2,5,12,19,24,27,31,34,42,49};
int ia167[30] ={3,4,12,15,21,28,32,39,47,48
,6,9,16,17,29,30,31,38,41,42
,7,8,11,20,26,27,34,35,45,46};
int ia190[30] = {3,10,11,14,22,23,32,35,43,44
,6,9,16,19,24,29,37,38,45,48
,2,5,13,18,25,30,31,40,41,0};
int ia21[30] ={ 2,5,16,19,25,30,34,39,45,48,
1,9,12,13,21,24,33,36,44,49,
3,8,15,20,23,26,35,40,43,46};
int ia64[30] ={6,9,13,20,28,29,33,40,43,48
,2,7,16,19,24,27,31,34,44,47
,5,8,14,17,21,30,32,37,41,46};
int ia102[30] ={4,9,14,19,22,29,35,38,46,47
,5,8,13,16,21,26,33,40,41,48
,6,7,15,17,28,30,32,39,42,45};
int ia178[30] ={6,9,15,20,23,24,37,38,42,45
,7,8,16,19,22,25,34,39,43,46
,1,2,17,18,26,29,31,40,47,0};
int ia180[30] ={1,4,13,18,27,30,33,38,45,46
,2,3,12,15,22,23,39,40,44,47
,8,9,11,17,24,25,32,37,49,0};
vector<int>via11(ia11,ia11+30);
vector<int>via34(ia34,ia34+30);
vector<int>via72(ia72,ia72+30);
vector<int>via167(ia167,ia167+30);
vector<int>via190(ia190,ia190+30);
vector<int>via21(ia21,ia21+30);
vector<int>via64(ia64,ia64+30);
vector<int>via102(ia102,ia102+30);
vector<int>via178(ia178,ia178+30);
vector<int>via180(ia180,ia180+30);
CIdxComb cb;
cb.SetSizes(10,6);
vector<string> vsia;
vsia.push_back( "ia11" );
vsia.push_back( "ia34" );
vsia.push_back( "ia72" );
vsia.push_back( "ia167" );
vsia.push_back( "ia190" );
vsia.push_back( "ia21" );
vsia.push_back( "ia64" );
vsia.push_back( "ia102" );
vsia.push_back( "ia178" );
vsia.push_back( "ia180" );
vector<unsigned int> vi(6);
vi[0] = 0;
vi[1] = 1;
vi[2] = 2;
vi[3] = 3;
vi[4] = 4;
vi[5] = 5;
cout<< vsia[ vi[0] ] << " "
<< vsia[ vi[1] ] << " "
<< vsia[ vi[2] ] << " "
<< vsia[ vi[3] ] << " "
<< vsia[ vi[4] ] << " "
<< vsia[ vi[5] ] << "\n";
int Total = 1;
while ( cb.GetNextComb( vi ) )
{
// "Do whatever processing you want" - I want to put all the values
// from the vectors to their 6 elemnts combinations
{
map<string,vector<int> > m1;
map <string,vector<int> > :: const_iterator m1_AcIter, m1_RcIter;
typedef pair<string,vector<int> > String_Int_Pair;//there has been a change here
m1.insert(make_pair("ia11", via11));
m1.insert(make_pair("ia34", via34));
m1.insert(make_pair("ia72", via72));
m1.insert(make_pair("ia167", via167));
m1.insert(make_pair("ia190", via190));
m1.insert(make_pair("ia21", via21));
m1.insert(make_pair("ia64", via64));
m1.insert(make_pair("ia102", via102));
m1.insert(make_pair("ia178", via178));
m1.insert(make_pair("ia180", via180));
m1_AcIter = m1.end( );
m1_AcIter--;
m1_RcIter = m1.find( m1_AcIter -> first );
cout << m1_RcIter -> second << "." << endl;//The compiler stops here.
// I don't want only
//one particular string - representing vector of course - to be copied to output.
// I've got 210 combinations each of 6 strings. That makes 1260 strings altogether
// to be identified and filled with vectors values of integer .
}
cout<< vsia[ vi[0] ] << " "
<< vsia[ vi[1] ] << " "
<< vsia[ vi[2] ] << " "
<< vsia[ vi[3] ] << " "
<< vsia[ vi[4] ] << " "
<< vsia[ vi[5] ] << endl;
++Total;
}
cout<< "\nTotal : " << Total << endl;
system( "pause" );
return 0;
}
If you could help me, I would be really happy!
Looking forward to hearing from You,
Waldemar
|
|
|
|
|
Hello.
How get the video card memory size(total physical video ram size) under vc++ ?
I tried with IDirect3DDevice9::GetAvailableTextureMem(); ,but not work.
Thanks for help!
|
|
|
|
|
Try to get this info using WMI and Win32_VideoController based on COM API for WMI.I'm not 100% sure but MaxMemorySupported member of this class should do the job.
Life is a stage and we are all actors!
|
|
|
|
|
Avoid WMI
See on Win32 ng[^] for official method (internal)
|
|
|
|
|
I find this code:
#include "stdafx.h"
#include <Ddraw.h>
int main( int argc, char* argv[] )
{
LPDIRECTDRAW7 lpDD;
DDSCAPS2 ddsCaps2;
DWORD dwTotal;
DWORD dwFree;
HRESULT hr;
hr = lpDD->QueryInterface(IID_IDirectDraw7, &lpDD);
if (FAILED(hr))
return hr;
// Initialize the structure.
ZeroMemory(&ddsCaps2, sizeof(ddsCaps2));
ddsCaps2.dwCaps = DDSCAPS_VIDEOMEMORY;
hr = lpDD->GetAvailableVidMem(&ddsCaps2, &dwTotal, &dwFree);
if (FAILED(hr))
return hr;
}
but doesn 't work.
The errors:(2)
error C2039: 'QueryInterface' : is not a member of 'IDirectDraw7'
error C2039: 'GetAvailableVidMem' : is not a member of 'IDirectDraw7'
|
|
|
|
|
?
Thanks.
Easy Profiler : a compile-time profiler for C++
www.potatosoftware.com
modified on Sunday, August 16, 2009 5:41 PM
|
|
|
|
|
The SetActivePage() method looks promising.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
I have a wizard application and it was all necessary to use such function in scenarios where I let the user to skip some pages..
Searched the internet, with no use, yesterday and consequently posted my question 10 hours ago but was all sure that if there would be a solution then an answer won't be sent until the sun reaches the US.
Thanks.
Easy Profiler : a compile-time profiler for C++
www.potatosoftware.com
|
|
|
|
|
Hi,
My application i calls a dll[Dll1.dll] which installs an keyboard
hook. Whenever user presses some key the hook function will execute
from another dll[Dll2.dll]. The hook function will try to create a COM
object using CoCreateInstance.I have given CoInitialize on top. The
problem is that the CoCreateInstance fails with error 1008. Please
tell me what is happening.
The same code is running perfectly when i use it in different exe or
dll. I am using the following code
CoInitialize(NULL);
IShellWindows *psw;
if (SUCCEEDED(CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL,
IID_IShellWindows, (void**)&psw)))
AfxMessageBox(L"Pass");
else{
CString str;
str.Format(L"%d",GetLastError());
AfxMessageBox(str);
}
The value in the HRESULT is - "Failed to allocate necessary memory"
This problem only occurs within the hook function. Any other function
in the same dll i put this code it works just fine.
I am using VC++2005 as my development envoirnment.
Any security reasons??
Thanks,
J
|
|
|
|
|
Hello guys
i have a problem with my SDI program
i show some data in my document and when i want see print preview or print data which shown in doc i see data in small font. how can i fix this problem
regards.
|
|
|
|
|
I'm assuming you're drawing the text in the OnDraw function.
The passed in CDC object will by default use its currently selected font which could be different for the screen and printer.
To get the same font across the screen and printer, in the OnDraw function, create a CFont object and use SelectObject to attach it to the passed in CDC object.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hi,
How to use mouse as an erasing tool while holding its right button ??
Thanks for any help.
|
|
|
|
|
Is this a programming question?
Otherwise, try this[^]. Just glue it to the bottom of the mouse.
|
|
|
|
|
How and what you erase is entirely up to your program to decide.
Basically you need to write the erasing code in the WM_MOUSEMOVE[^] handler.
You get if the right mouse button is down by checking wParam for MK_RBUTTON.
And you will get the mouse coordinates from lParam.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I know everything except how this erasing code should look like. So I beg for any help with this code.
And this is exactly what I want to do:
Using left button I'm drawing a sketch, but in case of a mistake I want to use right button to remove part of this sketch.
Thanks for any help.
|
|
|
|
|
kudlaty79 wrote: I know everything except how this erasing code should look like.
That's exactly what Superman was explaining to you: there's nothing like a standard erasing tool. You have to implement it yourself and how you're going to implement it is fully dependent on how you draw your data. So, if you want some suggestions here, you will need to explain in details how you draw your data.
|
|
|
|
|
Here is drawing code:
void COrder::OnLButtonDown(UINT nFlags, CPoint point)
{
if(drawing_status==1)
{
last_point = point;
}
CDialog::OnLButtonDown(nFlags, point);
}
void COrder::OnLButtonUp(UINT nFlags, CPoint point)
{
if(drawing_status==1)
{
UpdateWindow();
}
CDialog::OnLButtonUp(nFlags, point);
}
void COrder::OnMouseMove(UINT nFlags, CPoint point)
{
if(drawing_status==1)
{
CClientDC draw(this);
CPen pen;
if((nFlags & MK_LBUTTON)==MK_LBUTTON)
{
pen.CreatePen(PS_SOLID, 1, RGB(0,0,255));
draw.SelectObject(pen);
if(last_point.x<322 || last_point.x>626 || last_point.y<372 || last_point.y>596)
{
}
else
{
draw.MoveTo(last_point);
draw.LineTo(point);
}
last_point = point;
}
CDialog::OnMouseMove(nFlags, point);
}
|
|
|
|
|
Please use the pre tags to format your code properly as specified in the posting guidelines.
Now to your problem: you approach on drawing your data is wrong. You shouldn't draw directly on the screen in response to a mouse event. Doing so will causes many problems: try to put another window in front of your window (or minimizing your window) and then making your window visible again. You'll see that your drawings have disappeared.
What you should do instead is store all the points where you clicked with the mouse as pure data and refresh your view. The OnPaint handler will be called and there you need to redraw everything. Search for the scribble example on MSDN, this will show you exactly how to do so.
Once this is done, erasing becomes "easier" because you only need to remove points of data which are stored in your document. This depends a bit how you want your erase tool to work: remove a complete line, or only sections, ...
|
|
|
|
|