21 个解决方案
#1
用SendMessage可以吗?该怎么写呢?
#2
up
#3
就用SendMessage,要不PostMessage也成
#4
如何得到窗口句柄呢?
#5
鼠标的焦点已经在另一个程序中的一个文本框中!
这不是很简单的事了吗?
这不是很简单的事了吗?
#6
大虾,直接SendMessage可以吗?可是怎么获得窗口句柄呢?
#7
用sendMessage或者是用socket的方法进行通信
#8
up
#9
#include "stdafx.h"
#include "resource.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
CString g_path;
CString g_user;
CString g_pass;
BOOL m_bFlag;
UINT counter=0;
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam);
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CWnd* pWnd=CWnd::FindWindow(NULL,_T("IP出校设置器"));
if(pWnd)
{
MessageBox(NULL,"IPClient已经运行了","错误",MB_ICONSTOP);
return 0;
}
MSG msg;
HWND hWnd;
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if(-1==::GetFileAttributes("c:\\autofix.ini"))
{
CString strCmd=lpCmdLine;
if(strCmd.GetLength()<5)
{
MessageBox(hWnd,"初次运行,请将ipclient的图标拖动到本程序图标上","初次运行",MB_ICONINFORMATION);
return 0;
}
g_path=lpCmdLine;
DialogBox(hInstance, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
return 0;
}
else
{
char path[260];
char user[32];
char pass[32];
memset(path,0,260);
memset(user,0,32);
memset(pass,0,32);
::GetPrivateProfileString("IPCLIENT","path",NULL,path,260,"c:\\autofix.ini");
::GetPrivateProfileString("IPCLIENT","user",NULL,user,32,"c:\\autofix.ini");
::GetPrivateProfileString("IPCLIENT","pass",NULL,pass,32,"c:\\autofix.ini");
if(::GetFileAttributes(path)==-1)
{
MessageBox(hWnd,"ipclient.exe路径不正确","错误",MB_ICONSTOP);
::DeleteFile("c:\\autofix.ini");
PostQuitMessage(0);
}
::WinExec(path,SW_SHOW);
Sleep(500);
g_user=user;
g_pass=pass;
m_bFlag=TRUE;
while (m_bFlag)
{
EnumWindows(EnumWindowsProc, 0);
}
}
return msg.wParam;
}
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId = LOWORD(wParam);
int wmEvent = HIWORD(wParam);
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
switch (wmId)
{
case IDC_LOGIN:
char user[32];
char pass[32];
memset(user,0,32);
memset(pass,0,32);
GetWindowText(GetDlgItem(hDlg,IDC_EDIT1),user,32);
GetWindowText(GetDlgItem(hDlg,IDC_EDIT2),pass,32);
::WritePrivateProfileString("IPCLIENT","path",g_path,"c:\\autofix.ini");
::WritePrivateProfileString("IPCLIENT","user",user,"c:\\autofix.ini");
::WritePrivateProfileString("IPCLIENT","pass",pass,"c:\\autofix.ini");
::WinExec(g_path,SW_SHOW);
Sleep(500);
g_user=user;
g_pass=pass;
if(g_user.IsEmpty()||g_pass.IsEmpty())
{
MessageBox(NULL,"帐户或者密码为空","错误",MB_ICONSTOP);
CWnd* pWnd=CWnd::FindWindow(NULL,_T("IP出校设置器"));
if(pWnd)
{
pWnd->PostMessage(WM_CLOSE);
}
::DeleteFile("c:\\autofix.ini");
PostQuitMessage(0);
}
m_bFlag=TRUE;
while (m_bFlag)
{
EnumWindows(EnumWindowsProc, 0);
}
PostQuitMessage(0);
break;
}
break;
}
return FALSE;
}
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
{
char sWindowClass[256];
CString strWindowClass;
CString strWindowName;
::GetClassName(hwnd, sWindowClass, 256);
strWindowClass = sWindowClass;
if(strWindowClass==_T("KUIElement"))
{
::SendMessage(::GetParent(hwnd),WM_COMMAND,(WPARAM)::GetWindowLong(hwnd,GWL_ID),(LPARAM)hwnd);
}
if (strWindowClass == _T("TMaskEdit")||
strWindowClass == _T("TEdit")
)
{
if(counter==0)
{
char m_pass[260];
memset(m_pass,0,260);
strcpy(m_pass,g_pass);
::SendMessage(hwnd,WM_SETTEXT,260,(LPARAM)m_pass);
}
if(counter==1)
{
char m_user[260];
memset(m_user,0,260);
strcpy(m_user,g_user);
::SendMessage(hwnd,WM_SETTEXT,260,(LPARAM)(char*)m_user);
::SetForegroundWindow(hwnd);
::SendMessage(hwnd,WM_SETFOCUS,NULL,NULL);
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
PostQuitMessage(0);
}
counter++;
}
return TRUE;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
CString sWindowText;
GetWindowText(hwnd, sWindowText.GetBuffer(256), 256);
sWindowText.ReleaseBuffer();
if(sWindowText.Left(2)=="IP")
// if (sWindowText.Find(_T("IP出校设置器")) != -1)
{
m_bFlag=FALSE;
::EnumChildWindows(hwnd, EnumChildProc, 0);
}
return TRUE;
}
#include "resource.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
CString g_path;
CString g_user;
CString g_pass;
BOOL m_bFlag;
UINT counter=0;
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam);
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CWnd* pWnd=CWnd::FindWindow(NULL,_T("IP出校设置器"));
if(pWnd)
{
MessageBox(NULL,"IPClient已经运行了","错误",MB_ICONSTOP);
return 0;
}
MSG msg;
HWND hWnd;
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if(-1==::GetFileAttributes("c:\\autofix.ini"))
{
CString strCmd=lpCmdLine;
if(strCmd.GetLength()<5)
{
MessageBox(hWnd,"初次运行,请将ipclient的图标拖动到本程序图标上","初次运行",MB_ICONINFORMATION);
return 0;
}
g_path=lpCmdLine;
DialogBox(hInstance, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
return 0;
}
else
{
char path[260];
char user[32];
char pass[32];
memset(path,0,260);
memset(user,0,32);
memset(pass,0,32);
::GetPrivateProfileString("IPCLIENT","path",NULL,path,260,"c:\\autofix.ini");
::GetPrivateProfileString("IPCLIENT","user",NULL,user,32,"c:\\autofix.ini");
::GetPrivateProfileString("IPCLIENT","pass",NULL,pass,32,"c:\\autofix.ini");
if(::GetFileAttributes(path)==-1)
{
MessageBox(hWnd,"ipclient.exe路径不正确","错误",MB_ICONSTOP);
::DeleteFile("c:\\autofix.ini");
PostQuitMessage(0);
}
::WinExec(path,SW_SHOW);
Sleep(500);
g_user=user;
g_pass=pass;
m_bFlag=TRUE;
while (m_bFlag)
{
EnumWindows(EnumWindowsProc, 0);
}
}
return msg.wParam;
}
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId = LOWORD(wParam);
int wmEvent = HIWORD(wParam);
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
switch (wmId)
{
case IDC_LOGIN:
char user[32];
char pass[32];
memset(user,0,32);
memset(pass,0,32);
GetWindowText(GetDlgItem(hDlg,IDC_EDIT1),user,32);
GetWindowText(GetDlgItem(hDlg,IDC_EDIT2),pass,32);
::WritePrivateProfileString("IPCLIENT","path",g_path,"c:\\autofix.ini");
::WritePrivateProfileString("IPCLIENT","user",user,"c:\\autofix.ini");
::WritePrivateProfileString("IPCLIENT","pass",pass,"c:\\autofix.ini");
::WinExec(g_path,SW_SHOW);
Sleep(500);
g_user=user;
g_pass=pass;
if(g_user.IsEmpty()||g_pass.IsEmpty())
{
MessageBox(NULL,"帐户或者密码为空","错误",MB_ICONSTOP);
CWnd* pWnd=CWnd::FindWindow(NULL,_T("IP出校设置器"));
if(pWnd)
{
pWnd->PostMessage(WM_CLOSE);
}
::DeleteFile("c:\\autofix.ini");
PostQuitMessage(0);
}
m_bFlag=TRUE;
while (m_bFlag)
{
EnumWindows(EnumWindowsProc, 0);
}
PostQuitMessage(0);
break;
}
break;
}
return FALSE;
}
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
{
char sWindowClass[256];
CString strWindowClass;
CString strWindowName;
::GetClassName(hwnd, sWindowClass, 256);
strWindowClass = sWindowClass;
if(strWindowClass==_T("KUIElement"))
{
::SendMessage(::GetParent(hwnd),WM_COMMAND,(WPARAM)::GetWindowLong(hwnd,GWL_ID),(LPARAM)hwnd);
}
if (strWindowClass == _T("TMaskEdit")||
strWindowClass == _T("TEdit")
)
{
if(counter==0)
{
char m_pass[260];
memset(m_pass,0,260);
strcpy(m_pass,g_pass);
::SendMessage(hwnd,WM_SETTEXT,260,(LPARAM)m_pass);
}
if(counter==1)
{
char m_user[260];
memset(m_user,0,260);
strcpy(m_user,g_user);
::SendMessage(hwnd,WM_SETTEXT,260,(LPARAM)(char*)m_user);
::SetForegroundWindow(hwnd);
::SendMessage(hwnd,WM_SETFOCUS,NULL,NULL);
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
PostQuitMessage(0);
}
counter++;
}
return TRUE;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
CString sWindowText;
GetWindowText(hwnd, sWindowText.GetBuffer(256), 256);
sWindowText.ReleaseBuffer();
if(sWindowText.Left(2)=="IP")
// if (sWindowText.Find(_T("IP出校设置器")) != -1)
{
m_bFlag=FALSE;
::EnumChildWindows(hwnd, EnumChildProc, 0);
}
return TRUE;
}
#10
HWND hwnd = ::GetFocus();
char ch[]="0123456789";
for (i = 0 ;i<10 ; i++)
::PostMessage (hwnd, WM_CHAR, (WPARAM)chqq[i], 0);//发送字符
::PostMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);//发送回车消息
char ch[]="0123456789";
for (i = 0 ;i<10 ; i++)
::PostMessage (hwnd, WM_CHAR, (WPARAM)chqq[i], 0);//发送字符
::PostMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);//发送回车消息
#11
GetFocus不行吧,我不是在同一个程序中,我是向另一个程序的一个文本框发送,该怎么获得这个文本框的句柄呢?
#12
To richie_cn(追风无影剑) :
HWND hWnd=::GetForegroundWindow();
HWND hEdit=::GetFocus();
char ch[]="0123456789";
for (int i = 0 ;i<10 ; i++)
::PostMessage (hEdit, WM_CHAR, (WPARAM)ch[i], 0);//·¢ËÍ×Ö·û
::SetWindowText(hWnd,"Test");
//程序的标题可以被更改,但是程序中的文本框还是没有输入字符,怎么回事?
HWND hWnd=::GetForegroundWindow();
HWND hEdit=::GetFocus();
char ch[]="0123456789";
for (int i = 0 ;i<10 ; i++)
::PostMessage (hEdit, WM_CHAR, (WPARAM)ch[i], 0);//·¢ËÍ×Ö·û
::SetWindowText(hWnd,"Test");
//程序的标题可以被更改,但是程序中的文本框还是没有输入字符,怎么回事?
#13
hFwnd是父窗口句柄
hChild是子窗口句柄(控件)
hFwnd::=findWindow(classname,caption);//找父窗口句柄
hChild=::FindWindowFromPoint(hFwnd.....);//找子窗口句柄
::SendMessage(hChild,WM_CHAR,(WPARAM)chqq[i], 0);//发送字符
hChild是子窗口句柄(控件)
hFwnd::=findWindow(classname,caption);//找父窗口句柄
hChild=::FindWindowFromPoint(hFwnd.....);//找子窗口句柄
::SendMessage(hChild,WM_CHAR,(WPARAM)chqq[i], 0);//发送字符
#14
有这个函数吗?FindWindowFromPoint
我MSDN找不到?
我MSDN找不到?
#15
如何得到已经有焦点的这个文本框的句柄?
#16
BOOL EnumChildWindows(
HWND hWndParent, // handle to parent window
WNDENUMPROC lpEnumFunc, // callback function
LPARAM lParam // application-defined value
);
HWND hWndParent, // handle to parent window
WNDENUMPROC lpEnumFunc, // callback function
LPARAM lParam // application-defined value
);
#17
学习!
#18
鼠标钩子(WH_MOUSE Hook),取得鼠标下方子窗体的HANDLE.
不过写钩子程序挺麻烦,得写个dll文件
不过写钩子程序挺麻烦,得写个dll文件
#19
我晕~~~~人家问的这么简单的问题,竟然弄出这么多内容来!!!
HWND hWnd = ::FindWindow("TFormMain","Window name"); //查找目标窗口句柄
HWND eWnd = ::FindWindowEx(hWnd,NULL,"TEdit",""); //查找目标窗口的Edit控件句柄
::SendMessage(eWnd,WM_SETTEXT,0,(LPARAM)IP.GetBuffer(IP.GetLength())); //向目标的Edit控件发送文本
::PostMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);//向目标的Edit控件发送回车键消息!
HWND hWnd = ::FindWindow("TFormMain","Window name"); //查找目标窗口句柄
HWND eWnd = ::FindWindowEx(hWnd,NULL,"TEdit",""); //查找目标窗口的Edit控件句柄
::SendMessage(eWnd,WM_SETTEXT,0,(LPARAM)IP.GetBuffer(IP.GetLength())); //向目标的Edit控件发送文本
::PostMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);//向目标的Edit控件发送回车键消息!
#20
如果TEXT窗体由焦点的话,没必要钩子
用
HWND WindowFromPoint(
POINT Point // point
);
用
HWND WindowFromPoint(
POINT Point // point
);
#21
如果是IE中的文本框怎么办? 不是一个窗口?如何在IE中的两个文本框中移动输入焦点?
#1
用SendMessage可以吗?该怎么写呢?
#2
up
#3
就用SendMessage,要不PostMessage也成
#4
如何得到窗口句柄呢?
#5
鼠标的焦点已经在另一个程序中的一个文本框中!
这不是很简单的事了吗?
这不是很简单的事了吗?
#6
大虾,直接SendMessage可以吗?可是怎么获得窗口句柄呢?
#7
用sendMessage或者是用socket的方法进行通信
#8
up
#9
#include "stdafx.h"
#include "resource.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
CString g_path;
CString g_user;
CString g_pass;
BOOL m_bFlag;
UINT counter=0;
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam);
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CWnd* pWnd=CWnd::FindWindow(NULL,_T("IP出校设置器"));
if(pWnd)
{
MessageBox(NULL,"IPClient已经运行了","错误",MB_ICONSTOP);
return 0;
}
MSG msg;
HWND hWnd;
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if(-1==::GetFileAttributes("c:\\autofix.ini"))
{
CString strCmd=lpCmdLine;
if(strCmd.GetLength()<5)
{
MessageBox(hWnd,"初次运行,请将ipclient的图标拖动到本程序图标上","初次运行",MB_ICONINFORMATION);
return 0;
}
g_path=lpCmdLine;
DialogBox(hInstance, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
return 0;
}
else
{
char path[260];
char user[32];
char pass[32];
memset(path,0,260);
memset(user,0,32);
memset(pass,0,32);
::GetPrivateProfileString("IPCLIENT","path",NULL,path,260,"c:\\autofix.ini");
::GetPrivateProfileString("IPCLIENT","user",NULL,user,32,"c:\\autofix.ini");
::GetPrivateProfileString("IPCLIENT","pass",NULL,pass,32,"c:\\autofix.ini");
if(::GetFileAttributes(path)==-1)
{
MessageBox(hWnd,"ipclient.exe路径不正确","错误",MB_ICONSTOP);
::DeleteFile("c:\\autofix.ini");
PostQuitMessage(0);
}
::WinExec(path,SW_SHOW);
Sleep(500);
g_user=user;
g_pass=pass;
m_bFlag=TRUE;
while (m_bFlag)
{
EnumWindows(EnumWindowsProc, 0);
}
}
return msg.wParam;
}
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId = LOWORD(wParam);
int wmEvent = HIWORD(wParam);
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
switch (wmId)
{
case IDC_LOGIN:
char user[32];
char pass[32];
memset(user,0,32);
memset(pass,0,32);
GetWindowText(GetDlgItem(hDlg,IDC_EDIT1),user,32);
GetWindowText(GetDlgItem(hDlg,IDC_EDIT2),pass,32);
::WritePrivateProfileString("IPCLIENT","path",g_path,"c:\\autofix.ini");
::WritePrivateProfileString("IPCLIENT","user",user,"c:\\autofix.ini");
::WritePrivateProfileString("IPCLIENT","pass",pass,"c:\\autofix.ini");
::WinExec(g_path,SW_SHOW);
Sleep(500);
g_user=user;
g_pass=pass;
if(g_user.IsEmpty()||g_pass.IsEmpty())
{
MessageBox(NULL,"帐户或者密码为空","错误",MB_ICONSTOP);
CWnd* pWnd=CWnd::FindWindow(NULL,_T("IP出校设置器"));
if(pWnd)
{
pWnd->PostMessage(WM_CLOSE);
}
::DeleteFile("c:\\autofix.ini");
PostQuitMessage(0);
}
m_bFlag=TRUE;
while (m_bFlag)
{
EnumWindows(EnumWindowsProc, 0);
}
PostQuitMessage(0);
break;
}
break;
}
return FALSE;
}
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
{
char sWindowClass[256];
CString strWindowClass;
CString strWindowName;
::GetClassName(hwnd, sWindowClass, 256);
strWindowClass = sWindowClass;
if(strWindowClass==_T("KUIElement"))
{
::SendMessage(::GetParent(hwnd),WM_COMMAND,(WPARAM)::GetWindowLong(hwnd,GWL_ID),(LPARAM)hwnd);
}
if (strWindowClass == _T("TMaskEdit")||
strWindowClass == _T("TEdit")
)
{
if(counter==0)
{
char m_pass[260];
memset(m_pass,0,260);
strcpy(m_pass,g_pass);
::SendMessage(hwnd,WM_SETTEXT,260,(LPARAM)m_pass);
}
if(counter==1)
{
char m_user[260];
memset(m_user,0,260);
strcpy(m_user,g_user);
::SendMessage(hwnd,WM_SETTEXT,260,(LPARAM)(char*)m_user);
::SetForegroundWindow(hwnd);
::SendMessage(hwnd,WM_SETFOCUS,NULL,NULL);
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
PostQuitMessage(0);
}
counter++;
}
return TRUE;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
CString sWindowText;
GetWindowText(hwnd, sWindowText.GetBuffer(256), 256);
sWindowText.ReleaseBuffer();
if(sWindowText.Left(2)=="IP")
// if (sWindowText.Find(_T("IP出校设置器")) != -1)
{
m_bFlag=FALSE;
::EnumChildWindows(hwnd, EnumChildProc, 0);
}
return TRUE;
}
#include "resource.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
CString g_path;
CString g_user;
CString g_pass;
BOOL m_bFlag;
UINT counter=0;
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam);
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CWnd* pWnd=CWnd::FindWindow(NULL,_T("IP出校设置器"));
if(pWnd)
{
MessageBox(NULL,"IPClient已经运行了","错误",MB_ICONSTOP);
return 0;
}
MSG msg;
HWND hWnd;
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if(-1==::GetFileAttributes("c:\\autofix.ini"))
{
CString strCmd=lpCmdLine;
if(strCmd.GetLength()<5)
{
MessageBox(hWnd,"初次运行,请将ipclient的图标拖动到本程序图标上","初次运行",MB_ICONINFORMATION);
return 0;
}
g_path=lpCmdLine;
DialogBox(hInstance, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
return 0;
}
else
{
char path[260];
char user[32];
char pass[32];
memset(path,0,260);
memset(user,0,32);
memset(pass,0,32);
::GetPrivateProfileString("IPCLIENT","path",NULL,path,260,"c:\\autofix.ini");
::GetPrivateProfileString("IPCLIENT","user",NULL,user,32,"c:\\autofix.ini");
::GetPrivateProfileString("IPCLIENT","pass",NULL,pass,32,"c:\\autofix.ini");
if(::GetFileAttributes(path)==-1)
{
MessageBox(hWnd,"ipclient.exe路径不正确","错误",MB_ICONSTOP);
::DeleteFile("c:\\autofix.ini");
PostQuitMessage(0);
}
::WinExec(path,SW_SHOW);
Sleep(500);
g_user=user;
g_pass=pass;
m_bFlag=TRUE;
while (m_bFlag)
{
EnumWindows(EnumWindowsProc, 0);
}
}
return msg.wParam;
}
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId = LOWORD(wParam);
int wmEvent = HIWORD(wParam);
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
switch (wmId)
{
case IDC_LOGIN:
char user[32];
char pass[32];
memset(user,0,32);
memset(pass,0,32);
GetWindowText(GetDlgItem(hDlg,IDC_EDIT1),user,32);
GetWindowText(GetDlgItem(hDlg,IDC_EDIT2),pass,32);
::WritePrivateProfileString("IPCLIENT","path",g_path,"c:\\autofix.ini");
::WritePrivateProfileString("IPCLIENT","user",user,"c:\\autofix.ini");
::WritePrivateProfileString("IPCLIENT","pass",pass,"c:\\autofix.ini");
::WinExec(g_path,SW_SHOW);
Sleep(500);
g_user=user;
g_pass=pass;
if(g_user.IsEmpty()||g_pass.IsEmpty())
{
MessageBox(NULL,"帐户或者密码为空","错误",MB_ICONSTOP);
CWnd* pWnd=CWnd::FindWindow(NULL,_T("IP出校设置器"));
if(pWnd)
{
pWnd->PostMessage(WM_CLOSE);
}
::DeleteFile("c:\\autofix.ini");
PostQuitMessage(0);
}
m_bFlag=TRUE;
while (m_bFlag)
{
EnumWindows(EnumWindowsProc, 0);
}
PostQuitMessage(0);
break;
}
break;
}
return FALSE;
}
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
{
char sWindowClass[256];
CString strWindowClass;
CString strWindowName;
::GetClassName(hwnd, sWindowClass, 256);
strWindowClass = sWindowClass;
if(strWindowClass==_T("KUIElement"))
{
::SendMessage(::GetParent(hwnd),WM_COMMAND,(WPARAM)::GetWindowLong(hwnd,GWL_ID),(LPARAM)hwnd);
}
if (strWindowClass == _T("TMaskEdit")||
strWindowClass == _T("TEdit")
)
{
if(counter==0)
{
char m_pass[260];
memset(m_pass,0,260);
strcpy(m_pass,g_pass);
::SendMessage(hwnd,WM_SETTEXT,260,(LPARAM)m_pass);
}
if(counter==1)
{
char m_user[260];
memset(m_user,0,260);
strcpy(m_user,g_user);
::SendMessage(hwnd,WM_SETTEXT,260,(LPARAM)(char*)m_user);
::SetForegroundWindow(hwnd);
::SendMessage(hwnd,WM_SETFOCUS,NULL,NULL);
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
keybd_event(VK_RETURN,
NULL,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
PostQuitMessage(0);
}
counter++;
}
return TRUE;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
CString sWindowText;
GetWindowText(hwnd, sWindowText.GetBuffer(256), 256);
sWindowText.ReleaseBuffer();
if(sWindowText.Left(2)=="IP")
// if (sWindowText.Find(_T("IP出校设置器")) != -1)
{
m_bFlag=FALSE;
::EnumChildWindows(hwnd, EnumChildProc, 0);
}
return TRUE;
}
#10
HWND hwnd = ::GetFocus();
char ch[]="0123456789";
for (i = 0 ;i<10 ; i++)
::PostMessage (hwnd, WM_CHAR, (WPARAM)chqq[i], 0);//发送字符
::PostMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);//发送回车消息
char ch[]="0123456789";
for (i = 0 ;i<10 ; i++)
::PostMessage (hwnd, WM_CHAR, (WPARAM)chqq[i], 0);//发送字符
::PostMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);//发送回车消息
#11
GetFocus不行吧,我不是在同一个程序中,我是向另一个程序的一个文本框发送,该怎么获得这个文本框的句柄呢?
#12
To richie_cn(追风无影剑) :
HWND hWnd=::GetForegroundWindow();
HWND hEdit=::GetFocus();
char ch[]="0123456789";
for (int i = 0 ;i<10 ; i++)
::PostMessage (hEdit, WM_CHAR, (WPARAM)ch[i], 0);//·¢ËÍ×Ö·û
::SetWindowText(hWnd,"Test");
//程序的标题可以被更改,但是程序中的文本框还是没有输入字符,怎么回事?
HWND hWnd=::GetForegroundWindow();
HWND hEdit=::GetFocus();
char ch[]="0123456789";
for (int i = 0 ;i<10 ; i++)
::PostMessage (hEdit, WM_CHAR, (WPARAM)ch[i], 0);//·¢ËÍ×Ö·û
::SetWindowText(hWnd,"Test");
//程序的标题可以被更改,但是程序中的文本框还是没有输入字符,怎么回事?
#13
hFwnd是父窗口句柄
hChild是子窗口句柄(控件)
hFwnd::=findWindow(classname,caption);//找父窗口句柄
hChild=::FindWindowFromPoint(hFwnd.....);//找子窗口句柄
::SendMessage(hChild,WM_CHAR,(WPARAM)chqq[i], 0);//发送字符
hChild是子窗口句柄(控件)
hFwnd::=findWindow(classname,caption);//找父窗口句柄
hChild=::FindWindowFromPoint(hFwnd.....);//找子窗口句柄
::SendMessage(hChild,WM_CHAR,(WPARAM)chqq[i], 0);//发送字符
#14
有这个函数吗?FindWindowFromPoint
我MSDN找不到?
我MSDN找不到?
#15
如何得到已经有焦点的这个文本框的句柄?
#16
BOOL EnumChildWindows(
HWND hWndParent, // handle to parent window
WNDENUMPROC lpEnumFunc, // callback function
LPARAM lParam // application-defined value
);
HWND hWndParent, // handle to parent window
WNDENUMPROC lpEnumFunc, // callback function
LPARAM lParam // application-defined value
);
#17
学习!
#18
鼠标钩子(WH_MOUSE Hook),取得鼠标下方子窗体的HANDLE.
不过写钩子程序挺麻烦,得写个dll文件
不过写钩子程序挺麻烦,得写个dll文件
#19
我晕~~~~人家问的这么简单的问题,竟然弄出这么多内容来!!!
HWND hWnd = ::FindWindow("TFormMain","Window name"); //查找目标窗口句柄
HWND eWnd = ::FindWindowEx(hWnd,NULL,"TEdit",""); //查找目标窗口的Edit控件句柄
::SendMessage(eWnd,WM_SETTEXT,0,(LPARAM)IP.GetBuffer(IP.GetLength())); //向目标的Edit控件发送文本
::PostMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);//向目标的Edit控件发送回车键消息!
HWND hWnd = ::FindWindow("TFormMain","Window name"); //查找目标窗口句柄
HWND eWnd = ::FindWindowEx(hWnd,NULL,"TEdit",""); //查找目标窗口的Edit控件句柄
::SendMessage(eWnd,WM_SETTEXT,0,(LPARAM)IP.GetBuffer(IP.GetLength())); //向目标的Edit控件发送文本
::PostMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);//向目标的Edit控件发送回车键消息!
#20
如果TEXT窗体由焦点的话,没必要钩子
用
HWND WindowFromPoint(
POINT Point // point
);
用
HWND WindowFromPoint(
POINT Point // point
);
#21
如果是IE中的文本框怎么办? 不是一个窗口?如何在IE中的两个文本框中移动输入焦点?