I have a dialog box. I have 10 buttons on that dialog box. I am using CSkinButton class to use images for those buttons. I want to provide scrollbar to the dialog box dynamically. For example, if I use 6 buttons, will fit the size of the dialog box. If I want to use 10 buttons, then vertical and horizontal scroll bar should appear on the dialog box automatically. As I using Images (Bitmaps) for buttons, scroll bar doesn't appear automatically.
I have tried to set the property of the dialog box for scroll bar. It doesn't work.
Anybody have anny idea regarding this.?
Please let me know if you have any doubt in understanding the above questions.
I want to create an MFC MDI Application, which is used to draw engineering 2D drawing. A similar one to Auto CAD 2D software.
Can anyone of you suggest us the best open source library which we can use to implement 2D mfc drawings.
I know some of libraries like OpenGL, DirectX but i am not sure a) whether we can use these libraries to create 2D drawings. b) whether we need to purchase these libraries as we are developing a commercial application. c) there may be better libraries available for 2D drawing and it may be for free.
We have in many places in our code things like :
if ( string.compare(A) == 0 )
// do something for A
elseif ( string.compare(B) == 0 )
// do something for B
elseif (string.compare(C) == 0 )
// do something for C
I know that we cannot use switch cases for strings, but is there a better way to do cascading If comparisons on strings ?
Two optimization tricks:
1. You store the possible values (A, B, and C, ...) in a sorted array and you search your string in that array with binary halving. Alternatively you can store A,B,C in one of these: map/hashmap/search tree.
2. If you opt for using == and/or != with if/else then you can speed up these operations for strings by storing the hash value for each string. When you compare two strings you first compare the hash values. If the hash is different then you have your result immediately (false for == and true for !=). If the hash for the strings is different then you have to perform the actual comparison on the strings. I usually write a special string class that contains the hash as well. It has the drawback that the hash must be updated before comparisons if the string has been modified since the last hash calculations. Sometimes purely written old legacy code can be tweaked very well with this trick. Use djb2 to hash your strings, for unicode use utf8: http://www.cse.yorku.ca/~oz/hash.html[^]
EDIT: Just noticed my answer isn't exactly the what you are searching for, but I think there is no fine solution to your problem. This problem is similar to the typical factory patterns that are used to instantiate a specific type by name:
You can choose to store strings in buffers of length 4*n. That way you can compare two DWORD vectors. It will be case sensitive, but faster than strcmp. You can also use switch on the first DWORD, but !!!ONLY!!! if no two strings share the same 4 bytes at the begining.
t is there a better way to do cascading If comparisons on strings
Where "better" means what?
If you just don't like looking at the code then you could do code generation.
If there is a actual profiled performance problem traced to this then you can used collected data to order the comparisons with most used first and least used last. Depending on the number of strings, and the data in the strings other optimizations are possible.
One solution again dependent on data and usage is to parse the input, when first received, into a value such as an enumeration and only use that in the rest of the code.
If there is a lot of churn with these then generation can still help but dynamic collections might solve that, with care. However such solutions might not be as performant and add some level of complexity.
Last Visit: 31-Dec-99 19:00 Last Update: 25-May-15 23:13