SendMessage(hWnd,WM_SETTEXT,...)中的WM_SETTEXT怎么用?

eaststar 2001-07-31 10:17:52
...全文
1465 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ExitWindows 2001-08-01
  • 打赏
  • 举报
回复
up
ZHENG017 2001-07-31
  • 打赏
  • 举报
回复
SendMessage(hWnd,WM_CHAR,...)好点。
seedundersnow 2001-07-31
  • 打赏
  • 举报
回复

接收消息的窗口需要一个指针来定位这个string,于是就在SendMessage()的时候传给它

eaststar 2001-07-31
  • 打赏
  • 举报
回复
WM_SETTEXT
wParam = 0; // not used; must be zero
lParam = (LPARAM)(LPCTSTR)lpsz; // address of window-text string

是什么意思?自己的LPCTSTR怎么定义给WM_SETTEXT
eaststar 2001-07-31
  • 打赏
  • 举报
回复
我看了,还是不明白,请赐教!
flypuma 2001-07-31
  • 打赏
  • 举报
回复
什么意思?WParam,LParam怎么设置吗? 看help啊
ExitWindows 2001-07-31
  • 打赏
  • 举报
回复
up
ExitWindows 2001-07-31
  • 打赏
  • 举报
回复
up
kimryo 2001-07-31
  • 打赏
  • 举报
回复
char* buf="12345";
SendMessage(hwnd,WM_SETTEXT,0,(long)buf);
flypuma 2001-07-31
  • 打赏
  • 举报
回复
这个消息是用来设置窗口的标题Title的(如果是Edit或其他的,则含义有些不同),

char str[100];
sprintf(str,"%s,"Window Title"");
SendMessage(hWnd,WM_CHAR,0, (LPARAM)(LPCTSTR)(str));
ExitWindows 2001-07-31
  • 打赏
  • 举报
回复
up
对日常债务进行数据库操作 .586 .model flat,stdcall option casemap:none include pay.inc include p_Func.asm include p_const.asm include p_struct.asm include p_data.asm include macro.mac .data hInstance HINSTANCE ? CommandLine LPSTR ? hParent dword ? hCursor dword ? hconn_g dword ? henv_g dword ? hstmt_g dword ? dwCount_g dword ? bFlag_g dword ? pPayForData_g PAYFORDATA <> pConfigData CONFIGDATA <> .code include p_code.asm include p_db.asm include p_Dialog.asm include p_ListView.asm include P_ini.asm include p_html.asm ; --------------------------------------------------------------------------- start: invoke GetModuleHandle, NULL mov hInstance,eax invoke DialogBoxParam,hInstance,addr LoginDlgName,0,addr LoginDialog,NULL .if bFlag_g invoke GetCommandLine mov CommandLine,eax invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT .endif invoke ExitProcess,eax WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD LOCAL wc:WNDCLASSEX LOCAL msg:MSG LOCAL hwnd:HWND LOCAL hMenu:HWND LOCAL hAccelerator:HWND mov wc.cbSize,SIZEOF WNDCLASSEX mov wc.style, CS_HREDRAW or CS_VREDRAW mov wc.lpfnWndProc, OFFSET WndProc mov wc.cbClsExtra,NULL mov wc.cbWndExtra,NULL push hInstance pop wc.hInstance mov wc.hbrBackground,COLOR_BTNFACE+1 mov wc.lpszMenuName,offset MenuName mov wc.lpszClassName,OFFSET ClassName invoke LoadIcon,NULL,IDI_MAIN_ICON mov wc.hIcon,eax mov wc.hIconSm,eax mov hMainIco,eax invoke LoadMenu,hInstance,IDR_MENU mov hMenu,eax invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax invoke LoadCursor,hInstance,IDI_HANDLE_ICON mov hCursor,eax invoke LoadAccelerators,hInstance,IDA_ACCELERATOR mov hAccelerator,eax invoke RegisterClassEx, addr wc INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\ WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\ CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,hMenu,\ hInst,NULL mov hwnd,eax mov hParent,eax invoke ShowWindow, hwnd,SW_SHOWNORMAL invoke UpdateWindow, hwnd .WHILE TRUE invoke GetMessage, ADDR msg,NULL,0,0 .BREAK .IF (!eax) invoke TranslateAccelerator,hwnd,hAccelerator,addr msg .if eax == 0 invoke TranslateMessage, ADDR msg invoke DispatchMessage, ADDR msg .endif .ENDW mov eax,msg.wParam ret WinMain endp WndProc proc uses ebx hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM local @stFont:LOGFONT,@hFont:DWORD LOCAL @dwColor:dword .IF uMsg==WM_DESTROY invoke KillTimer,hWnd,IDC_TIMER_STATUSBAR invoke PostQuitMessage,NULL .elseif uMsg==WM_TIMER .if wParam==IDC_TIMER_STATUSBAR invoke _PrintMsg_3 .endif .ELSEIF uMsg==WM_CREATE invoke SetTimer,hWnd,IDC_TIMER_STATUSBAR ,1000,NULL invoke LoadIcon,hInstance,IDI_MAIN_ICON invoke SendMessage, hWnd, WM_SETICON, ICON_BIG,eax ;control invoke _DoToolBar,hInstance,hWnd,IDC_MAIN_TB mov hToolBar,eax ;invoke _DoEdit,hInstance,hToolBar,IDC_MAIN_EDIT ;mov hEdit,eax ;invoke _DoButton,hInstance,hToolBar,IDC_MAIN_BUTTON,_T("搜索") ;mov hButton,eax ;LABEL invoke _DoLabel,hInstance,hToolBar,IDC_BTN_LABEL_3,200,3,150,20 invoke SetDlgItemText,hToolBar,IDC_BTN_LABEL_3,_T("当前用户:") invoke _DoLabel,hInstance,hToolBar,IDC_BTN_LABEL_NAME,270,3,150,20 invoke _DoLabel,hInstance,hToolBar,IDC_BTN_LABEL_1,340,3,150,20 invoke SetDlgItemText,hToolBar,IDC_BTN_LABEL_1,_T("借入:") invoke _DoLabel,hInstance,hToolBar,IDC_BTN_LABEL_IN,380,3,150,20 invoke _DoLabel,hInstance,hToolBar,IDC_BTN_LABEL_2,480,3,150,20 invoke SetDlgItemText,hToolBar,IDC_BTN_LABEL_2,_T("借出:") invoke _DoLabel,hInstance,hToolBar,IDC_BTN_LABEL_OUT,520,3,150,20 invoke _DoStatusBar,hInstance,hWnd,IDC_MAIN_SB mov hStatusBar,eax invoke _DoListView,hInstance,hWnd,IDC_MAIN_LSV mov hListView ,eax invoke _InsertColumnToMainListV,hListView invoke _DoPopupMainMenu, hInstance,hWnd mov hPopupMainMenu,eax invoke _InitConfig,hWnd .elseif uMsg==WM_NOTIFY push edi mov edi, lParam mov eax, [edi.NMHDR].hwndFrom .if eax==hListView .if [edi.NMHDR].code==NM_DBLCLK ;双击 .elseif [edi.NMHDR].code==NM_CLICK ;单击 invoke _GetCurrentFocus,hListView,addr pPayForData_g .elseif [edi.NMHDR].code==NM_RCLICK ;右击 invoke _GetCurrentFocus,hListView,addr pPayForData_g invoke _ShowPopupMainMenu,hWnd,hPopupMainMenu .endif .endif pop edi .elseif uMsg==WM_COMMAND .if lParam !=0 ;工具栏 LOWORD wParam .if eax==IDC_TBB_NEW invoke DialogBoxParam,hInstance,addr NewDlgName,hWnd,addr IddNewDialog,NULL .elseif eax==IDC_TBB_SEE invoke DialogBoxParam,hInstance,addr SeeDlgName,hWnd,addr SeeDialog,NULL .elseif eax==IDC_TBB_PRINT invoke _Print_Html,hWnd .elseif eax==IDC_TBB_HELP invoke DialogBoxParam,hInstance,addr AboutDlgName,hWnd,addr AboutDialog,NULL .elseif eax==IDC_TBB_EXIT invoke SendMessage,hWnd,WM_CLOSE,0,0 .endif .elseif lParam ==0 HIWORD wParam .if eax==0 ;菜单栏 mov eax,wParam .if ax==IDM_NEW invoke DialogBoxParam,hInstance,addr NewDlgName,hWnd,addr IddNewDialog,NULL invoke _RefreshMTData,hWnd,hListView .elseif ax==IDM_SEE invoke DialogBoxParam,hInstance,addr SeeDlgName,hWnd,addr SeeDialog,NULL .elseif ax==IDM_PRINT invoke _Print_Html,hWnd .elseif ax==IDM_CALC invoke _OpenProgramExeFile,hWnd,addr SZCALC,NULL .elseif ax==IDM_HELP invoke DialogBoxParam,hInstance,addr AboutDlgName,hWnd,addr AboutDialog,NULL .elseif ax==IDM_PWD invoke DialogBoxParam,hInstance,addr PwdDlgName,hWnd,addr PwdDialog,NULL .elseif ax==IDM_REFRESH invoke _RefreshMTData,hWnd,hListView .elseif ax==IDM_DEMO invoke DialogBoxParam,hInstance,addr DemoDlgName,hWnd,addr DemoDialog,NULL .elseif ax==IDM_CAL invoke _PromptMsg,_T("建设...") .endif .elseif eax==1 ;快捷键 .endif .endif .elseif uMsg ==WM_SIZE .if wParam!=SIZE_MINIMIZED invoke SendMessage,hStatusBar,uMsg,wParam,lParam invoke SendMessage,hToolBar,uMsg,wParam,lParam mov eax,lParam mov edx,eax and eax,0ffffh shr edx,16 sub edx,46 invoke MoveWindow,hListView, 0, 28, eax,edx,TRUE mov eax,lParam and eax,0ffffh mov ebx,eax sub eax,210 sub ebx,55 invoke MoveWindow,hEdit, eax, 3,150,20,TRUE invoke MoveWindow,hButton,ebx, 3,50,20,TRUE .endif .elseif uMsg==WM_SIZING LimitWindowWidth 455 LimitWindowHeight 455 .ELSE invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .ENDIF xor eax,eax ret WndProc endp _RefreshMTData proc hWnd:dword,hOwner:dword pushad ;连接数据库 invoke DBConnect,hWnd .if eax invoke _PrintMsg_1,_T("数据库连接成功!") .endif ;显示数据 invoke SQLExecDirect,hstmt_g,addr SHOW_ALL_RECODE_MT,sizeof SHOW_ALL_RECODE_MT .if ax==SQL_SUCCESS || ax==SQL_SUCCESS_WITH_INFO ;73570000h invoke _ReadMTToMainListV,hOwner,hstmt_g mov dwCount_g,eax invoke _PrintMsg_2,dwCount_g,_T(" ") invoke _PrintMsg_1,_T("加载成功!") .endif invoke DisDBConnect,hWnd .if eax invoke _PrintMsg_1,_T("断开与数据库的连接!") .endif popad ret _RefreshMTData endp _RefreshOPData proc hWnd:dword,hOwner:dword LOCAL @nCount:dword pushad ;连接数据库 invoke DBConnect,hWnd .if eax invoke _PrintMsg_1,_T("数据库连接成功!") .endif ;显示数据 invoke SQLExecDirect,hstmt_g,addr SHOW_ALL_RECODE_OP,sizeof SHOW_ALL_RECODE_OP .if ax==SQL_SUCCESS || ax==SQL_SUCCESS_WITH_INFO ;73570000h invoke _ReadOPToSeeListV,hOwner,hstmt_g mov @nCount,eax invoke _SetGroupText,hWnd,@nCount invoke _PrintMsg_1,_T("加载成功!") .endif invoke DisDBConnect,hWnd .if eax invoke _PrintMsg_1,_T("断开与数据库的连接!") .endif popad ret _RefreshOPData endp _InitConfig proc hWnd:dword LOCAL @Buff[MAX_PATH]:byte pushad invoke _RefreshMTData,hWnd,hListView invoke SetDlgItemText,hToolBar,IDC_BTN_LABEL_NAME,addr pConfigData.szName invoke _CalcMTPayForRecord,hWnd,addr pConfigData.szName,FALSE mov dwMoneyIn,eax invoke wsprintf,addr @Buff,addr szMoney,dwMoneyIn invoke SetDlgItemText,hToolBar,IDC_BTN_LABEL_IN,addr @Buff invoke _CalcMTPayForRecord,hWnd,addr pConfigData.szName,TRUE mov dwMoneyOut,eax invoke wsprintf,addr @Buff,addr szMoney,dwMoneyOut invoke SetDlgItemText,hToolBar,IDC_BTN_LABEL_OUT,addr @Buff ;TITLE invoke RtlZeroMemory,addr @Buff,sizeof @Buff invoke lstrcpy,addr @Buff,addr pConfigData.szAppName invoke lstrcat,addr @Buff,_T(" -- ") invoke lstrcat,addr @Buff,addr pConfigData.szName invoke SendMessage,hWnd,WM_SETTEXT,0,addr @Buff popad ret _InitConfig endp end start
模拟键盘鼠标操作飞信界面发送短信 private void SendSMS() { #if DEBUG string[] addr = new string[] { "闻佃来"}; #else string[] addr = new string[] { "张三", "李四"}; #endif string message = " "; if (message == "") return; Rectangle rect = new Rectangle(); Windows wins = new Windows(); IntPtr hwin = IntPtr.Zero; foreach (Window w in wins) { if (w.Title.IndexOf("发短信") >= 0) { hwin = w.hWnd; break; } } //未找到发送窗口,点击主窗口下的短信发送按钮 if (hwin == IntPtr.Zero) { wins = new Windows(); foreach (Window w in wins) { if (w.Title.IndexOf("飞信2013") >= 0) { //唤醒屏保 Win32.SetCursorPos(10,10); Win32.mouse_event(Win32.MOUSEEVENTF_MOVE, 50, 50, 0, 0); Thread.Sleep(1500); Win32.ShowWindow(w.hWnd, Win32.SW_SHOWNORMAL); Win32.SetForegroundWindow(hwin); Win32.GetWindowRect(w.hWnd, ref rect); IntPtr hDesk = Win32.GetDesktopWindow(); Rectangle rdesk = new Rectangle(); Win32.GetWindowRect(hDesk,ref rdesk); if (rect.Y < 0) { //上 Win32.SetCursorPos(rect.X +(rect.Width-rect.X)/2,0); Win32.mouse_event(Win32.MOUSEEVENTF_MOVE, 0, 1, 0, 0); Thread.Sleep(1500); Win32.GetWindowRect(w.hWnd, ref rect); } else if (rect.Y >= rdesk.Height - 3) { //下 Win32.SetCursorPos(rect.X + (rect.Width - rect.X) / 2,rdesk.Height); Win32.mouse_event(Win32.MOUSEEVENTF_MOVE, 0, -1, 0, 0); Thread.Sleep(1500); Win32.GetWindowRect(w.hWnd, ref rect); } else if (rect.X <= 0) { //左边 Win32.SetCursorPos(0, rect.Y + (rect.Height - rect.Y) / 2); Thread.Sleep(2000); Win32.mouse_event(Win32.MOUSEEVENTF_MOVE, 1, 0, 0, 0); Thread.Sleep(1500); Win32.GetWindowRect(w.hWnd, ref rect); } else if (rect.X >= rdesk.Width - 3) { //右边 Win32.SetCursorPos(rdesk.Width, rect.Y + (rect.Height - rect.Y) / 2); Thread.Sleep(2000); Win32.mouse_event(Win32.MOUSEEVENTF_MOVE, -1, 0, 0, 0); Thread.Sleep(1500); Win32.GetWindowRect(w.hWnd, ref rect); }else { Win32.MoveWindow(w.hWnd, rect.Left, 0, rect.Width - rect.Left, rect.Height - rect.Top, true); Win32.GetWindowRect(w.hWnd, ref rect); Thread.Sleep(300); } Win32.SetCursorPos(rect.X+70,rect.Height-50); Win32.mouse_event(Win32.MOUSEEVENTF_LEFTDOWN | Win32.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); Thread.Sleep(2000); break; } } //再次查找发送窗口 wins = new Windows(); foreach (Window w in wins) { if (w.Title.IndexOf("发短信") >= 0) { hwin = w.hWnd; break; } } } //查询发送窗口成功 if (hwin != IntPtr.Zero) { Win32.ShowWindow(hwin, Win32.SW_SHOWNORMAL); Win32.SetForegroundWindow(hwin); Win32.GetWindowRect(hwin, ref rect); IntPtr hwndtel = Win32.WindowFromPoint(rect.Left + 120, rect.Top + 45); IntPtr hwndsend = Win32.WindowFromPoint(rect.Left + 50, rect.Height - 60); //单击地址栏 Win32.SetCursorPos(rect.Left + 120, rect.Top + 45); Win32.mouse_event(Win32.MOUSEEVENTF_LEFTDOWN | Win32.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); Thread.Sleep(1000); //加入地址 for (int i = 0; i < addr.Length; i++) { Clipboard.SetText(addr[i]); Thread.Sleep(200); Win32.SendMessage(hwndtel, Win32.WM_PASTE, 0, 0); Thread.Sleep(300); Win32.SendMessage(hwndtel, Win32.WM_KEYDOWN, 0X0D, 0);//发 Win32.SendMessage(hwndtel, Win32.WM_KEYUP, 0X0D, 0); //送 Win32.SendMessage(hwndtel, Win32.WM_CHAR, 0X0D, 0); //回车 Thread.Sleep(300); } //加入消息文本 Clipboard.SetText(message); Thread.Sleep(200); Win32.SendMessage(hwndsend, Win32.WM_PASTE, 0, 0); Thread.Sleep(200); #if DEBUG #else if (!_TestMode) { Win32.SendMessage(hwndsend, Win32.WM_KEYDOWN, 0X0D, 0); Win32.SendMessage(hwndsend, Win32.WM_KEYUP, 0X0D, 0); Win32.SendMessage(hwndsend, Win32.WM_CHAR, 0X0D, 0); } #endif textBox1.AppendText("---------------------------------------- \n"); textBox1.AppendText(DateTime.Now + ":"+ message + "\n"); } else { textBox1.AppendText("无法打开飞信短信发送窗口\n"); } _LastSend = DateTime.Now; LastSendTime = _LastSend; }
作者: 三角猫 出处: http://www.zu14.cn/ 版权归 三角猫 和 真有意思网 所有,转载请注明出处 using System; using System.Collections.Generic; using System.Text; namespace QQAutoMsg { /// /// 消息发送 /// internal static class QQMsgSender { /// /// 发送消息 /// /// 所以已打开的QQ窗体的列表 /// 消息内容 internal static void Go(List qqChatWindows, string msg) { foreach (EnumQQChatWindows.QQChatWindow win in qqChatWindows) { SendMsg(win.WindowHwnd, msg); } } /// /// 根据窗体句柄,找到输入框和发送按钮,发送消息出去 /// /// 聊天窗口句柄 /// 消息内容 private static void SendMsg(IntPtr hWnd, string msg) { if (NativeMethods.IsWindow(hWnd)) //确认该聊天窗口仍然有效 { ////找到 发送 按钮 IntPtr hwndButton = NativeMethods.FindWindowEx(hWnd, IntPtr.Zero, "Button", "发送(S)"); if (IntPtr.Zero != hwndButton) { ////找到窗体顺序上的第一个RichEdit20A控件,其实就是消息显示框 IntPtr hwndRichEdit = NativeMethods.FindWindowEx(hWnd, IntPtr.Zero, "RichEdit20A", null); ////利用spy++,可以看到消息输入框的父窗体是类名为 AfxWnd42 的控件 ////在顺序上是显示框的下一个窗体 if (IntPtr.Zero != hwndRichEdit) { ////找到 AfxWnd42 这个窗体 hwndRichEdit = NativeMethods.GetWindow(hwndRichEdit, NativeMethods.GW_HWNDNEXT); if (IntPtr.Zero != hwndRichEdit) { ////这才是真正的消息输入框 hwndRichEdit = NativeMethods.FindWindowEx(hwndRichEdit, IntPtr.Zero, "RichEdit20A", null); if (hwndRichEdit != IntPtr.Zero) { ////发送消息,因为QQ屏蔽了 WM_SETTEXT, WM_PASTE 命令,所有采用 EM_REPLACESEL 来实现 NativeMethods.SendMessage(hwndRichEdit, NativeMethods.EM_REPLACESEL, IntPtr.Zero, msg); ////给发送按钮发 鼠标单击消息 NativeMethods.SendMessage(hwndButton, NativeMethods.BM_CLICK, IntPtr.Zero, IntPtr.Zero); } } } } } } } }

16,466

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧