Results 1 to 12 of 12

Thread: Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes.. etc

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes.. etc

    I have a project where I need to rename the windows class names of the forms/controls. I was told this either could not be done or was at least difficult in visual basic .net but was wondering what the truth of the matter was and also if it could be done in visual studio otherwise with c# and c++? Hoping there for an easy way to get this done.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes..

    Please always provide a FULL and CLEAR explanation of the problem. Are you talking about the class name that would be used, for instance, when calling the FindWindow and FindWindowEx API functions? If so, may I ask why you think you need to set those values?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes..

    Right yes exactly, when calling FindWindow/FindWindowEX, basically I want to do this because I hate calling class names like these "WindowsForms10.Window.8.app.0.143b42a_r15_ad1" I think it's crap, so I just want to be able to use my own class names to make my code more easily readable and understandable.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes..

    Quote Originally Posted by DreamWarrior77 View Post
    I just want to [...] make my code more easily readable and understandable.
    Then you should assign the class names to appropriately-named constants and use those in your API calls. That is how you make code readable, understandable AND maintainable. Once you're using a constant with a descriptive name, the actual value of that constant is completely irrelevant.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes..

    ohh I see what you mean, ok would this change the class name so that I can call it by something easier? Like turn this "WindowsForms10.Window.8.app.0.143b42a_r15_ad1" into "Chat Room Window" for example..? I mean would I be able to call it by "Chat Room Window" via FindWindow and FindWindowEX? That is what I am trying to do with this. I am sorry I am so rusty I have not programmed much since vb6 and I am still transitioning into .net.. and I have not been feeling well. Constants, ok I need to do some research..
    Last edited by DreamWarrior77; Jul 22nd, 2018 at 10:04 PM.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes..

    sorry this posted twice and I don't know how to delete the second post so I edited it..

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes..

    alright well I tried a google search but not much info came up for trying to change class name of form1 for example. I am trying silly stuff like this in form load:

    Code:
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Const (ActiveForm.Name = "Chat Room Window")
        End Sub
    End Class
    I have no idea.. but this is how I used to find out how to do things was to mess around and attempt to figure it out. Obviously I have no clue with this but if you could point me in the right direction though I would greatly appreciate it.
    Last edited by DreamWarrior77; Jul 22nd, 2018 at 10:23 PM.

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes..

    a Const is basically the same as a variable, but your code cannot alter the value of it.

    To declare one you use something like this:
    Code:
    Const ChatRoomClass as String = "WindowsForms10.Window.8.app.0.143b42a_r15_ad1"
    Then to use it, instead of this:
    Code:
    chatRoomHandle = FindWindow("WindowsForms10.Window.8.app.0.143b42a_r15_ad1", "")
    ...you can do this:
    Code:
    chatRoomHandle = FindWindow(ChatRoomClass, "")
    Much easier to read, and if you declare all of the class-name constants in one place it is also easier to maintain.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes..

    Quote Originally Posted by DreamWarrior77 View Post
    ohh I see what you mean
    It would appear not.
    Quote Originally Posted by DreamWarrior77 View Post
    ok would this change the class name so that I can call it by something easier?
    No it wouldn't. I'm saying that you should not bother trying to do that as it doesn't really serve a useful purpose. What I was suggesting was what si_the_geek has shown, i.e. assign the current, default class names to constants and then use those constants. Because the constant name would be self-describing, your code becomes easy to read and self-documenting.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes..

    ok sorry jmcilhinney I am mostly a visual learner if I can't see an example especially with programming I may not understand how it works. When reading about programming it can be difficult for me trying to theorize how things should work together I am not too great at understanding things unless I can either see how it works or someone walks me through it and helps me understand it. Some stuff I have no problem but a lot of it just does not seem to want to come together and make sense in my mind just yet. I am still very much a work in progress and a hobbyist when it comes to programming.

    Thanks si_the_geek, yes that seems to make much more sense, awesome.. I will need to experiment with this, where can I use this though? I mean can I use this in the load form event? Would that be ideal or would using this in a module make more sense?

    Ok, jmcilhinney you said
    you should not bother trying to do that as it doesn't really serve a useful purpose.
    I disagree and that is why I originally asked this question, although constants will work for my personal projects mostly one particular project I actually need to do it this way.
    I also would not mind doing it that way for my own personal projects unless there is some valid reason not to?
    Well the deal is this, I am trying to emulate an old chat software that I have software addons to, where.. these addons had chat games and ascii text. The goal is to fool the addon programs into thinking that the old chat software is loaded by using the emulated class names for the forms/controls so the addon programs can send these text lines to an emulated chat room and I can preserve the data of the addons.
    Last edited by DreamWarrior77; Jul 23rd, 2018 at 10:48 PM.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes..

    So you're saying that you have some other program that is already looking for specific class names? If so then you probably ought to have said that when I asked in my very first replay:
    If so, may I ask why you think you need to set those values?
    If you give us all the relevant information then it's easier to provide the best advice. If you actually NEED specific class names to make something work then that's different to just wanting a shorter class name because you think the defaults look bad. I asked that question for a reason and you answered:
    I just want to be able to use my own class names to make my code more easily readable and understandable.
    That's very different to what you seem to be saying now.
    I will need to experiment with this, where can I use this though? I mean can I use this in the load form event? Would that be ideal or would using this in a module make more sense?
    You use it wherever it's appropriate. Again, we can't read your mind. You need to think about what you need and implement the code appropriately. A constant can be declared locally in a method, privately in a class or publicly in a module. You do the one that you need. If you only need to refer to the constant in one method then declare it in that method. If you need it throughout a class then declare it in that class. If you need it throughout the project then declare it in a module. This is basic programming principles. It's not at all specific to what you're doing. You should ALWAYS declare EVERYTHING with scope as narrow as you can and as wide as you must.

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: Rename Window Class Of Forms, Listboxs, Textboxes, Buttons, Labels, Comboboxes..

    Quote Originally Posted by DreamWarrior77 View Post
    Thanks si_the_geek, yes that seems to make much more sense, awesome..
    si_the_geek just showed you how to do what jmcilhinney told you to do...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width