Click here to Skip to main content
15,885,365 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionProblem related to CImageList(explanation) Pin
a_david1236-Sep-05 20:18
a_david1236-Sep-05 20:18 
QuestionHow does CListCtrl notify its parent window when a cell content has changed? Pin
followait6-Sep-05 20:18
followait6-Sep-05 20:18 
AnswerRe: How does CListCtrl notify its parent window when a cell content has changed? Pin
Ian Bowler7-Sep-05 13:39
Ian Bowler7-Sep-05 13:39 
GeneralRe: How does CListCtrl notify its parent window when a cell content has changed? Pin
followait7-Sep-05 16:15
followait7-Sep-05 16:15 
AnswerRe: How does CListCtrl notify its parent window when a cell content has changed? Pin
David Crow8-Sep-05 2:34
David Crow8-Sep-05 2:34 
QuestionSEARCH PATTERN Pin
russel.ak6-Sep-05 19:58
russel.ak6-Sep-05 19:58 
AnswerRe: SEARCH PATTERN Pin
kakan6-Sep-05 21:25
professionalkakan6-Sep-05 21:25 
QuestionCross app SendMessage Pin
ayon1116-Sep-05 19:56
ayon1116-Sep-05 19:56 
Hi,

I have a VB6 application with a listview control in it. I have written an app in VC++ to
get the handle of the ListView control of the VB6 app.Then I used Jeff Ritcher's suggestion
from http://www.microsoft.com/msj/0997/win320997.aspx and according read the items from the
listview.Then I have to select the item. The problem comes here.When I select an item in the
listview, it gets selected ,but the previously selected item is still hilighted.The multiple
selection property of the listview is set to false.I have also tried to deselct the items.But
it didnot work.I am pasting the code below:

void CListtestDlg::OnButton1()
{


CString str1,str2,str3,str4="Item1";
HWND hWnd=::FindWindow ("ThunderRT6FormDC",NULL);
str1.Format ("%x",hWnd);
//::MessageBox(0,str1,"Handle1",MB_OK);

HWND hWnd1=::FindWindowEx (hWnd,NULL,"ListView20WndClass",NULL);
// HWND hWnd1=::GetWindow (hWnd,GW_CHILD);

HWND hWnd2=::FindWindowEx (hWnd,NULL,"ThunderRT6CommandButton",NULL);
str2.Format ("%x",hWnd2);

//::MessageBox(0,str2,"Handle2",MB_OK);

// BOOL hWnd2=::EnableWindow (hWnd,TRUE);

//int m=::GetDlgCtrlID (hWnd1);
/* if(hWnd2)
{
str3.Format ("%d",hWnd2);
::MessageBox (0,str3,"m",MB_OK);
}
//long c=::SendDlgItemMessage(hWnd,
*/
//::SendMessage(hWnd1,LVN_INSERTITEM,1,5);
TCHAR sz[100];
LV_ITEM lvItem;
//LPTSTR lpText=(LPVOID*)::HeapAlloc (::GetProcessHeap (),0,200);
//int x;
//x=ListView_GetCountPerPage(hWnd1);
// lvItem.mask=LVIF_TEXT;
//lvItem.pszText="Item 100";
// lvItem.iItem=0;
// lvItem.iSubItem=0;
// lvItem.pszText=sz;
//lvItem.cchTextMax= sizeof(sz);


//LRESULT lResult = ::SendMessage(hWnd1, LVM_GETITEM, 0, (LPARAM) &lvItem );

//BOOL b = ListView_GetItem(hWnd1,&lvItem);

TCHAR* szText1=NULL;
TCHAR* szText2=NULL;
TCHAR* szText3=NULL;
TCHAR *szText4=" Item 1";
// int n=ListView_GetItemCount(hWnd1);
// str3.Format ("%d",n);
//::MessageBox (hWnd1,str3,"Item count",MB_OK);


getItemTextFromListBox(hWnd1, 0,0, &szText1);
getItemTextFromListBox(hWnd1, 0,1, &szText2);
getItemTextFromListBox(hWnd1, 1,0, &szText3);
// ListView_SetItemState(hWnd1, -1, 0, LVIS_SELECTED)
//int x=ListView_GetItemState(hWnd1,1,1);
// str3.Format ("%d",x);
//::MessageBox (0,str3,"Value",MB_OK);
// ListView_SetItemState(hWnd1,-1,0,LVIS_SELECTED );
//ListView_SetHotItem(hWnd1,2);
//ListView_RedrawItems(hWnd1,0,2);
if( 0==_tcscmp(szText1,szText4))
{
TRACE("Matched");

//
// ListView_RedrawItems(hWnd1,0,2);
// int dd=ListView_GetSelectedCount(hWnd1);
//if(dd>0)
//{
//::SetFocus (hWnd1);
// ::SetActiveWindow (hWnd1);
//ListView_SetItemState(hWnd1, -1, 0, 0);
//::SendMessage(hWnd1,WM_SETFOCUS,0,0);
::SendMessage(hWnd1,WM_SETFOCUS,0,0);
::SendMessage(hWnd1,LVM_SETITEMSTATE,0,0);
//::SendMessage (hWnd1,LVM_REDRAWITEMS,0,0);
//ListView_SetItemState(hWnd1, -1, 0, (LVIS_FOCUSED) ); // deselect // deselect
// ::SetFocus (hWnd1);
// ListView_RedrawItems(hWnd1,0,2);
//if(!x)
//{
// ListView_SetItemState(hWnd1, -1, 0, LVIS_SELECTED);
//ListView_SetItemState(hWnd1, 1, 0, LVIS_SELECTED );
//}
//if(dd>0)
//{
RECT re;
//ListView_GetViewRect(hWnd1,&re);
//long d=re.left ;
//long e
//BOOL k= ::UpdateWindow (hWnd1);
int x=ListView_GetSelectedCount(hWnd1);
// ListView_SetItemCount
//ListView_SetItemState(hWnd1, 2, LVIS_SELECTED , LVIS_SELECTED );
//}
//:: UpdateWindow(hWnd1);// select iListPos
//ListView_SetItemState(hWnd1, 0, LVIS_FOCUSED , LVIS_FOCUSED );
//::UpdateWindow(hWnd2);
// ListView_Update(hWnd1,1);
//Button_Click(hWnd2);
//::SendMessage(hWnd2,WM_LBUTTONDOWN,0,0);
//::SendMessage(hWnd2,WM_LBUTTONUP,0,0);

}


if(szText1)
delete szText1;
if(szText2)
free(szText2);
if(szText3)
free(szText3);

}

bool
getItemTextFromListBox(HWND hWndListView, int item, int subItem, TCHAR** ppwszText)
{
bool retcode=false;
TCHAR szReadBuffer[1024];
memset(szReadBuffer, 0, sizeof(szReadBuffer) );
LV_ITEM* plvi=NULL;

DWORD dwProcessId;
GetWindowThreadProcessId(hWndListView, &dwProcessId);
// Open a handle to the remote process's kernel object
HANDLE hProcess = OpenProcess(
PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,
FALSE, dwProcessId);

if (hProcess == NULL) {
MessageBox(NULL, __TEXT("Could not communicate with process"),
"ERROR", MB_OK | MB_ICONWARNING);
goto cleanup;
}

// Allocate memory in the remote process's address space
plvi = (LV_ITEM*) VirtualAllocEx(hProcess,
NULL, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

if(plvi==NULL) {
goto cleanup;
}

// Get the ListView item's text data
// Initialize a local LV_ITEM structure
LV_ITEM lvi;
memset(&lvi, 0, sizeof(LV_ITEM) );
lvi.mask = LVIF_TEXT;
lvi.iItem = item;
lvi.iSubItem = subItem;
// NOTE: The text data immediately follows the LV_ITEM structure
// in the memory block allocated in the remote process.
lvi.pszText = (LPTSTR) (plvi + 1);
lvi.cchTextMax = 100;

// Write the local LV_ITEM structure to the remote memory block
if( !WriteProcessMemory(hProcess, plvi, &lvi, sizeof(lvi), NULL) ) {
goto cleanup;
}

// Tell the ListView control to fill the remote LV_ITEM structure
ListView_GetItem(hWndListView, plvi);

// Read the remote text string into the end of our clipboard buffer
if( !ReadProcessMemory(hProcess, plvi + 1, (LPVOID) &szReadBuffer, sizeof(szReadBuffer), NULL) ) {
goto cleanup;
}

*ppwszText = (TCHAR*) malloc( _tcslen( szReadBuffer ) + sizeof(TCHAR) );
if(!*ppwszText) {
goto cleanup;
}

retcode=true;
_tcscpy(*ppwszText, szReadBuffer);

// ListView_SetItemState(hWndListView, -1, 0, LVIS_SELECTED);

cleanup:
// Free the memory in the remote process's address space
if(hProcess) {
VirtualFreeEx(hProcess, plvi, 0, MEM_RELEASE);
// Cleanup and put our results on the clipboard
CloseHandle(hProcess);
}
return retcode;
}


QuestionHow to make a combobox to be flat? Pin
followait6-Sep-05 19:29
followait6-Sep-05 19:29 
AnswerRe: How to make a combobox to be flat? Pin
David Crow7-Sep-05 3:31
David Crow7-Sep-05 3:31 
Generalyes Pin
followait7-Sep-05 16:06
followait7-Sep-05 16:06 
GeneralRe: yes Pin
David Crow8-Sep-05 2:33
David Crow8-Sep-05 2:33 
QuestionHow the watch the url in IE? Pin
redduke6-Sep-05 18:32
redduke6-Sep-05 18:32 
AnswerRe: How the watch the url in IE? Pin
ThatsAlok6-Sep-05 18:52
ThatsAlok6-Sep-05 18:52 
Questiondata communication between applications Pin
Nishad S6-Sep-05 18:15
Nishad S6-Sep-05 18:15 
AnswerRe: data communication between applications Pin
Christian Graus6-Sep-05 18:44
protectorChristian Graus6-Sep-05 18:44 
GeneralRe: data communication between applications Pin
Nishad S6-Sep-05 18:51
Nishad S6-Sep-05 18:51 
AnswerRe: data communication between applications Pin
ThatsAlok6-Sep-05 18:54
ThatsAlok6-Sep-05 18:54 
GeneralRe: data communication between applications Pin
Christian Graus6-Sep-05 19:04
protectorChristian Graus6-Sep-05 19:04 
AnswerRe: data communication between applications Pin
cmk7-Sep-05 2:32
cmk7-Sep-05 2:32 
GeneralRe: data communication between applications Pin
Nishad S7-Sep-05 18:06
Nishad S7-Sep-05 18:06 
GeneralRe: data communication between applications Pin
cmk8-Sep-05 4:18
cmk8-Sep-05 4:18 
QuestionSilent Crash On 2K - Debug Suggestions? Pin
Paul Belikian6-Sep-05 16:56
Paul Belikian6-Sep-05 16:56 
Answer[Msg Deleted] Pin
Christian Graus6-Sep-05 17:10
protectorChristian Graus6-Sep-05 17:10 
AnswerRe: Silent Crash On 2K - Debug Suggestions? Pin
Christian Graus6-Sep-05 17:10
protectorChristian Graus6-Sep-05 17:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.