C++怎么用sendmessage发送文本给窗口
C++小白,想用C++写一段自动保存qq另存为文件的代码。以下是代码,如果我只传一个字符到填路径的编辑框,是可以成功的,但是如果传多个字符(最终需要传完整路径),会在另存...
C++小白,想用C++写一段自动保存qq另存为文件的代码。以下是代码,如果我只传一个字符到填路径的编辑框,是可以成功的,但是如果传多个字符(最终需要传完整路径),会在另存为窗口的编辑框显示为乱码。请大神帮助,谢谢。#include "stdafx.h"#include <iostream> #include <ctime> #include <windows.h>#include "string"long getTime();using namespace std;long i_first_time;long getTime() { return clock() / CLOCKS_PER_SEC;}HWND FindWnd(LPCWSTR wName) { HWND L_FWD; L_FWD = ::FindWindow((LPCWSTR)("ThunderDFrame"),wName); // End If if (L_FWD == 0) L_FWD = ::FindWindow(NULL, wName); return L_FWD;}void save_excel(int i_type) { HWND FWnd, BWnd, h1, h2, h3, h4, h5; char *v_path; //LPARAM v_path,aa; if (i_type == 1) v_path = "D:\\mb51.xlsm"; //else //v_path = "C:\Users\Tiny\Desktop" + "\mseg" + Format(Now(), "YYYYMMDDHHMMSS") + ".xlsx" //End If FWnd = FindWnd(TEXT("另存为")); h1 = ::FindWindowEx(FWnd, 0, TEXT("DUIViewWndClassName"), NULL); h2 = ::FindWindowEx(h1,0, TEXT("DirectUIHWND"),NULL); h3 = ::FindWindowEx(h2,0, TEXT("FloatNotifySink"),NULL); h4 = ::FindWindowEx(h3,0, TEXT("ComboBox"), NULL); h5 = ::FindWindowEx(h4,0, TEXT("Edit"), NULL); char* aa = "A\0"; //SendMessage() //发送填写的路径 //SendMessage(h3, WM_SETTEXT, 42, (LPARAM)v_path); long i_temp1=::SendMessage(h5, WM_SETTEXT, 0, LPARAM(aa)); //cout << h5 << endl; cout <<*aa<<endl; cout <<LPARAM(aa)<<endl; cout <<i_temp1<<endl; BWnd = FindWindowEx(h5, 0, TEXT("Button"), TEXT("保存(&S)")); //cout << BWnd << endl; long i_temp2=::SendMessage(BWnd, 17893, 0, 0); //点击保存按键 //SendMessage(h5, BM_CLICK, 0, 0); return;}int main() { long i = 0; //获取第一次的时间 i_first_time = getTime(); long lastTime = 0; //超过15秒自动退出 while (1 && (lastTime - i_first_time < 15)) { long now = getTime(); if (now - lastTime > 2) { //cout << ++i << endl; save_excel(1); lastTime = now; } } return 0;}
展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询