edit1:=CreateWindowEx(0,'edit','asds',ws_Child or ws_Visible or
                        ws_Border or bs_PushButton,
                        0,0,160,30,hWnd,id_edit1,hInstance,nil);SetWindowPos(GetDlgItem(hWnd,id_edit1),0,Rect.Right div 2-250,
                 Rect.Bottom -200,0,0,swp_NoZOrder or swp_NoSize);
这样创建后,请问该如何对其进行读写?

解决方案 »

  1.   

    edit1:=CreateWindowEx(0,'edit','asds',ws_Child or ws_Visible or
                            ws_Border or bs_PushButton,
                            0,0,160,30,hWnd,id_edit1,hInstance,nil);SetWindowPos(GetDlgItem(hWnd,id_edit1),0,Rect.Right div 2-250,
                     Rect.Bottom -200,0,0,swp_NoZOrder or swp_NoSize);
    .//SendMessage(Edit1,WM_SetText,0,Integer(pchar('this is Edit')));
      

  2.   

    上面給的是寫,
    讀換成  WM_GetText
      

  3.   


    wm_Command:           
     begin
      case LoWord(wParam) of
        id_Button3:         
          begin
           if HiWord(wParam)=bn_Clicked then
                SendMessage(edit2,WM_SetText,0,Integer(pchar('this is Edit')));
         end;
    我是用BUTTON按键触发 EDIT显示 ,但是无法显示,getlasterror 返回值为 1400 无效的窗口句柄。edit2 我是用 THandle 定义的,不知道哪里出了问题?
      

  4.   

    只要有handle,就可以实现你要的功能。而且生成的EXE极小。
      

  5.   


    把代碼貼全點。除非你的  Edit2 == 0 ??至於多行可以通過  SetwindowLong  來設置
      

  6.   


    function PlainWinProc(hWnd:THandle; nMsg:UINT;
      wParam,lParam:Cardinal):Cardinal;export;stdcall;
    var
      Rect:TRect;
      edit1,edit2,edit3:THandle;
    begin
      result:=0;  case nMsg of
        wm_Create:
         begin
          CreateWindowEx(0,'Button','&HELLO',ws_Child or ws_Visible or
                            ws_Border or bs_PushButton,
                            0,0,80,30,hWnd,id_Button1,hInstance,nil);
          CreateWindowEx(0,'Button','&退出',ws_Child or ws_Visible or
                            ws_Border or bs_PushButton,
                            0,0,80,30,hWnd,id_Button2,hInstance,nil);
          CreateWindowEx(0,'Button','&安装服务',ws_Child or ws_Visible or
                            ws_Border or bs_PushButton,
                            0,0,80,30,hWnd,id_Button3,hInstance,nil);
          CreateWindowEx(0,'Button','&启动服务',ws_Child or ws_Visible or
                            ws_Border or bs_PushButton,
                            0,0,80,30,hWnd,id_Button4,hInstance,nil);
          CreateWindowEx(0,'Button','&停止服务',ws_Child or ws_Visible or
                           ws_Border or bs_PushButton,
                            0,0,80,30,hWnd,id_Button5,hInstance,nil);
          CreateWindowEx(0,'Button','&卸载服务',ws_Child or ws_Visible or
                            ws_Border or bs_PushButton,
                            0,0,80,30,hWnd,id_Button6,hInstance,nil);
          CreateWindowEx(0,'Button','&发送消息',ws_Child or ws_Visible or
                            ws_Border or bs_PushButton,
                            0,0,80,30,hWnd,id_Button7,hInstance,nil);
          edit1:=CreateWindowEx(0,'edit','1',ws_Child or ws_Visible or
                            ws_Border ,
                            0,0,30,30,hWnd,id_edit1,hInstance,nil);
          edit2:=CreateWindowEx(0,'edit','',ws_Child or ws_Visible or
                            ws_Border ,
                            0,0,160,30,hWnd,id_edit2,hInstance,nil);
          edit3:=CreateWindowEx(0,'edit','',ws_Child or ws_Visible or
                            ws_Border ,
                            0,0,160,300,hWnd,id_edit3,hInstance,nil);
         end;
        wm_Size:
         begin
          GetClientRect(hWnd,Rect);
          SetWindowPos(GetDlgItem(hWnd,id_Button1),0,Rect.Right div 2-300,
                     Rect.Bottom div 2-50,0,0,swp_NoZOrder or swp_NoSize);
          SetWindowPos(GetDlgItem(hWnd,id_Button2),0,Rect.Right div 2-200,
                     Rect.Bottom div 2-50,0,0,swp_NoZOrder or swp_NoSize);
          SetWindowPos(GetDlgItem(hWnd,id_Button3),0,Rect.Right div 2-300,
                     Rect.Bottom div 2-10,0,0,swp_NoZOrder or swp_NoSize);
          SetWindowPos(GetDlgItem(hWnd,id_Button4),0,Rect.Right div 2-200,
                     Rect.Bottom div 2-10,0,0,swp_NoZOrder or swp_NoSize);
          SetWindowPos(GetDlgItem(hWnd,id_Button5),0,Rect.Right div 2-100,
                     Rect.Bottom div 2-10,0,0,swp_NoZOrder or swp_NoSize);
          SetWindowPos(GetDlgItem(hWnd,id_Button6),0,Rect.Right div 2-100,
                     Rect.Bottom div 2-50,0,0,swp_NoZOrder or swp_NoSize);
          SetWindowPos(GetDlgItem(hWnd,id_Button7),0,Rect.Right div 2-200,
                     Rect.Bottom - 150,0,0,swp_NoZOrder or swp_NoSize);
          SetWindowPos(GetDlgItem(hWnd,id_edit1),0,Rect.Right div 2-300,
                     Rect.Bottom -200,0,0,swp_NoZOrder or swp_NoSize);
          SetWindowPos(GetDlgItem(hWnd,id_edit2),0,Rect.Right div 2-250,
                     Rect.Bottom -200,0,0,swp_NoZOrder or swp_NoSize);
          SetWindowPos(GetDlgItem(hWnd,id_edit3),0,Rect.Right -300,
                     Rect.Bottom div 2-200,0,0,swp_NoZOrder or swp_NoSize);
         end;    wm_Command:           
        begin        case    LoWord(wParam) of
                 id_Button1:
                        begin
                            if HiWord(wParam)=bn_Clicked then
                               MessageBox(hWnd,'OK','Demo',MB_OK);
                        end;
                 id_Button2:
                        begin
                            if HiWord(wParam)=bn_Clicked then
                             Halt;
                        end;
                 id_Button3:            //安装
                        begin
                            if HiWord(wParam)=bn_Clicked then
                               ShellExecute(hWnd, 'open','DemoSrv.exe','/install','', SW_SHOWNORMAL);
                            SendMessage(edit2,WM_SetText,0,Integer(pchar('安装服务...')));
                             showmessage(inttostr(getlasterror()));
                        end;
                 id_Button4:            //启动
                        begin
                            if HiWord(wParam)=bn_Clicked then
                                StartClick;
                        end;
                 id_Button5:            //停止
                        begin
                            if HiWord(wParam)=bn_Clicked then
                                StopClick;
                        end;
                 id_Button6:            //卸载
                        begin
                            if HiWord(wParam)=bn_Clicked then
                                ShellExecute(hWnd, 'open','DemoSrv.exe','/remove','', SW_SHOWNORMAL);
                        end;
                 id_Button7:            //消息
                        begin
                            if HiWord(wParam)=bn_Clicked then
                                PipeInstanceProc ;
                        end;
               end;
        end;    wm_DropFiles:
          begin
            MessageBox(hWnd,'Drop File','Plain API',MB_OK);
            DragFinish(wParam);
          end;    wm_Destroy:
             PostQuitMessage(0);
        else
          result:=DefWindowProc(hWnd,nMsg,wParam,lParam);
      end;
    end;
      

  7.   

    可以了  edit句柄应该定义为全局变量,多谢 starluck  !还有 SetwindowLong  可否给个简单的样例?
      

  8.   

    可以了  edit句柄应该定义为全局变量,多谢 starluck  ! 还有 SetwindowLong  可否给个简单的样例?