Another sidenote if you are using MFC: If you create gui elements (windows, etc..) from another thread its a problem because MFC installs hooks on newly created gui stuff and registers this-and-that to its internal structures that are not thread safe and you can cause all kind of diseases!
Then is_from_keyboard() below is better suited. It includes punctuation , spaces etc.
int is_from_keyboard(int ch)
if ( ch>31 && ch<128) return1;
cout<<"The ASCII character -> "<<ch<<" ("<<(int)ch<<") <- is from the keyboard. \n\n";
cout<<"The ASCII character -> "<<ch<<" ("<<(int)ch<<") <- is NOT from the keyboard. \n\n";
i am having a combobox (created through resource), and through code, i am updating the combobox with a list. for example, i am filling with "Kir" and "K". if i use CB_SELECTSTRING to select "K", its always selecting "Kir".
if i use "Kj" in place of "K", then the selection between "Kir" and "Kj" is fine.
from msdn definition : It selects the first list item, if any, that begins with the characters in the specified text.
I construct a CRange object and then call CRange's function get_shapeRange() to get a CShapeRange object.
but it triggers an exception. (but it's OK to call another function get_InlineShapes) I have no idea why it triggers an exception.
does anyone knows why? thanks.
By the way, I call this code in a keyboard hook function.
bool isRangeShape(__in CRange& oRange)
// I promise oRange is correct, because I can call
// like this oRange.get_InlineShapes()
// in word2010 it's ok,but in word2003 triggers an exception
// but corresponding VBA code works fun in word2003 (not fun, I'm sorry)// word2003 don't support this method, oh my god!!!
CShapeRange oShpRange = oRange.get_ShapeRange();
long lCount = oShpRange.get_Count();
if (lCount > 0)
I have one dialog box. I have picture control on that dialog. I'll draw two masks on the canvas using OnMouseMove functionality. one mask is completed, another one is incomplete mask (only a line drawn using pen). When I remove/delete the completed mask, incomplete doesn't get deleted but its not visible. How to show the line after removing the completed mask in MFC.
i am having n-number of points like p1(x,y), p2(x,y), p3(x,y), .... pn(x,y). All points lie on a single line.(either a curve or a straight line). i would like to find, using those points, whether that line is straight or not straight. i googled and tried some of the methods given in examples, (straight line equation, finding if collinear) but those are not working fine even for straight line also.
i am using visual studio 2008 with win32 (not MFC).
One way would be by using slope. Find the slope of the line corresponding to the first two points (y-coord of p2 - y-coord of p1) / (x-coord of p2 - x-coord of p1).
Find the slopes of the lines corresponding to all other points (with respect to the first point), say (y-coord of pk - y-coord of p1) / (x-coord of pk - x-coord of p1), where k varies from 3 to n.
All of these slopes should be within a reasonable tolerance band. And, since all of these lines pass through p1, they all would lie on the same straight line if they fell within the tolerance band.
The above would not work if the x-coordinates of p2 and p1 are the same (because denominator would be zero). In that case, you choose a point whose x-coordinate is unique as the reference point.
Not sure whether this is the most efficient way, but it certainly a way of achieving what you want.
You mean, that your slope value is 0.000002? This means that your line is almost horizontal. Your tolerance values would have to be at least 1/1000 or 1/10000 of your "average" slope value. Then, it would indicate that these points are on a straight line. (You need to use a "double" type to store these numbers, and a "float" may not suffice).
By the way, what is the purpose of this exercise? That purpose would in some sense determine the method of straight-line detection.
- Take the first and last points to build the 3D law of their straightness
- Define the fluctuation radius as "allowed error"
- All other points must lie in the "pipe" =>
=> any point projection onto the law(1) may not be greather as the radius(2)
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
One more way would be by using the cross product. Take two points, say p1 and p2 as reference. Consider the vector p1-p2. Now, take a point pk, and hence that vector p1-pk. Find the cross product of these two vectors (p1-p2 and p1-pk). That cross product should be near zero (all three components of the cross product) if the points are collinear. Repeat this for all points pk (k belonging to the set 3 to n).
With some algorithm you should pick 2 points that are far enough from each other. After this you can create a line object using these 2 points. The line object can be used to easily determine the distance of the other points from this line and you can accept distances less then a defined epsilon value.
An O(n) algorithm to determine the 2 endpoints (assuming that the points are in a line) before your create the line object:
Initialize an empty bounding AABB and then expand it by adding all points. Declare six point variables and each of them should store the last point that was used to expand the AABB in +x,-x,+y,-y,+z,-z directions (note: the first point should fill all the six variables).
When this is done choose a dimension in which the size of the AABB is the biggest (x, y, or z). If the biggest dimension is zero (or near zero) then all points are located at the same spot.
Lets say its x: in this case the two endpoints (from the previously mentioned 6 point variables) are the points that were stored when the AABB was expanded last time in -x and +x directions.
I am new to this forum but i hope i am at the right place. I am working on a project which has to be upgraded from the base project written in C++. We have decided to use emwin from segger as GUI which is written in C. The big heck is we have our base project middle ware still in C++.
Please suggest me whether its a wise idea to keep middleware in C++ and go ahead with GUI in C. The GUI library is written with Extern C so we will not have problem calling the library function. But how can we get the data from C++ middleware application.
But how can we get the data from C++ middleware application.
This question is not clear, what data, where is it held and where is it going? On a more basic point there is no problem using C-based libraries from C++ programs; after all the entire Windows API, including the GDI section, is written in C and used extensively from C++ programs.
One of these days I'm going to think of a really clever signature.
My question was any body can provide some sample code in C++ from where we can access GUI which is written in c. I have GUI button click call back function also written in c language itself. how can we pass that to a c++ application.?