根据两种方法,标题和类名,找出来的句柄都是0
classhwndFather 是父窗口句柄。通过spy_++获得。
用什么正确方法可以获取?strcpy(szTitleFind,"导出对话框");
classhwndMsgbox= FindTitleWnd(classhwndFather, szTitleFind);
printf("classhwndMsgbox:%d\r\n", classhwndMsgbox);
//类名:#32770 (Dialog)
classhwndMsgbox=FindWithClassName(classhwndFather,"#32770");
printf("classhwndMsgbox:%d\r\n", classhwndMsgbox);
HWND FindTitleWnd(HWND ParentWnd,char szTitleFind[512])
{
HWND hChild = ::GetWindow(ParentWnd, GW_CHILD);for(; hChild!=NULL ; hChild=::GetWindow(hChild,GW_HWNDNEXT))
{
//判断是否为需要的控件
//if ( GetDlgCtrlID(hChild) == ControlID )
char szTitle[512];
GetWindowText(hChild, szTitle, 512);
if (strcmp(szTitleFind,szTitle)==0)
return hChild;HWND FindWnd=FindTitleWnd(hChild,szTitleFind);
if (FindWnd)
return FindWnd;
}
return NULL;
} HWND FindWithClassName(HWND ParentWnd,const TCHAR* FindClassName)
{
HWND hChild = ::GetWindow(ParentWnd, GW_CHILD);TCHAR ClassName[100];
for(; hChild!=NULL ; hChild=::GetWindow(hChild,GW_HWNDNEXT))
{
::GetClassName(hChild,ClassName,sizeof(ClassName)/sizeof(TCHAR));if (_tcscmp(ClassName,FindClassName)==0)
return hChild;HWND FindWnd=FindWithClassName(hChild,FindClassName);
if (FindWnd)
return FindWnd;
}
return NULL;
}
classhwndFather 是父窗口句柄。通过spy_++获得。
用什么正确方法可以获取?strcpy(szTitleFind,"导出对话框");
classhwndMsgbox= FindTitleWnd(classhwndFather, szTitleFind);
printf("classhwndMsgbox:%d\r\n", classhwndMsgbox);
//类名:#32770 (Dialog)
classhwndMsgbox=FindWithClassName(classhwndFather,"#32770");
printf("classhwndMsgbox:%d\r\n", classhwndMsgbox);
HWND FindTitleWnd(HWND ParentWnd,char szTitleFind[512])
{
HWND hChild = ::GetWindow(ParentWnd, GW_CHILD);for(; hChild!=NULL ; hChild=::GetWindow(hChild,GW_HWNDNEXT))
{
//判断是否为需要的控件
//if ( GetDlgCtrlID(hChild) == ControlID )
char szTitle[512];
GetWindowText(hChild, szTitle, 512);
if (strcmp(szTitleFind,szTitle)==0)
return hChild;HWND FindWnd=FindTitleWnd(hChild,szTitleFind);
if (FindWnd)
return FindWnd;
}
return NULL;
} HWND FindWithClassName(HWND ParentWnd,const TCHAR* FindClassName)
{
HWND hChild = ::GetWindow(ParentWnd, GW_CHILD);TCHAR ClassName[100];
for(; hChild!=NULL ; hChild=::GetWindow(hChild,GW_HWNDNEXT))
{
::GetClassName(hChild,ClassName,sizeof(ClassName)/sizeof(TCHAR));if (_tcscmp(ClassName,FindClassName)==0)
return hChild;HWND FindWnd=FindWithClassName(hChild,FindClassName);
if (FindWnd)
return FindWnd;
}
return NULL;
}
void CTestDlg::OnFind()
{
float sNum; // TODO: Add your control notification handler code here
pWndDlg=FindWindow("#32770","单溢流原始数据输入对话框");
if(pWndDlg==0)
{
AfxMessageBox("单溢流原始数据输入对话框");
return;
}
pWndEdit1000=pWndDlg->GetDlgItem(0x03E8);// 汽相流量的 ID 0x003E8
// pWndEdit1000->SendMessage(WM_SETFOCUS,0,0);
// pWndEdit1000->SendMessage(EM_SETSEL,0,-1);
// get text
// OK
// CString str;
// pWndEdit1000->GetWindowText(str);
// afxDump << str << "\n";
char txt[40];
pWndEdit1000->SendMessage(WM_COPY,0,0);// COPY汽相流量的数据到剪贴板
GetCBtext(txt);//剪贴板上的数据赋值给 txt[40],取出汽相流量输入框值
//
// sscanf(txt,"%f",&m_Edit);// 字符转变为浮点数
// UpdateData(FALSE); // 显示m_Edit的值
// 下面送入新的值
sNum= m_Edit; //C++程序界面 EDIT 汽相流量输入(第一个输入框)
sNum=sNum * xNum[0][m_iCount];
// 乘上系数, 1.0 --0.1 共10个系数,每按一次"寻找窗口" 按钮,系数改变一次
pWndEdit1000->SendMessage(WM_SETFOCUS,0,0);//汽相流量输入框得到焦点
pWndEdit1000->SendMessage(EM_SETSEL,0,-1); // 选中汽相流量输入框
// sNum=1111.22f;
char text[40];
sprintf(text,"%7.2f",sNum);// 浮点数据变成字符
// not OK !
// afxDump << text << "\n";
// pWndEdit1000->SetWindowText(text);
SetCBtext(text);// 送到剪贴板
pWndEdit1000->SendMessage(WM_PASTE,0,0);//PASTE到fhxnt.exe 程序界面的汽相流量输入框
// 新值已送入到 fhcnt.exe 程序界面的汽相流量输入框
m_iCount++; // " 寻找窗口"一次,计数增1,最多10 次.
if (m_iCount>9) m_iCount=0;
// COPYDATASTRUCT cds;
// pWndEdit1000->SendMessage(WM_COPYDATA,(WPARAM)this->m_hWnd,(LPARAM)&cds);
// pWndEdit1000->SendMessage(WM_COPY,0,0); // pWndEdit1000->PostMessage(WM_KEYDOWN,VK_CONTROL,0x43<<16);
// pWndEdit1000->PostMessage(WM_KEYUP,VK_CONTROL,0x43<<16);
// keybd_event(VK_CONTROL,0x43,0,0);
// keybd_event(VK_CONTROL,0x43,KEYEVENTF_KEYUP,0);
// char editTxt[260]={0};
// int len=pWndEdit1000->SendMessage(EM_GETLINE,0,(LPARAM)editTxt);
// pWndEdit1000->GetWindowText(editTxt,260);
}
这个问题解决了。请问大哥,https://blog.csdn.net/visualeleven/article/details/6403628#commentsedit 你这里有列表框自动点中的代码。我这里要点中的是combobox,请问怎么修改可以实现呢?谢谢。
这个问题解决了。请问大哥,https://blog.csdn.net/visualeleven/article/details/6403628#commentsedit 你这里有列表框自动点中的代码。我这里要点中的是combobox,请问怎么修改可以实现呢?谢谢。
ComboBox_SetCurSel() 找到ComboBox句柄,然后设置一个索引看看,不确定是否有效。