Page 1 of 2 12 LastLast
Results 1 to 40 of 41

Thread: Easy c++ to vB code

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18

    Easy c++ to vB code

    Hey what's up all. I started with vB about 2 weeks ago, it's so much fun. I'm learnin quick. I have come here and other places for so much help already, never posted though, I thank all you gurus...heh. But, it seems I have a dillema. I have this short c++ code that I need ported to vB, if thats even possible. All it does is send commands to a game console with the command Console("COMMANDHERE"). I would greatly appreciate help on this. I don't know what I can give in return for your experties, I'm not skilled enough in vB yet to make anything for ya guys. We can talk if I get replies. Heh.. See ya guys later.

    P.S. This is the C++ code to send commands to a game console.
    ****************************************************
    inline void Console(char *cgCmd)
    {
    HWND MohCons = FindWindow(0, "Mohaa Console");
    EnumChildWindows(MohCons, EnumChildSendCommandProc,(LPARAM)cgCmd);
    }


    BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam)
    {
    char className[1024];

    GetClassName(hwnd,className,sizeof(className));

    if (strcmp("Edit",className)) return true;
    if (ES_READONLY & GetWindowLong(hwnd,GWL_STYLE)) return true;

    SendMessage(hwnd,WM_SETTEXT,0,lParam);

    SendMessage(hwnd,WM_CHAR,13,0);
    return 1;

    }

    ****************************************************

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Here it is
    VB Code:
    1. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    2.  
    3. Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    4.  
    5. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    6. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    7. Private Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    8.  
    9. Private Sub Console(String cgCmd)
    10.      Dim MohCons As Long
    11.      MohCons =  FindWindow(0,"Mohaa Console")
    12.      EnumChildWindows MohCons,AddressOf EnumChildSendCommandProc,strPtr(cgCmd)  
    13. End Sub
    14.  
    15.  
    16. Public Function EnumChildSendCommandProc(hwnd As Long,lParam As Long)
    17. Dim ClassName As String*1024
    18. GetClassName hwnd,className,len(className)
    19. if className="Edit" Then EnumChildSendCommandProc=True
    20. if ES_READONLY And GetWindowLong(hwnd,GWL_STYLE) Then EnumChildSendCommandProc=True
    21. SendMessage hwnd,WM_SETTEXT,0,lParam
    22. SendMessage hwnd,WM_CHAR,13,0
    23. EnumChildSendCommandProc=True

    I haven't specify the values for the constants used in the above code... can u do it yourself???? like
    Const ES_READONLY = 2 'This is not actual value

  3. #3
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    I think this should do it:

    Code:
    'in a Form:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Sub Console ()
      Dim MohCons As Long
    
      Me.AutoRedraw = True
      MohCons = FindWindow(vbNullString, "Mohaa Console")
      EnumChildWindows MohCons, AddressOf EnumChildSendCommandProc, ByVal 0&
    End Sub
    
    'in a Module:
    Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    
    Function EnumChildSendCommandProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
        Dim lpClassName As String
        Dim L As Long
    
        lpClassName = Space$(1024)
        L = GetClassName (hwnd, lpClassName, 1024)
        If (Left$(lpClassName, L) = "Edit") Then Exit Sub
        If (GetWindowLong(hwnd, GWL_STYLE) And ES_READONLY) Then Exit Sub
        Form1.Print Hex$(LParam)
        'continue enumeration:
        EnumChildProc = 1
    End Function
    * I AM *

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Wow. I can't believe you guys actually wrote those huge snippets for me. You don't know how much I appreciate this. Thank you. But ok. I have a couple questions. I dont have any idea what to do in converting things from c++, so i dont know where to put the constant values and that. Once this is figured out, I will learn off of what you guys did. And it might be my last time buggin ya guys. For the second one, I tried a button:

    Private Sub Command1_Click()
    Console ("set name x39rox")
    End Sub

    And i get this error:

    Wrong number of arguments or invalid property assignment.

    And it points to the console part. So i assume thats not the correct command for it. Can u write a simple button for that? If this is possible, and gets complete, i'll be like a boy at a candy shop. Hah. Tty guys later. Thank you again compie and kahn.

  5. #5
    Lively Member
    Join Date
    Jan 2002
    Posts
    108

    hmm

    considering it's a sub procedure and not a function
    you should try....


    VB Code:
    1. Private Sub Command1_Click()
    2.      Console "set name x39rox"
    3. End Sub

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    I get the same error. Man, I'm trying everything I can come up with, which isn't alot, but I'm tryin.

    Edit: I just thought of something. Shouldnt it look for the main window name first (Medal of Honor Allied Assault), then look for the other window (MOHAA Console)?

    Edit2: Ok guys, well I'm going to bed now (i was up all night trying to do this). Its 11:58am now here. Sheesh. Heh, I will probably dream of this too, lol. So, I am hoping to god that someone figures a way to do this, or make this. Good Luck guys. Thanks a ton again.

    O yeah, this gives me an error in the first one:


    Private Sub Console(String cgCmd)


    The 'string' cant be there i think. ?
    Last edited by x39rox; Jul 21st, 2003 at 12:02 PM.

  7. #7
    Lively Member
    Join Date
    Jan 2002
    Posts
    108

    You could try...

    changing the prototype of the sub procedure to

    VB Code:
    1. Private Sub Console(String cgCmd) ' from this to
    2. Private Sub Console(Dim cgCmd as String)

  8. #8
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    VB Code:
    1. Private Sub Command1_Click()
    2. Console "set name x39rox"
    3. End Sub

    This is giving you an error while trying to use the second method is because the second method does not take a parameter. As you can see the delcaration of the function is just simply
    Console() with no arguments. The reason you are having an error trying to use the first one is this.

    VB Code:
    1. 'Data type needs to be after the variable
    2. Private Sub Console(String cgCmd)
    3.  
    4. 'such as this
    5. Private Sub Console(cgCmd as String)

    When you do that it passes by reference as default, if you want to pass the variable by value you will need this

    VB Code:
    1. Private Sub Console(ByVal cgCmd as String)
    Last edited by Maldrid; Jul 21st, 2003 at 03:15 PM.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Hm, that seemed to work. I get these zero's that come up on my form now when the game is not active. When the game is active, I get nothing that prints on the form, but it doesnt do the command. So we got half of it working I guess, lol. Anyone see a problem with it? I'm still thinkin it should look for the game window (Medal of Honor Allied Assaut) first and then look for a window inside the game (MOHAA Console) then send whatever command i specify to the game. Doesn't that seem logical? Well, you guys are the experts here, I'm just throwin out ideas. I'll check back today to see if ya guys have an answer. Thanks a whole lot again. It's so nice of yall.

  10. #10
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    O yeah, this gives me an error in the first one:


    Private Sub Console(String cgCmd)


    The 'string' cant be there i think. ?

    Oooopss!!! sorry...my mistake.. this String shouldn't be here...I just mistyped...
    It should be like this...
    VB Code:
    1. Private Sub Console (cgCmd As String)
    2. ......
    3. .
    4. .
    5. .
    6. .
    7. End Sub
    So sorry... i created a hassle for ya...

  11. #11
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Have u figured out the Const thingy???

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    No, I haven't. I have no idea what your even talking about, heh. Are you saying it shouldn't work until I put some values somewhere? I wan't this thing to work so bad man. Can you explain?

  13. #13
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    These are the constants you will need to declare in a module

    VB Code:
    1. Public Const GWL_STYLE& = (-16)
    2. Public Const WM_CHAR = &H102
    3. Public Const WM_SETTEXT = &HC
    4. Public Const ES_READONLY = &H800

  14. #14
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Originally posted by x39rox
    No, I haven't. I have no idea what your even talking about, heh. Are you saying it shouldn't work until I put some values somewhere? I wan't this thing to work so bad man. Can you explain?
    Sorry!!! just got so lazy.. Thanx Maldrid...
    VB has not got these constants defined bydefault like how C++ does.. therefore you have to define them by yourselves.....

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Ok, I put that in there now. But, the darn thing still won't work. I must be causing you guys to scream at your computer...heh. I am sorry, I'm learning everytime you guys post though, so keep postin, lol. I just double checked with the person that made the c++ code and he said he's 150% sure the c++ code is right because he uses it all the time. So, either this is not possible, or something is wrong. <-- good inference...lol.

  16. #16
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    What method are you using? The first or second? I think you should be using the first method that manikhan posted because he allows you to pass a string. Also what exactly isn't working? Do you get an error? Or no error just doesn't do anything? Do you step through the code and make sure you are getting the right handle to the window? I am not sure but I think you can use Spy++ to find out what handle the window has to make sure it is getting the correct one.

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Ok. Heres the scoop so far. I used spy++ like 5 mins before you posted that, weird eh? Anyway, it says caption name is "MOHAA Console". So that's correct. I was using compies before and it just wasnt doing anything, no errors either. Now I tried kahns, and I get an error here where i highlighted the red:

    Dim ClassName As String * 1024
    GetClassName hwnd, ClassName, Len(ClassName)
    If ClassName = "Edit" Then EnumChildSendCommandProc = True
    If ES_READONLY And GetWindowLong(hwnd, GWL_STYLE) Then EnumChildSendCommandProc = True
    SendMessage hwnd, WM_SETTEXT, 0, lParam
    SendMessage hwnd, WM_CHAR, 13, 0
    EnumChildSendCommandProc = True


    I put that^ in a module. I put this in a form:

    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

    Private Sub Console(ByVal cgCmd As String)
    Dim MohCons As Long
    MohCons = FindWindow(0, "Mohaa Console")
    EnumChildWindows MohCons, AddressOf EnumChildSendCommandProc, StrPtr(cgCmd)
    End Sub

    Private Sub Command1_Click()
    Console "set name x39rox"
    End Sub

    EDIT: Ok, i fixed the error. Just had the stuff in the wrong places and that. But now, when I press the button, the program hangs for a bit, then just exits, w/o asking me to save or anything. I didnt have the game open, maybe thats the problem. Ill go check now...
    Well, that wasnt it. Still does the same thing. Maybe I have all of the stuff in wrong places, mods, and forms, and that. Wow, Im so confused and frustrated. Hm, what in the world can be wrong?
    Last edited by x39rox; Jul 22nd, 2003 at 12:05 PM.

  18. #18
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    Ok let me tell you what you need in the form and what you need in the module.

    In the form you will need
    VB Code:
    1. Private Sub Console(ByVal cgCmd As String)
    2. Dim MohCons As Long
    3. MohCons = FindWindow(0, "Mohaa Console")
    4. EnumChildWindows MohCons, AddressOf EnumChildSendCommandProc, StrPtr(cgCmd)
    5. End Sub
    6.  
    7. Private Sub Command1_Click()
    8. Console "set name x39rox"
    9. End Sub

    In the module you will need
    VB Code:
    1. Public Const GWL_STYLE& = (-16)
    2. Public Const WM_CHAR = &H102
    3. Public Const WM_SETTEXT = &HC
    4. Public Const ES_READONLY = &H800
    5.  
    6. Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    7.  
    8. Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    9.  
    10. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    11.  
    12. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    13.  
    14. Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    15.  
    16.  
    17. Public Function EnumChildSendCommandProc(hwnd As Long,lParam As Long) as Boolean
    18. Dim ClassName As String*1024
    19. GetClassName hwnd,className,len(className)
    20. if className="Edit" Then EnumChildSendCommandProc=True
    21. if ES_READONLY And GetWindowLong(hwnd,GWL_STYLE) Then EnumChildSendCommandProc=True
    22. SendMessage hwnd,WM_SETTEXT,0,lParam
    23. SendMessage hwnd,WM_CHAR,13,0
    24. EnumChildSendCommandProc=True
    25. End Function

    Also use <vbcode> and </vbcode> when you are placing code. But put [ ] instead of < >

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Ok, thanks for the vbcode tip. Now, I have the code in right places, put when I press the button, the program hangs for maybe 2 seconds, then quits, no questions asked. I can't see anything that's conflicting, probably because I'm not too good like you guys yet. Well actually, would it make a difference if the game was in windowed mode, and not full? I have it in windowed so I can press the button in vB, ya know?

  20. #20
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    I don't think it matters about the full or windowed mode. What I would do is step through your code in run time and see at what point it hangs. Also make sure it is getting a handle for the window when it calls findwindow. I never tried do anything like this myself, I a just trying to help you with what I do know

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Ok, can you tell me how exactly to see what it finds when findwindow is called?

    EDIT: Ok, well I found 'step into', but I only have one button and when I press it, it just locks for 2 secs and quits.

    EDIT2: Well, I don't know if this is telling me what I just pressed, or a problem, but when I 'step into', then press the button, it highlights "Private Sub Command1_Click()" which is the button.
    Last edited by x39rox; Jul 22nd, 2003 at 02:03 PM.

  22. #22
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    I am pretty sure you know about breakpoints right? Since you can put breakpoints in C++. Well you can do the same thing in VB. Just put a breakpoint on that line. Then run your program. Then hit the command button and when it reaches that line the program will stop and go into debug mode where you can run the code line by line. You use F8 to run a line of code. If you hit F5 it will run the rest of the code or run to the next breakpoint. Once you are in debug mode you can hit F8 to run the FindWindow line of code and then put your mouse pointer over the MohCons variable. Soon a tooltip popup will show up giving you the value of that variable.

    To insert a breakpoint you can click on the left panel of the code screen on the line of code where you want the breakpoint. Or you can move your mouse cursor where you want the breakpoint to be, then go to Debug->Toggle Breakpoint, or move your mouse cursor to the line you want the breakpoint on and hit F9.

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Hm, well MohCons = 0. So it's not finding the window. That's not good. Why would that be?

  24. #24
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    Well is Mohass Console a child window? Because FindWindow does not work for child windows.

  25. #25
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    Ok I made you a form with a module in it to show you how to do it. Maybe you can look at it and apply it to what you want. Just create a new project and add the form and module to the project. Then set Form1 as the start up form in the properties. Then when you run it, if you click the command button notice how the command button text changes. I hope this helps.
    Attached Files Attached Files

  26. #26

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Yea, it is. The main window is "Medal of Honor Allied Assault". Mohaa Console is in there. So Mohaa COnsole is a child. I'm doing more of the breakpoint thing also, and I found out that:

    classname = "all these weird characters that show up as squares".

    So, I guess there has to be another command to find a child window then?

    Edit: That test you made helped me to change button labels when pressed, thank you. But I think Mohaa Console id a child window, as it is in the main window "Medal of Honor Allied Assault".
    Last edited by x39rox; Jul 22nd, 2003 at 04:53 PM.

  27. #27
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    Well basicially what you are gonna do is find the parent window which is "Medal of Honor Allied Assault". Then when you call EnumChildWindows, it is going to go through each child window and set your text. The only child windows it won't is if it is readonly and if it is under the "Edit" Classname. So this is what your code should look like.

    In the form
    VB Code:
    1. Private Sub Command1_Click()
    2.     Console "set name x39rox"
    3. End Sub
    4.  
    5. Private Sub Console(ByVal cgCmd As String)
    6.     Dim Ret As String
    7.  
    8.     Ret = "Medal of Honor Allied Assault"
    9.     WinWnd = FindWindow(vbNullString, Ret)
    10.     Me.AutoRedraw = True
    11.    
    12.     EnumChildWindows WinWnd, AddressOf EnumChildProc, StrPtr(cgCmd)
    13. End Sub

    Then in your module
    VB Code:
    1. Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, _
    2.     ByVal lpWindowName As String) As Long
    3.  
    4. Public Declare Function SendMessage Lib _
    5. "user32" Alias "SendMessageA" (ByVal hwnd _
    6. As Long, ByVal wMsg As Long, ByVal wParam _
    7. As Long, lParam As Any) As Long
    8.  
    9. Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
    10.     Dim lpClassName As String
    11.     Dim RetVal As Long
    12.    
    13.     'Create a buffer
    14.     ShowWindow hwnd, SW_SHOWNORMAL
    15.     lpClassName = Space(256)
    16.     'retrieve the class name
    17.     RetVal = GetClassName(hwnd, lpClassName, 256)
    18.    
    19.     If Left(lpClassName, RetVal) = "Edit" Then EnumChildProc = True
    20.     If ES_READONLY And GetWindowLong(hwnd, GWL_STYLE) Then EnumChildProc = True
    21.     SendMessage hwnd, WM_SETTEXT, 0, lParam
    22.     SendMessage hwnd, WM_CHAR, 13, 0
    23.     EnumChildProc = 1
    24.  
    25. End Function

  28. #28

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Well, that looks decent. Except it does the same thing as the other one, it hangs for 2 secs, then exits. I am truely sorry for the trouble you are going through just to help me out. I appreciate it so much, and I'm learning every step of the way. But, have you tried to run this?

  29. #29
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    I have checked EnumChildProc .. it's causing error.. so i used FindWindowEx function. What following code does ..It finds a window named Medal of Honor Allied Assault then it find among its children the window named "Mohaa Console" then in this window it finds a window which is not EDIT and which is NOT readonly... (well i just cudn't understand this part why is it so??)
    then sending the message. All the Finding things are working fine.. (I didn't check with your parameters though)... SendMessage i just cudn't try....
    I changed your most of the code (if not entire code) But i tried to solve the problem .... not to recorrect the code...
    Tell me if it did..
    VB Code:
    1. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    2. Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    3. Public Declare Function getClassName Lib "user32" Alias "GetClassNameA" (ByVal Hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    4. Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    5. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    6. Public Const GWL_EXSTYLE = (-20)
    7. Public Const WM_CHAR = &H102
    8. Public Const WM_SETTEXT = &HC
    9. Public Const ES_READONLY = &H800&
    10. Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long
    11. Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    12. Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal Hwnd As Long) As Long
    13. Public Sub Console(cgCmd As String)
    14.      Dim MohCons As Long
    15.      Dim ParentWindow As Long
    16.      Dim ActualConsole As Long
    17.      
    18.      ParentWindow = FindWindowEx(0, 0, vbNullString, "Medal of Honor Allied Assault")
    19.      If ParentWindow Then
    20.             MohCons = FindWindowEx(ParentWindow, MohCons, vbNullString, "Mohaa Console")
    21.  
    22.                 Do
    23.                     ActualConsole = FindWindowEx(MohCons, actualwindow, vbNullString, vbNullString)
    24.                     If UCase(getClassNameFromHwnd(MohCons)) = UCase("Edit") Or (ES_READONLY And GetWindowLong(actualwindow, GWL_STYLE)) Then
    25.                     Else
    26.                         SendMessage ActualConsole, WM_SETTEXT, 0, cgCmd
    27.                         SendMessage ActualConsole, WM_CHAR, 13, 0
    28.                     End If
    29.                    
    30.                 Loop While ActualConsole <> 0
    31.      End If
    32. End Sub
    33. Public Function getNameFromHwnd(Hwnd As Long) As String
    34. Dim title As String * 255
    35. Dim tLen As Long
    36. tLen = GetWindowTextLength(Hwnd)
    37. GetWindowText Hwnd, title, 255
    38. getNameFromHwnd = Left(title, tLen)
    39. End Function
    40. Public Function getClassNameFromHwnd(Hwnd As Long) As String
    41. Dim ClassName As String * 1024
    42. getClassName Hwnd, ClassName, 1024
    43. getClassNameFromHwnd = Left(ClassName, InStr(1, ClassName, Chr(0)) - 1)
    44. End Function
    Last edited by moinkhan; Jul 23rd, 2003 at 01:54 AM.

  30. #30

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Wow. Never seen that before. Uhm, it changed all my window names to a flashing square and some weird ascii text. Like it was looping, which i seen in the code. I couldnt stop i, so i had to restart. Hm. I cant believe you wrote all that. Man i wish i could do that, heh. Well, any ideas why it froze my comp? Lol, o yeah, it still didnt do the command. I talked with the guy that made the c++ code, and he said he THINKS Mohaa Console is a parent window. See, in the game u can press ` and the console will open. And its called MOhaa Console as well, which is why i said its a child. But there is also a console hat stays open while u play, which is what i think that code that he made uses. So, a direct perfect transformation of that c++ code that i posted into vB would work, i assume. What if anything can I do for you guys that are trying so hard for me, noone ever did this for me...ever. Well, if ya can, try to see what went wrong, and thing of somehting i can do for u guys. Thanks guys, check back later.

  31. #31
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Ooops!!!!!!!! DAmn it!!
    in the statement right after Do Replace actualwindow with ActualConsole
    ActualConsole = FindWindowEx(MohCons, actualwindow, vbNullString, vbNullString)

  32. #32

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Lol, well now when I press the button, EVERY one of my windows gets its name changed to some weird ascii text. No freezing tho, just looks like someone hacked my computer, lol.

  33. #33
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    WM_SETTEXT msg behaves differently for different types of classes....If you will send this message to a window it will try to change the Caption of the window(this is what it is doing for u).. if sent to a textbox it will write the text within the textbox..What i think Mohaa Console should be an Edit Window (TextField) then when you send this message to it.... the text will be entered then you are sending WM_CHAR to mimic Enter effect....Am i Right...Can you send me That Gaming software (Mohaaa) at [email protected]??? I will check my coding with real world parameters
    well.. if yes tell me so that i check my this account.....

  34. #34

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Well, its a real game. 50 bucks if your a nice guy... If your a guy that knows some things, you can get it for cheaper, maybe even for nothing... . That would be GREAT if you could 'aquire it' and work with it. Thanks for ALL yur help so far man, i've learned alot. I might post on another forum, see if anyone can get it workin. Thanks again man.

  35. #35
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Excuse MEeeeeee!!!! When u say "I will try another forum" you insult US (not United States.. US means US..WE)
    OK!!! I don't require the game... i will mimic one and then will do whatever you want and will send that to u... Atlast this is the question of our PRESTIGE...

    (JUST KIDDING)
    Except for the promise that i'll look into your problem more..

  36. #36

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Wow. Your really gung-ho about this. That's so cool. You can't even think on how much I appreciate this. I know I've said it alot, but I can't say it enough. Thank you so much. I have to get ready for work now, I'll check back when I get home.

  37. #37
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Here you go... The Zip file below contains an Exe and a vb project. when you run that exe A parent window comes which contains Mohaa Console window which contains a textbox which contains NOthing .. Run this exe then
    Run the project and click the Command1 button.. and see what happens..

    Oopss.. silly me.. see next msg for the zip file
    Last edited by moinkhan; Jul 25th, 2003 at 01:26 AM.

  38. #38
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    This is the zip file
    Attached Files Attached Files

  39. #39

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Wow, no way! You are so awesome. Except it's in some php form and not a zip, lol. Hurry post the zip!


    Never mind. I just renames it. Ill test it out now man. Wow. Thx so mcuh.

  40. #40

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    18
    Wow. Well I found two things. This code rocks btw. Anyway, you have to start the the mohaa mimic first THEN start the button. Then it works, if u dont do it that way, it wont. Second, it works perfect in the mimic, but now in the game sadly, it doesnt. So, what I'm thinking is use the same method, just make Mohaa Console a parent, like its own window. And make the command send right to the window "Mohaa Console" instead of going through "Medal of Honor Allied Assault" first. I was told by the guy that gave me the c++ code that thats how his works. If c++ can send to it as a parent, then vB can. So, try that. Man, I wish I could like give you money or something, lol. I feel so bad for asking you for this stuff. Whats your aim or msn handle if you have one or the other. We can talk more on there and maybe arrange for me to give you something, heh. I thank you so much. Never have I ever gone to a forum and gotten this much help. Never. VERY good words go out for this one, all because of you . Well, GL man. O btw, my msn = [email protected]

Page 1 of 2 12 LastLast

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