| |

VerySource

 Forgot password?
 Register
Search
View: 1640|Reply: 12

FindWindow, SendMessage problem (urgent)

[Copy link]

1

Threads

7

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-9-28 21:30:02
| Show all posts |Read mode
The problem is this:
I want to pass a value to a text box (TextBox) in an application written by vb in vc
In vc, I first get the handle of the application (test) written by this vb
HWND hWnd = FindWindow(NULL, "Test");
Then use SendMessage to send a message to this handle
The question now is how to set the parameters of SendMessage and how to get the passed value in vb.
Thank you!
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-9-28 21:45:01
| Show all posts
sendmessage hwnd,WM_SETTEXT,0,"string"

It seems that VB can be notified in the Text1_Change event
Reply

Use magic Report

1

Threads

7

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-9-28 23:15:01
| Show all posts
Hellominlichao, the hwnd in your parameter is for TextBox, but FindWindow can only get the window
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-9-29 10:45:01
| Show all posts
Use findwindow directly in VB
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-9-29 14:45:02
| Show all posts
sendmessage hwnd,WM_SETTEXT,0,byval "string"
Reply

Use magic Report

1

Threads

11

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-9-29 23:45:01
| Show all posts
If you need to get the hwnd of the textbox
Need to use findwindowEx
Reply

Use magic Report

1

Threads

7

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-9-30 10:45:01
| Show all posts
Thank you, findwindowEx can get the handle of the textbox, but how to get the handle of the specified textbox, that is, if there are two textboxes, how can I get the handle of the second one?
Reply

Use magic Report

1

Threads

7

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-9-30 11:00:01
| Show all posts
In addition, I got the handle in vb in vc
Reply

Use magic Report

1

Threads

7

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-9-30 12:15:01
| Show all posts
I changed to WM_COPYDATA to do it now, but there was a problem again, the situation is as follows:
vb:
Private Sub Form_Load()
    gHW = Me.hwnd
    lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
End Sub
//In the module
Public Const WM_COPYDATA =&H4A
Public Const GWL_WNDPROC = -4
  
Public Declare Function FindWindow Lib "user32" Alias ​​"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function CallWindowProc Lib "user32" Alias ​​"CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias ​​"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
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
  
Global lpPrevWndProc As Long
Global gHW As Long

Public Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Select Case uMsg
      Case WM_COPYDATA
          MsgBox "ok"
          MsgBox lParam
          WindowProc = 0
          Exit Function
    End Select
    WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
  End Function

vc:
//Get the window handle first
HWND hWnd = ::FindWindow(NULL, "License Plate Recognition Test");
//Get the TextBox handle
HWND hWndTextBox = ::FindWindowEx(hWnd, NULL, "ThunderRT6TextBox", NULL);
//::SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)m_strPlateNum);
if (::IsWindow(hWndTextBox))
{
//::SendMessage(hWndTextBox, WM_SETTEXT, 0, (LPARAM)m_strPlateNum.GetBuffer());
::SendMessage(hWnd, WM_COPYDATA, 0, (LPARAM)m_strPlateNum.GetBuffer());
}
else
{
::MessageBox(NULL, "No window found", "Recognition", 0);
}
But the dialog box will not pop up?
Don't know where the problem is?
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-9-30 12:30:01
| Show all posts
Easy to use files or registry
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list