|
This is what's called the explicit function for a straight line, meaning that you calculate one coordinate based on the value of the other coordinate. The explicit representation comes with a few shortcomings that can be confusing at times when you deal with 2D geometrical elements. For example you wouldn't be able to draw a vertical line with an equation like what you posted! Also, for near vertical lines you'd have to take care what values of x would produce a valid y - you'll find that most values of x that lie well within the screen corrdinate range will produce y values that are way outside the screen.
The implicit representation avoids this confusion, but it is often much easier to use the parametric representation: In this case, you have two points, A and B. The parametric representation of a line through these two points is:
P(t) = A + t*(B-A) . This equation is in fact a set of equations, referring to the two coordinates, x and y:
P(t).x = A.x + t*(B.x-A.x)
P(t).y = A.y + t*(B.y-A.y)
If you implement a function to calculate P(t), using the formulas above, each value of t will yield a point P(t) somewhere on this line. For t==0 you will find that P(0)==A, and for t==1 you will find that P(1)==B.
Of course, you have to be careful with these calculations when dealing with pixel coordinates: you have to convert these coordinates to float values first, or else the rounding effects may lead to some unexpected results.
|
|
|
|
|
Thanks for the replies I finally got it working.
|
|
|
|
|
I know that the cbegin()/cend() and such methods were implemented to allow for easy const type inference, but I'm curious as to why there wasn't any equivalent added for find()? Also, there isn't a real easy way to "trick" auto into inferring a const version, is there?
Although it doesn't show itself as non-mutating in code, all I can think to do is use a const ref/pointer to the container, which would "force" a const_iterator return, right?
However, I really like how cbegin() clearly states it's const-ness, right where it's being used.
I've searched around off and on, looked through the (what I think is) the original proposal paper, nothing seems to hint as to why poor find() got the const-shaft.
Curious,
CraigL
|
|
|
|
|
The problem with find is that it's not a member function, and the const-ness of its return type depends on the const-ness of its arguments. If you call find with a search range defined by const_iterator 's, the return type will be a const_iterator , whether you like it or not. Similarly, if you tried to define a cfind() function that should return a const_iterator even if the arguments defining the range are non-const iterator , then you're facing the problem of how to derive the former type from the latter - it's impossible!
For begin and end it's different: their return types are derived from the list object, and it's easy to derive both iterator and const_iterator from the list type. find() has no such base type to refer to.
|
|
|
|
|
Sorry, I should have been more specific. Rather than general containers (some of which, you're right, have to use the find function) the map/set and the new unordered ones. They do have a member function, so could quite easily do the same thing as cbegin()/cend(), at least I can't see any reason why not.
For the not-to-const, I don't exactly follow. Gonna go play a bit to see what you mean.
Thanks,
CraigL
|
|
|
|
|
Hi, iam trying to display a browser control of type CWebBrowser2 in a dialog, which will be initiated from a dll.
now, the problem is, the dialog is getting displayed properly, when i dont insert the webbrowser control.
but when i draw the webbrowser control on the dialog, it is not showing up.
i even tried to create it dynamically, but Create method is returning by closing the application.
any ideas?
thanks in advance.
modified on Friday, June 17, 2011 5:19 PM
|
|
|
|
|
further investigations on this issue, concluded that, the window itself was not getting properly created for the web browser control. any ideas?
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
chandu004 wrote: the window itself was not getting properly created for the web browser control.
Derive your Dialog from CDialog instead of CHtmlDialog , while adding the Dialog through MFC Wizard and add a web browser control to it. Use the Navigate() method to browse to a URL.
|
|
|
|
|
after some browse through the net, i could solve this problem by adding AfxOleInit() in the calling application's InitInstance.
|
|
|
|
|
Hi,
short m_start_year;
COleDateTime tm = COleDateTime::GetCurrentTime();
m_start_year = (short) tm.GetYear();
I need to convert this m_start_year to CString to pass a argument for below function.
CString result_startdate = GetShowYear(m_start_year);
CString GetShowYear(CString m_start_year)
{
// Here i will do the Inline query and get the show start date.
}
In the above code how to cast short to CString as the GetShowYear need to pass only CString value but from tm.GetYear() i am getting as "short" value.
Any idea?
Reg,
SPa
|
|
|
|
|
Use CString::Format funcion to convert short to string like this.
CString strYear;
strYear.Format("%d", m_start_year);
http://www.mono-project.com/Main_Page
|
|
|
|
|
Simple yet very effective.
|
|
|
|
|
You cannot cast a short to a string, you need to use a converter such as sprintf() or similar.
The best things in life are not things.
|
|
|
|
|
In addition, _itoa() and similar functions are also there.
|
|
|
|
|
This code only writes the last registry entry to the ComboBox.
*I want to read all the registry entries and insert it to a ComboBox(DropDown List)*
HKEY phkResult = NULL;
LONG enumresult = 0;
TCHAR valuename[256]={0};
BYTE valuedata[4096]={0};
DWORD valuenamesize = sizeof(valuename);
DWORD valuedatasize = sizeof(valuedata);
if (RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\MY_PROG_KEY",0,KEY_READ,&phkResult) == ERROR_SUCCESS)
{
CCombo* InsCombo;
InsCombo = (CComboBox*) GetDlgItem(IDC_COMBO1);
int index = 0;
do
{
DWORD valuenamesize = sizeof(valuename);
DWORD valuedatasize = sizeof(valuedata);
enumresult=RegEnumValue(phkResult, index, valuename, &valuenamesize, 0,
NULL,
valuedata,
&valuedatasize);
m_ComboStr1=valuedata;
InsCombo->AddString(m_ComboStr1);
UpdateData(FALSE);
index ++;
m_ComboStr1='\0';
}while (enumresult != ERROR_NO_MORE_ITEMS);
RegCloseKey(phkResult);
}
<div class="modified">modified on Wednesday, June 15, 2011 5:21 AM</div>
|
|
|
|
|
It looks like you're misusing UpdateData() in the loop. Remove it, and handle such things after the loop.
|
|
|
|
|
I did that already, but after moving it outside the loop; ComboBox is not showing any string.
|
|
|
|
|
What is the definition of m_ComboStr1 ; also have you checked (with the debugger) that you are getting a valid string from RegEnumValue() ? I note also that you are redeclaring valuenamesize and valuedatasize within your do loop: this is not correct (even though it will not cause problems in this instance). Other than that the code would seem to be correct.
The best things in life are not things.
|
|
|
|
|
This piece of code as you suggested gives following error. Please Suggest.
Previous case : m_ComboStr1 is variable attached to the ComboBox (CString type)
Note: I'm new to VC++ programming.
error C2664: 'AddString' : cannot convert parameter 1 from 'unsigned char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
HKEY phkResult = NULL;
LONG enumresult = 0;
TCHAR valuename[256]={0};
BYTE valuedata[4096]={0};
DWORD valuenamesize = sizeof(valuename);
DWORD valuedatasize = sizeof(valuedata);
if (RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\MY_PROG_KEY",0,KEY_READ,&phkResult) == ERROR_SUCCESS)
{
CComboBox* InsCombo;
InsCombo = (CComboBox*) GetDlgItem(IDC_COMBO1);
int index = 0;
do
{
enumresult=RegEnumValue(phkResult, index, valuename, &valuenamesize, 0,
NULL,
valuedata,
&valuedatasize);
InsCombo->AddString(valuedata[index]);
index ++;
}while (enumresult != ERROR_NO_MORE_ITEMS);
RegCloseKey(phkResult);
}
|
|
|
|
|
Well the message is pretty clear; you are passing a character to a function that expects a string (const char* ). Try changing to something of the order of:
InsCombo->AddString(reinterpret_cast<const char*>(valuedata));
The best things in life are not things.
|
|
|
|
|
I appreciate your help.
The same code worked; as I did a silly mistake I needed to increase the drop down area
Thanks
HKEY phkResult = NULL;
LONG enumresult = 0;
TCHAR valuename[256]={0};
BYTE valuedata[4096]={0};
DWORD valuenamesize = sizeof(valuename);
DWORD valuedatasize = sizeof(valuedata);
if (RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\MY_PROG_KEY",0,KEY_READ,&phkResult) == ERROR_SUCCESS)
{
CComboBox* InsCombo;
InsCombo = (CComboBox*) GetDlgItem(IDC_COMBO1);
int index = 0;
while(RegEnumValue(phkResult, index, valuename, &valuenamesize, 0,
NULL,
valuedata,
&valuedatasize)!=ERROR_NO_MORE_ITEMS)
{
InsCombo->AddString(reinterpret_cast<const char*>(valuedata));
index ++;
}
}
RegCloseKey(phkResult);
return TRUE;
modified on Wednesday, June 15, 2011 5:20 AM
|
|
|
|
|
Gaurav Paul wrote: InsCombo->AddString(reinterpret_cast<const char*>(valuedata[index]));
You should not be using an offset value (valuedata[index] ) but merely the address of the array (valuedata ) as shown in my previous post.
The best things in life are not things.
|
|
|
|
|
I have done that; actually I posted the old code.
|
|
|
|
|
Am I to assume it is now working successfully?
The best things in life are not things.
|
|
|
|
|
Yes it is! Thanks.
|
|
|
|
|