|
hello guys.... im new to this. Im using VS 2008 to create Windows Forms Project, and wanna show message box in it. But it is not working here is the code
MessageBox(NULL,"message box","title here",NULL);
im using vc++.
|
|
|
|
|
This works fine in my test program, perhaps you could add some more context. Alternatively run your program through the debugger with a breakpoint at the MessageBox() call.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
There's nothing wrong with the one line you showed. I'd suspect your code is not being reached, rather than being wrong if it ever was reached.
As Richard said: Breakpoint time!
Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!
|
|
|
|
|
Start ya good old debugger
|
|
|
|
|
What exactly do you mean by not working?
You're probably running a UNICODE build and are getting compile errors.
Try this - MessageBox(NULL, L"message box", L"title here", NULL);
|
|
|
|
|
Hello,
I am working with a large code base that is written entirely in C++, MFC as well as other API's, and which also link against various other projects (ie static libs written in C++). I am looking to replace some of the UI with WPF, and need advice on the most efficient way of going about this. If I host WPF content (created in C#\.NET) in a Win32 window so that I can reuse the C++ code, I encounter many loader lock issues, many of which I have been able to overcome, but am now running into cases that are difficult to debug and which may become time consuming. On the other hand I could also create a C++ DLL and load this in my WPF application, however creating a C++\CLI interface for the existing code also appears to be challenging and time consuming. I don't know what would be involved in creating a COM interface, and if this is has any advantages over the other approaches. I have spent a great deal of time trying various options but still without a clear choice. Is there a recommended approach or a resource where I can learn about the pros and cons of these approaches, including relative time investiment that is involved?
|
|
|
|
|
Huch, this is a huge topic and could take hours if not days to discuss... I try to comment some of the points you've made.
If I host WPF content (created in C#\.NET) in a Win32 window so that I can reuse the C++ code, I encounter many loader lock issues.
First, decide which way around you are going to interoperate. You have tried to embedd WPF content in Win32 windows. Then you (or the WPF itself) probably tried to embedd other (or probably the same) native Win32 content in the same WPF control which can lead to loader locks, since a safe recursive binding of this kind is hard to ensure. I recommend fixing the direction of interoperability once and for all times: The best choice is to let a WPF application be the master - then you can safely embedd Win32 native content including Direct3D, WinForms or whatever. Usage of Win32 or WinForms content in the WPF is well documented and supported on MSDN and in other WPF related sources since this is the intended way to do it.
On the other hand I could also create a C++ DLL and load this in my WPF application, however creating a C++\CLI interface for the existing code also appears to be challenging and time consuming.
But this is the only clean way to do it. It is also the intended way to do it, therefore it is quite well documented and has been subject to many articles and whole chapters of various WPF related books. I recommend reading on that a bit, it is not hard and can be automated to some extent.
Cheers,
Paul
|
|
|
|
|
Thank-you kindly for your response, Paul. I guess I was confused from the msdn website, as it was not clear what the actual intended way was. I am continuing to try and get the C++/CLI interface to work, I have run into another hiccup though and have placed a new post here in case anyone has insight on this: http://www.codeproject.com/Questions/118940/Exception-raised-in-WPF-app-when-referencing-Cplus.aspx
Do you have any comments on the use of COM? Why would people use this approach as opposed to creating a C++/CLI interface?
|
|
|
|
|
Well, there is a huge amount of ActiveX (COM-based) controls around. This is the reason why people would go the COM-way. However, this is easier as it might seem on the first sight: There is a quite transparent way to import COM-based controls using the Windows Forms infrastructure. After some not-so-nice hick-hack preparation work, the procedure itself is not much different from embedding a Windows Form control... All WPF-related books I have around, contain a quite representative (and functional) samples how to do all that.
|
|
|
|
|
Very good reply - this is the sort of thing I'll soon be faced with too. Nicely laid out logic!
Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!
|
|
|
|
|
I am having a bad day!
I have created a CWnd derrived class which starts and uses a Windows timer. I have then derrived a class from this and created 3 instances. The idea being that each instance would get its own WM_TIMER message. What appears to be happening is that the first instance to be created is getting all of the WM_TIMER messages.
Am I right in saying that this should not happen? Any thoughts suggestions?
Tony
|
|
|
|
|
It's really difficult to help you without seeing any code. Are you using the same timer Id for all the timer messages ?
|
|
|
|
|
Hi Cedric.
Thanks for your reply. I have found the problem. I had a static variable in the OnTimer() to count the ticks. Of course being static, it is updated by all instances of the class. I have changed this to a class member and all is well.
I am so embarrassed!
|
|
|
|
|
The world is fine.
|
|
|
|
|
Hello everyone,
I am unable to figure how to code the following in C++. It is quite simple when the dimensions of the input array is preset. However, I am at a loss on how to do this when that is not the case.
So, just to explain I have an array which represent values in a multidimensional histogram. For the sake of argument, let us assume that the histogram is 3 dimensional and the x-dimension is of size 10, y dimension is of size 20 and z-dimension is of size 30.
Now, what I want to do is traverse through the histogram along each of the axes. So I want to go through the whole histogram along the rows, columns and the normal axes. If I hard-code the dimensions of the histogram it is quite easy to do so:
void traverse_histogram(float *histogram)
{
int index;
for (int z = 0; z < 30; ++z)
{
for (int y = 0; y < 20; ++y)
{
for (int x = 0; x < 10; ++x)
{
index = z * 20 * 10 + y * 10 + x;
}
}
}
for (int z = 0; z < 30; ++z)
{
for (int x = 0; x < 10; ++x)
{
for (int y = 0; y < 20; ++y)
{
index = z * 20 * 10 + y * 10 + x;
}
}
}
for (int y = 0; y < 20; ++y)
{
for (int x = 0; x < 10; ++x)
{
for (int z = 0; z < 30; ++z)
{
index = z * 20 * 10 + y * 10 + x;
}
}
}
}
Now, what I have is a situation where the dimensions are not hard-coded (they also can be more than 3) and what I need to do is generalize this somehow, so that it works when the number of dimensions and the dimension size are also dynamic. However, I am really struggling to figure out how this might work.
So, the new function signature is as follows:
void traverse_histogram(float *histogram, int num_dims, int *dimensions)
{}
I would be really grateful if someone can help me figure out a good way to do this. I am really stumped.
Thanks,
Keith
|
|
|
|
|
Firstly recognise that the generic index is calculated as follows:
index = X0 + X1*D0 + X2*D1*D0 + ... + Xn*Dn-1*Dn-2*...*D0
Where Xi is the index in axis i and Di is the size of dimension i
To make this word we need an array of the same size as the dimension array to hold each of the indices along the axes. Given this, the following code will calulate the index:
int calculate_product(int dim, int *dimensions)
{
int product = 1;
for(int i = 0; i < dim; ++i)
product *= dimensions[i];
return product;
}
int calculate_index(int num_dims, int *dimensions, int *indices)
{
int index = 0;
for(int i = 0; i < num_dims; ++i)
index += indices[i]*calculate_product(i, dimensions);
return index;
}
If we want to traverse along axis i, the outer loop should iterate over axis i - 1, the next loop iterates over axis i - 2, ..., then iterate over axis 0, then iterate over axis num_dims - 1, ..., then axis i + 1, and finally over axis i. First we need a function to get the previous axis number:
int previous(int current, int num_dims)
{
if(current > 0)
return current - 1;
return num_dims - 1;
}
Now to traverse the array, starting from a given axis, it is easiest to use recursion.
void traverse(int axis, int current, float *histogram, int num_dims, int *dimensions, int *indices)
{
for(indices[current] = 0; indices[current] < dimensions[current]; ++indices[current])
{
if(axis == current)
{
int index = calculate_index(num_dims, dimensions, indices);
}
else
{
traverse(axis, previous(current, num_dims), histogram, num_dims, dimensions, indices);
}
}
}
void traverse_axis(int axis, float *histogram, int num_dims, int *dimensions)
{
int *indices = new int[num_dims];
for(int dim = 0; dim < num_dims; ++dim)
indices[0] = 0;
traverse(axis, previous(axis, num_dims), histogram, num_dims, dimensions, indices);
delete [] indices;
}
void traverse_histogram(float *histogram, int num_dims, int *dimensions)
{
traverse_axis(num_dims - 1, histogram, num_dims, dimensions);
traverse_axis(num_dims - 1, histogram, num_dims, dimensions);
traverse_axis(1, histogram, num_dims, dimensions);
traverse_axis(0, histogram, num_dims, dimensions);
}
Graham
Librarians rule, Ook!
|
|
|
|
|
Thanks for such a detailed reply! I will give this a go.
Keith
|
|
|
|
|
Hello,
Just a quick clarification: In your traverse_axis code, you have:
for(int dim = 0; dim < num_dims; ++dim)
indices[0] = 0;
I am guessing you meant indices[dim] = 0 or something else as this seems to be not right.
Many thanks,
Keith
|
|
|
|
|
Keith Vitali wrote: I am guessing you meant indices[dim] = 0
Oops - yes, you are correct
Graham
Librarians rule, Ook!
|
|
|
|
|
Thanks for that.
The code seems to work fine. I would have never figured this out on my own!
/K
|
|
|
|
|
If you're using C++ leave all your C baggage behind. While the solution outlined would be great for C why not wrap all the messing about with dimensions to a class? You can bung the dimensions in the class along with your data and not have to fiddle about with pointers so much and all the errors that that produces (for example not having enough data for the number of dimensions).
Cheers,
Ash
|
|
|
|
|
hello guys...how can I learn that whether a particular feature is good to implememnt or not? Lets suppose that I use templates in my C++ prog, now how can I know that this is good to implement it or not??
|
|
|
|
|
Only experience will help you. Good news that it need not be your experience, it could just as well be someone else's. Read a book on design patterns or design practices. Design Patterns: Elements of Reusable Object-Oriented Software[^] is one place to start. I would say googling would be a good option, but admittedly might be hard if you don't know what key words to search for. If you're in doubt, you could drop a specific or general design question on a forum close to you.
The best shortcut to experience is to get a mentor.
|
|
|
|
|
thanks....the book looks to be good one.
|
|
|
|
|
overloaded Name wrote: Lets suppose that I use templates in my C++ prog, now how can I know that this is good to implement it or not??
Do they benefit, or add to the functionality of, the project? Can you complete the project without them?
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|