2016-11-07 7 views
1

필자가 작성한 코드에 문제가 있습니다. 나는 직원 정보를 열거하는 테이블을 가지고있다. 레코드를 선택하고 마우스 오른쪽 버튼을 클릭 할 때 클립 보드에 전자 메일 주소 복사본이 있으려고합니다. 나는 다음과 같은 코드가 있습니다 :문이 작동하지 않는 경우 AutoIT

#include <GUIConstantsEx.au3> 
#include <mssql.au3> 
#include <MsgBoxConstants.au3> 
#include <Array.au3> 
#include <WindowsConstants.au3> 
#include <AutoItConstants.au3> 
global $title = "E-Mail address lookup" 
global $name = InputBox($title,"Please type the name of the person you wish to find") 
global $sqlCon = _MSSQL_Con("server", "username", "password", "directory-plus") 
global $result = _MSSQL_GetRecord($sqlCon, "autoit_view","*", "WHERE cn LIKE '%" & StringStripWS($name,3) & "%'") 
if StringLen(StringStripWS($name,3)) < 1 then 
MsgBox(0, $title, "Name cannot be empty") 
Else 
Global $rset = UBound($result) - 1 
Global $ControlID = GUICreate($title, 500, 150) 
Global $idListview = GUICtrlCreateListView("Deparment|E-Mail Address|Name|Telephone Number", 10, 10, 480, 150) 
for $count = 1 to $rset step 1 
     GUICtrlCreateListViewItem($result[$count][0] & "|" & $result[$count][2] & "|" & $result[$count][1] & "|" & $result[$count][2], $idListview) 
     if MouseClick($MOUSE_CLICK_RIGHT)==1 Then 
      ClipPut($result[$count][2]) 
     EndIf 
Next 
GUISetState(@SW_SHOW) 
GUISetState() 

While 1 
Global $Msg = GUIGetMsg() 
Switch $Msg 
    Case -3, $ControlID 
     Exit 
EndSwitch 
WEnd 
EndIf 

나는 내 내 IF 문을 생각했을 트릭하지만를 할 것 루프에 대한 내 코드를 실행하면, 마지막 행했을 때의 이메일 주소 열에서 무엇이든 그것을 단지 복사 특정 행을 마우스 오른쪽 버튼으로 클릭 할 때 전자 메일 주소를 복사하려고하지만 실제로 수행 할 방법을 모르겠습니다.

답변

1

코드에 두 가지 주요한 문제가 있습니다. 첫 번째는 MouseClick()이 마우스 버튼이 눌러 졌는지 확인하지 않고 대신 마우스 버튼을 클릭한다는 것입니다. 마우스 버튼의 클릭이 성공하기 때문에 MouseClick ($ MOUSE_CLICK_RIGHT) == 1은 true로 평가됩니다. 작성한 각 목록보기 항목에 대해 이메일 주소를 클립 보드에 넣습니다.

두 번째 문제는 if 문이 잘못된 위치에 있다는 것입니다. 각 목록보기 항목을 만든 직후에 실행됩니다.

는 대신, 동안 문을 변경하려면 다음과 로

While 1 
Global $Msg = GUIGetMsg() 
Switch $Msg 
    Case -3, $ControlID 
    Exit 
    case $GUI_EVENT_SECONDARYDOWN 
    $selecteditem=StringSplit(GUICtrlRead(GUICtrlRead($idListview)),"|") 
    if @error=0 and $selecteditem[0]>1 Then 
    ClipPut($selecteditem[2]) 
    EndIf 
EndSwitch 
WEnd 
관련 문제