Technology & Programming Enthusiast blog

<
OMNITECHIE
 

Bitblt equivalent , Enum Class and Form designer juggling

May 18, 2008 12:51 by Rickron

BitBlt

Here's my problem ... I wanted a function similar to the bitblt  function like copyfromscreen but using bitmap and i didn't find anything. Does anyone know how to get through this. But since I am working in C++/CLI I ended up simply using bitblt function directly from user32.dll (without the usual interop mecanism). It worked nicely as usual, thanks to the possibility to "mix" managed and native code, very cool.

Generics 

 Ones will admit that C++/CLI is not easy to use. I just remember  a feature I didn't  use often ( I mean defining my own generic class and reuse them) ,  the "generics" ( the equivalent to C++ template). Mainly because I was in a GUI development work time and  I had some reserve on how generic could be useful to do generic control without losing for example the form designer support (this thing in C++/CLI seems to be so fragile..!!!! and I even wonder if using generic in the c# form designer is still possible). But may be in the next months....I will bring you some example.

Enum types

 Another not so obvious C++/cli language feature : "managed enum"

 Thanks to the MSDN documentation. Suppose you have a enum class with an AttributeFlags applied on it so that it behave like bitwise. Then one would admit that if I use native enum into  an if statement I should get a normal test performed.  Then such code

[FlagsAttribute]

enum class toto

{

a = 0,

b = 1,

c = 2,

d = 3

};

and the if statement. Since I have combined value I have to use  the & operator to get the condition working because the == operator is clearly not sufficient,

 

 

toto ttt = toto::a|toto::b|toto::d;

 

if(ttt & toto::b)

{

int i = 0;

}

I was getting this error :

1>.\enumtest.cpp(22) : error C2451: conditional expression of type 'toto' is illegal

1> This conversion requires an explicit cast (static_cast, C-style cast or function-style cast)

Yes it looks very annoying but this is just another example to which extent is going the correct type use in operator.

And moreover the MSDN provide me with this to fix. At first sight it looks very strange but after all it shows at which point the language is capricious when dealing with managed types...;))

if((ttt & toto::b) != toto())

{

int i = 0;

//--

}

Take note of the right hand side equality operator where we need an on-the-fly constructed enum object to properly have the equality get performed

Until now I think it is the most unsual construct in the language.

Rickron


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories:
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts