Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem selecting external checkbox (LVIF_STATE not defined error)

Status
Not open for further replies.

davidck88

Programmer
Jan 5, 2009
27
NL
Hi all.I want check a checkbox in external window using the following method but i get compile error that LVIF_STATE variable is not defined could an expert show me how LVIF_STATE,LVIS_CHECKED ,LVITEM, LVIS_STATEIMAGEMASK should be defined so they get used by our local LV_ITEM to change the selected item? Looking forward for replies.Thanks

Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long


Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
                ByVal hwnd As Long, _
                ByVal wMsg As Long, _
                ByVal wParam As Long, _
                ByVal lParam As Long) As Long
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
 Const WM_COMMAND = &H111
 Private Const WM_CLOSE As Long = &H10
 Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
 Private Const VK_SPACE = &H20


Private Sub Command1_Click()
Dim x As Long, editx As Long
Dim button As Long


 'Set up our local LV_ITEM to change the selected item
LVITEM.mask = LVIF_STATE
LVITEM.state = LVIS_CHECKED
LVITEM.stateMask = LVIS_STATEIMAGEMASK

 x = FindWindow("#32770", "session")
 If x Then
 'MsgBox "found"
 SendMessage x, LVM_SETITEMSTATE, 1, LVI
 End If

End Sub
 
patrickIRL thanks for your reply. I made some changes but now now i don't get any error but when i click the button the external application that holds checkboxes freeze and crushes!! could you tell me what i am doing wrong here ? the window that holds the checkbox lists has SysListView32 class name i also poste part of c++ code that i was given. I be happy if you help select those checkboxes all at once.Thanks

Note : I was given a c++ part of the code too as shown at the end

Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long


Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
              '  ByVal hwnd As Long, _
              '  ByVal wMsg As Long, _
               ' ByVal wParam As Long, _
               ' ByVal lParam As Long) As Long
  Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
             
               
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
 Const WM_COMMAND = &H111
 Private Const WM_CLOSE As Long = &H10
 Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
 Private Const VK_SPACE = &H20
 '
Private Const LVIS_STATEIMAGEMASK As Long = &HF000
Private Const LVIS_UNCHECKED = &H1000
Private Const LVIS_CHECKED = &H2000
Private Const LVIF_STATE = &H8
Private Const LVM_FIRST = &H1000
Private Const LVM_SETITEMSTATE = (LVM_FIRST + 43)

Private Type LV_ITEM
  Mask As Long
  iItem As Long
  iSubItem As Long
  state As Long
  stateMask As Long
  pszText As String
  cchTextMax As Long
  iImage As Long
  lParam As Long
  iIndent As Long
End Type



Private Sub Command1_Click()
Dim x As Long, editx As Long
Dim button As Long

 Dim LV As LV_ITEM
 Dim Sel As Boolean
 'Set up our local LV_ITEM to change the selected item
 With LV
.Mask = LVIF_STATE
'.state = LVIS_SELECTED
.state = IIf(Sel, LVIS_CHECKED, LVIS_UNCHECKED)
.stateMask = LVIS_STATEIMAGEMASK
End With

 x = FindWindow("#32770", "session")
 If x Then
 'MsgBox "found"
 

  button = FindWindowEx(x, 0&, "SysListView32", vbNullString)
 SendMessage button, LVM_SETITEMSTATE, 1, LV

 End If
End Sub

c++ part of the code:
Code:
HWND hParent =::FindWindow("#32770","session");
            HWND hList = ::FindWindowEx(hParent, 0, "SysListView32", NULL);
            bool bCheck=true;
            int count=(int)::SendMessage(hList, LVM_GETITEMCOUNT, 0, 0);
            LV_ITEM     lvi;
            lvi.state=UINT((int(bCheck) + 1) << 12);
            lvi.stateMask=LVIS_STATEIMAGEMASK;
         
            for(int i=0; i<count; i++)
            {
               WPARAM ItemIndex=(WPARAM)i;
               
               ::SendMessage(hList,LVM_SETITEMSTATE,ItemIndex,(LPARAM)&lvi);
               
            }
            HWND button = ::FindWindowEx(hParent, 0, "button", "Invite");
               ::SendMessage((HWND)button,WM_LBUTTONDOWN,1,1);
              ::SendMessage((HWND)button,WM_LBUTTONUP,1,1);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top