Accessing objects and instances from string help

Posts 1–3 of 3 · Page 1 of 1
Accessing objects and instances from string help
Problem 1:
Say I have a winforms label object, how could I change it's text by accessing it from text.
To explain this, say I have multiple labels (label1, 2 and 3), i'm not sure which one i want to change the text of and it's up to the user to change it via command line like so:
>settext label1 test

Problem 2:
Is there anyway to get the instances of a class and alter, say, a variable of the instance?
Example: I have a class "game". An instance is created at runtime, but more are created dynamically by the user.
How could i change the sizeX int of each "game" instance programatically?
Code:
private void openNewClient_Click(object sender, EventArgs e)
        {
               Client.Game game = new Client.Game(this.sizeX, this.sizeY, this.Handle) //Constructor takes size for the game and IntPtr to set its parent as
        }

private void Main_SizeChanged()
{
        //here i'd like to change each instance of "Game"s size to this.sizeX and this.sizeY
}
If i need to better explain these issues, tell me
Perhaps you guys could help? @eth0nic @DatCoder
For starters what language do you use?
Most languages don't store the name of the methods, they reference them by using memory addresses, but you can use Dictionary use map each addresses to Strings but it's usually done with a simple switch. If you tell me more about it we could work something out. What do you want to make? There is usually a better way.

Problem 2: That's what class variables are for (static keyword):
Code:
class Game {
public:
 static int something;
};
int Game::something = 1;

int main() {
 Game one;
 Game two;
 Game three;

 std::cout << one.something << std::endl; //1

 Game::something = 5;
 std::cout << two.something << std::endl; //5

 two.something = 4;
 std::cout << three.something << std::endl; //4

 return 0;
}
The code above is C++, most languages have different syntax.
Quote Originally Posted by DatCoder View Post
For starters what language do you use?
Most languages don't store the name of the methods, they reference them by using memory addresses, but you can use Dictionary use map each addresses to Strings but it's usually done with a simple switch. If you tell me more about it we could work something out. What do you want to make? There is usually a better way.

Problem 2: That's what class variables are for (static keyword):
Code:
class Game {
 static int something;
}
int Game::something = 1;

main() {
 Game one;
 Game two;
 Game three;

 Game::something = 5;
}
The code above is C++, most languages have different syntax.
Code is c#
This is my project: A realm client/wrapper so to speak with many features

I'm using embedding flashplayerprojector using the WinAPI setparent, and sizing it/moving it with MoveWindow.
As you can see here, it has tabbing. Problem is when you resize the form, the flashplayers or games dont resize along with it to their containing tab size.

Right now i'm not handling each client as a class becuase I dont know how to access them to resize them all when the form is resized.
Opening a new tab calls this code, which is in a seperate class from the GUI class that contains all my WinAPI functions a few other things.
[one of the problems that I ran into was that flash projector's handle is destroyed and re-created as a new instance I believe when you open it with a file.
I could get away with just settingparent with just ex.Handle, but that no-longer works when you load a flash file into it, so I then have to getProcessByName to get its new handle]
Code:
public void Embed(IntPtr handle, string file, bool isNewTab) //handle is the handle of the new tab that was created by the user, file is the client location.
        {                                                                      
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.Arguments = file;
            psi.FileName = exeLocation + @"\flashplayer.exe";
            ex = Process.Start(psi);
            if (isNewTab == false)
            {
                mainHandle = ex.Handle;
            }
            Thread.Sleep(1600);
            IntPtr ehandle = FindWindowByCaption(IntPtr.Zero, "Adobe Flash Player 11");
            SetParent(ehandle, handle);
            handleArray.Add(ehandle); //The list mentioned below
            SetWindowLong(ehandle, GWL_STYLE, (WS_VISIBLE));
            Thread.Sleep(300);
            RECT rect;
            Rectangle myrect = new Rectangle();
            GetWindowRect(new HandleRef(this, ehandle), out rect);
            myrect.X = rect.Left;
            myrect.Y = rect.Top;
            myrect.Width = rect.Right - rect.Left;
            myrect.Height = rect.Bottom - rect.Top;
            MoveWindow(ehandle, 0, -20, myrect.Width, myrect.Height + 20, true);
        }
I have an array(<list>) of all handles that are created so then, when the form is resized:
Code:
public void Resize(int width, int height) //new size of containing tabs (they are all the same size)
        {
            foreach (IntPtr I in handleArray)
            {
                MoveWindow(I, 0, -20, width + 2, height + 20, true);
            }
        }
I'm using a custom tab control that is behaving weird or somthing when the main tab isn't the selected one, so when I resize the from while in a tab other than the main one, the games aren't resized, even the the fricken Resize() function is called..
My god this is a mess, perhaps you could add me on skype?
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us