Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
R

roshihans

@roshihans
About
Posts
18
Topics
8
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How to create a .resx file in windows forms application (VS2005)
    R roshihans

    Hi, Each time I create a new windows forms application, the resource file that I get was app.rc. How to create and set a .resx as the resource file on my application? Thanks

    Managed C++/CLI winforms tutorial question learning

  • Serialization problem
    R roshihans

    I'm trying to binary serialize a 2D array using [Serializable] and ISerializable. In Special constructor for deserialization, I can't deserialize my array. I don't know what the type in info->GetValue("something", ??Type::typeid). This is my code :

    [Serializable]
    private ref class SerializedArrayClass : public ISerializable
    {
    public:
    array<array<float>^>^ jaggedArray;
    array<float, 2>^ genericArray;
    // Matrix is my other class
    Matrix^ matrixArray;

    int width;
    int height;
    int nElement;
    
    // Constructor
    SerializedArrayClass(int width, int height)
    {
    	this->width = width;
    	this->height = height;
    }
    
    // Init those 3 arrays
    InitArray()
    {
    	// ...
    }
    

    protected:
    // Special Constructor for deserialize
    SerializedArrayClass(SerializationInfo^ info, StreamingContext context)
    {
    this->width = safe_cast<int>(info->GetValue("width", int::typeid));
    this->height = safe_cast<int>(info->GetValue("height", int::typeid));

    	// this is where the problems begin
    	this->jaggedArray = safe\_cast<array<array<float>^>^>>(info->GetValue("jaggedArray", ??::typeid));
    	this->genericArray = safe\_cast<array<float, 2>^>>(info->GetValue("genericArray", ??::typeid));
    	this->matrixArray = safe\_cast<Matrix^>(info->GetValue("matrixArray", ??::typeid));
    }
    

    public:
    // For serialize
    virtual void GetObjectData(SerializationInfo^ info, StreamingContext context)
    {
    info->AddValue("width", this->width);
    info->AddValue("height", this->height);
    info->AddValue("jaggedArray", this->jaggedArray);
    info->AddValue("genericArray", this->genericArray);
    info->AddValue("matrixArray", this->matrixArray);
    }
    }

    What is the correct Type for 2D array and Matrix object? Thanks,

    Managed C++/CLI question data-structures json help

  • Generics problem
    R roshihans

    Thanks for your reply, Actually I want to make a 2D matrix class that doesn't just limited in one type (ValueType) only so that I can create a Matrix<float> or Matrix<int> depending on what I need. I thought that generic is the most appropriate and also the simplest solution but it turns out that I was wrong.

    Managed C++/CLI help question learning

  • Generics problem
    R roshihans

    Anybody? :(

    Managed C++/CLI help question learning

  • Generics problem
    R roshihans

    I'm still learning about generics so I create a generics function like this :

    generic<class T> where T : ValueType
    T Process(T val)
    {
    val = val * 15;
    return val;
    }

    and called float a = Process<float>(10.0), but then I got " error C2296: '*' : illegal, left operand has type 'T' " in the line val = val * 15;. Then I try a simpler method like this :

    generic<class T> where T : ValueType
    T Process()
    {
    T val = 15;
    return val;
    }

    Called float a = Process<float>() and I still got "error C2440: 'initializing' : cannot convert from 'int' to 'T' " in the line T val = 15; What is the correct way to use generics? Thanks in advance

    Managed C++/CLI help question learning

  • Fade TabPage between TabControl's tab selection
    R roshihans

    After searching on the internet, the possible solution that come out is by using TabPage.DrawToBitmap, put the bitmap in a PictureBox, set the position of PictureBox to the same location of TabPage, and fade it. The code is below :

    System::Void tabControl1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
    {
    alphaBlend = 250;
    repaint = true;

    // set TabPicture visibility, location, and size
    TabPictureBox->Visible = true;
    int posX = tabControl1->Location.X + tabControl1->TabPages\[tabControl1->SelectedIndex\]->Margin.Left + 1;
    int posY = tabControl1->Location.Y + tabControl1->ItemSize.Height + 1 + 
    	tabControl1->TabPages\[tabControl1->SelectedIndex\]->Margin.Top;
    TabPictureBox->Location = System::Drawing::Point(posX, posY);
    TabPictureBox->Size = tabControl1->TabPages\[tabControl1->SelectedIndex\]->Size;
    
    // set Bitmap
    TabBitmap = gcnew Bitmap(tabControl1->TabPages\[tabControl1->SelectedIndex\]->Width, 
    	tabControl1->TabPages\[tabControl1->SelectedIndex\]->Height);			
    tabControl1->TabPages\[tabControl1->SelectedIndex\]->DrawToBitmap(TabBitmap,
    		Rectangle(0, 0, tabControl1->TabPages\[tabControl1->SelectedIndex\]->Width, 
    			tabControl1->TabPages\[tabControl1->SelectedIndex\]->Height));
    
    while (alphaBlend > 0)
    {				
    	alphaBlend = alphaBlend - 25;
    	TabPictureBox->Refresh();
    }
    
    TabPictureBox->Visible = false;
    repaint = false;
    

    }

    System::Void TabPictureBox_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
    {
    if (repaint)
    {
    if (TabBitmap != nullptr)
    {
    Bitmap^ temp = gcnew Bitmap(TabBitmap);
    Graphics^ bitmapGraphics = Graphics::FromImage(temp);
    if (alphaBlend < 0) alphaBlend = 0;
    SolidBrush^ greyBrush = gcnew SolidBrush(Color::FromArgb(alphaBlend, Color::White));
    bitmapGraphics->CompositingMode = CompositingMode::SourceOver;
    bitmapGraphics->FillRectangle(greyBrush, Rectangle(0, 0, TabBitmap->Width, TabBitmap->Height));
    e->Graphics->CompositingQuality = CompositingQuality::GammaCorrected;
    e->Graphics->DrawImage(temp, 0, 0);
    }
    }
    }

    The problem is that each time I select the tabPage, my CPU usage spike to 70 - 80% and the fading effect is kind of slow. Is there any solution to fix it so that I can draw the bitmap faster and with minimum CPU usage (less than 50%)? Thanks.

    Managed C++/CLI graphics help css algorithms question

  • FormBorderStyle problem
    R roshihans

    What is the equivalent window style for FormBorderStyle.Fixed3D, FormBorderStyle.FixedSingle, FormBorderStyle.FixedDialog, FormBorderStyle.SizableToolWindow and FormBorderStyle.FixedToolWindow? The only one I know is WS_THICKFRAME for FormBorderStyle.Sizable.

    C# question help

  • Form With Shadow
    R roshihans

    Saksida Bojan wrote:

    this.SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.DoubleBuffer, true);

    It seems that SetStyle only applied in client area. I can't make the non-client area transparent. Any suggestion?

    C# question help tutorial

  • Form With Shadow
    R roshihans

    Thanks a lot for your help. I will try your suggestion

    C# question help tutorial

  • Form With Shadow
    R roshihans

    Saksida Bojan wrote:

    for painting try look into OnPaint event or you can even ovverride

    I thought if I paint form's border with a transparent-shadow background (using png file), it will not become transparent unless I set the main form transparent too. And how to paint the shadow into the border which is located in non-client area?

    C# question help tutorial

  • Form With Shadow
    R roshihans

    When you say override CreateParams, did you refer to the main form's CreateParams? But then, where do I draw the png image files into?. Sorry, but I'm new in this so I'm still confused.

    C# question help tutorial

  • Form With Shadow
    R roshihans

    Thanks for the reply, I'm using Windows XP, so I think there are no WS_ for AERO.

    C# question help tutorial

  • Form With Shadow
    R roshihans

    I have a form and a png image file (with a transparent shadow in its border) and what I want is to make a drop shadow effect on the form. I know there are CS_DROPSHADOW solution for this, but I think it doesn't look too good. So I create a "fake" form using CreateWindowEx (via DllImport), and draw the png image file into the fake form.

    void CreateFakeForm()
    {
    WNDCLASSEX wndClsEx = new WNDCLASSEX();
    wndClsEx.Init();
    wndClsEx.style = CS_VREDRAW | CS_HREDRAW;
    wndClsEx.lpfnWndProc = m_DefWndProcDelegate;
    wndClsEx.cbClsExtra = 0;
    wndClsEx.cbWndExtra = 0;
    wndClsEx.hInstance = GetModuleHandle(null);
    wndClsEx.hIcon = IntPtr.Zero;
    wndClsEx.hIconSm = IntPtr.Zero;
    wndClsEx.hCursor = IntPtr.Zero;
    wndClsEx.hbrBackground = IntPtr.Zero;
    wndClsEx.lpszClassName = m_WndClsName;
    wndClsEx.lpszMenuName = null;

            bool success = RegisterClassEx(ref wndClsEx) != 0;
    
            UInt32 dwExStyle = WS\_EX\_LAYERED |
                WS\_EX\_TRANSPARENT |
                WS\_EX\_NOACTIVATE |
                WS\_EX\_LEFT;
            UInt32 dwStyle = WS\_VISIBLE | WS\_OVERLAPPED;
            
            FakeWndHandle = CreateWindowEx(dwExStyle
                , m\_WndClsName
                , null
                , dwStyle
                , X
                , Y
                , PngImg.Width
                , PngImg.Height
                , MainFormHandle
                , IntPtr.Zero
                , GetModuleHandle(null)
                , IntPtr.Zero
                );
    

    }

    The problem is my fake form always in the topmost position. Is there a way to put the fake form behind the main form? In other words, how do I set z-order between the main form and the fake form so that the fake form placed at the bottom of the Z order? How to hide the fake form whenever the main form minimized or maximized, and move or resize the fake form whenever the main form moved or resized? Thanks.

    C# question help tutorial

  • Problem to communicate between forms [modified]
    R roshihans

    Thanks a lot Navaneeth, you have help me solve those two problems!! Pheww.. I kinda confused at first because of this circular dependency problems, but it's has clear now.

    Managed C++/CLI help csharp c++ question

  • Problem to communicate between forms [modified]
    R roshihans

    N a v a n e e t h wrote:

    By constructor injection, I meant to pass the first form's object to second form via constructor. Something like

    Form2(Form1^ form1) // First form's object is injected through constructor
    {
    // keep the form1 object for future use
    }

    But Form1 already include Form2.h (in my case Form1 act as a "parent" form, and instantiate Form2). So I think I can't declare Form2 (Form1^ form1) and keep the form1 object, like you have mentioned above, because I need to include Form1.h inside Form2.h, and that will give me this "fatal error C1014: too many include files : depth = 1024". Or maybe I don't need to include Form1.h inside Form2.h? Thanks

    Managed C++/CLI help csharp c++ question

  • Problem to communicate between forms [modified]
    R roshihans

    Thanks for your quick reply, Navaneeth!! And now, the delegate thing is works perfectly!! I has been searching a lot about this in the internet without a result and now it's solved! Thanks a lot Navaneeth!! :thumbsup: I dunno if my question is beyond the topic, but can I ask about another thing? this is about the answers that Navaneeth wrote

    N a v a n e e t h wrote:

    Because you are instantiating a new instance in the child form. You need to pass the main form's instance to child form (through constructor injection or some setter methods).

    constructor injection? I'm still a beginner in C++, so I'm barely hear about this. When you say constructor injection, is it something like dependency injection? I'm googling it in the internet, and this is that came up. Correct me if I was wrong, but from what I read in Internet, this dependency injection can be done using a container (??), created by third party developer (they mentioned something about pico container and others). It can not be done by .NET itself? I'm still confused :confused:

    Managed C++/CLI help csharp c++ question

  • Problem to communicate between forms [modified]
    R roshihans

    Hi, I have a problem to pass some data between forms. Let's say I have 2 form, FormMain and FormChild, FormChild will be called from FormMain. What I want to do is simple. Whenever I change the textBox1's text in FormChild, the textBox1's text in FormMain will also contain the same text. After googling for a while, I got 2 solution : by using a delegate or directly instantiate FormMain in FormChild. Both solution unfortunately is in C#, so I need to convert it first. Well, I thought at first that there will be no problem at all to convert it, but that is just plain wrong. Both of the solution I get is just give me some error. Here is the converted source code 1.using delegate in Form Main.h :

    #include "Form Child.h"

    namespace Delegates {

    public delegate void AddTextChangeDelegate(String^ item);
    
    public ref class FormMain : System::Windows::Forms::Form
    {
    public:
    	FormMain()
    	{
    		formChild = gcnew FormChild();
    	}
    
    // declare as global variable	
    private:
    	FormChild^ formChild;
    
    private: 
    	System::Void button1\_Click(System::Object^  sender, System::EventArgs^  e)
    	{			
    		formChild->AddTextChangeCallback = gcnew AddTextChangeDelegate(&this->AddTextChangeCallbackFn);
    		formChild->Show();
    	}
    
    private:
    	System::Void AddTextChangeCallbackFn(String^ str)
    	{
    		textBox1->Text = str;
    	}
    };
    

    }

    in Form Child.h

    namespace Delegates {

    public ref class FormChild : System::Windows::Forms::Form
    {
    // declaring delegate, and get "error C2143: syntax error : missing ';' before '^' "
    // the compiler seems doesn't recognize this
    public:
    	AddTextChangeDelegate^ AddTextChangeCallback;
    
    // user click add button and the delegate executed
    private:
    	System::Void btnAdd\_Click(System::Object^ sender, System::EventArgs^ e)
    	{
    		AddTextChangeCallback(textBox1->Text );
    	}
    
    };
    

    }

    2. directly instantiate FormMain the solution I get (in C#) is just simply declare FormMain as a global variable in FormChild, then exposed the textBox in FormMain as a public. But when I do the same thing in C++, the compiler give an error "error C2143: syntax error : missing ';' before '^' ". so probably I just need to include the Form Main.h in Form Child.h, which give me another error "fatal error C1014: too many include files : depth = 1024" (is it because both form include each other's header?, so that is like making some cyclic dependency thing? I'm not sure why). After googling once more, I found that it is st

    Managed C++/CLI help csharp c++ question

  • MPEG Video file
    R roshihans

    Does anyone know how to read frame types from mpeg file? I want to know if this frame is frame I, P or B Some source code would be appreciated Thanks

    Graphics tutorial question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups