|
Sorry LB_GETTEXT is not what I want. I want the data/string associated with the item. GETTEXT shows me the text for the string that is already displaying in the listbox.
|
|
|
|
|
OK just replace the LB_GETTEXT like this:
int data = SendMessage(handle_List, LB_GETITEMDATA, (WPARAM)i, 0);
However you do not say what data you are expecting to get returned from the ListBox . In your original sample you cast the returned value to a char* and then complain you always get "?" printed out, so I am assuming it is not a pointer to a character array. What value do you store in the itemdata when you create the ListBox ?
I must get a clever new signature for 2011.
|
|
|
|
|
i stored a TCHAR File_name in the listbox. here is the code for how i stored it.
int index = SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_ADDSTRING, 0, (LPARAM)str);
SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_SETITEMDATA, (WPARAM)index, (LPARAM)File_name);
here is the check I have after I add the string in just to make sure.
HWND hList = GetDlgItem(hwnd, IDC_LIST_COMPARE);
int data = SendMessage(hList, LB_GETITEMDATA, (WPARAM)index, 0);
MessageBox (hwnd, (char *)data, "The stored data for the newly selected item is...", MB_OK);
here the message box displays the string fine. I am pretty much using the exact same code as u have suggested, but i just cannot get it to work in the for loop for some stupid reason -_-;;
|
|
|
|
|
A couple of suggestions:
In your data retrieval loop your code might be a bit clearer if you write it as:
char* string = (char*)SendMessage(hList, LB_GETITEMDATA, (WPARAM)i, 0);
Also check that the returned pointer string still points to a valid address. When you add these data items to your list box, if they are pointers to local memory you need to ensure that they are not destroyed. Your code above does not make it clear exactly how they are created, and whether they are permanent.
I must get a clever new signature for 2011.
|
|
|
|
|
LOL still doesnt work. this problem is driving me insane... I need to link the filename with the item in the listbox >.<. why does it work on every single example i see on the web!
here is the full code. Please tell me if I made any mistake
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case ID_CMP_LOADFILE:
{
OPENFILENAME ofn;
TCHAR File_name[MAX_PATH];
int index = SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_ADDSTRING, 0, (LPARAM)str);
sprintf(File_name, "1");
SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_SETITEMDATA, (WPARAM)index, (LPARAM)File_name);
HWND hList = GetDlgItem(hwnd, IDC_LIST_COMPARE);
int data = SendMessage(hList, LB_GETITEMDATA, (WPARAM)index, 0);
MessageBox (hwnd, (char *)data, "The stored data for the newly selected item is...", MB_OK);
fclose(file_opened);
}
break;
}
case ID_CMP_COMPARE:
{
int count;
int i;
HWND handle_list = GetDlgItem(hwnd, IDC_LIST_COMPARE);
count = SendMessage(handle_list, LB_GETCOUNT, 0, 0);
for (i =0; i<count; i++)
{
TCHAR* data = SendMessage(handle_list, LB_GETITEMDATA, (WPARAM)i, 0);
MessageBox (hwnd, data, "The stored data for the newly selected item is...", MB_OK);
}
break;
}
thank you all soo much.. i really need to crack this..
|
|
|
|
|
As I said before, you need to be sure that your data fields are pointing at static memory blocks. You have the following line(s) in your code:
TCHAR File_name[MAX_PATH];
int index = SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_ADDSTRING, 0, (LPARAM)str);
sprintf(File_name, "1");
SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_SETITEMDATA, (WPARAM)index, (LPARAM)File_name);
However, as soon as you leave this function the variable File_name will be destroyed (because it is on the stack) and your pointer is no longer valid.
You need to do something like:
PTSTR pFile_name;
int index = SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_ADDSTRING, 0, (LPARAM)str);
pFile_name = new TCHAR[the length of the filename + 1];
SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_SETITEMDATA, (WPARAM)index, (LPARAM)pFile_name);
now when you leave this function your filename memory buffer will not be destroyed. You should also remember to delete[] all these memory blocks when you destroy your listbox.
I must get a clever new signature for 2011.
|
|
|
|
|
thank you soo much! I actually got it working with a different slightway, because this way everytime I load the filename it gets re-written, so I have to point the pFile_name to a 2D array. And I dnt know whats new, I just used malloc(), but i think it should be the same.
But yeah thank you soo much!
|
|
|
|
|
Had a try, no effect.
I am very sure there are strings associated with it though, because I add a messagebox check when i add the string in
int index = SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_ADDSTRING, 0, (LPARAM)str);
SendDlgItemMessage(hwnd, IDC_LIST_COMPARE, LB_SETITEMDATA, (WPARAM)index, (LPARAM)File_name);
HWND hList = GetDlgItem(hwnd, IDC_LIST_COMPARE);
int data = SendMessage(hList, LB_GETITEMDATA, (WPARAM)index, 0);
MessageBox (hwnd, (char *)data, "The stored data for the newly selected item is...", MB_OK);
here the string associated displayed fine. Since the dialogue box is zero-based index your code should work fine, but i have no idea why it is now working....
|
|
|
|
|
Hi all,
I have a problem with my app that I am writing (VC6), where when I add a dialog control and then double click to add a member function, VC does not add the function, and I end up with every Generated message map functions doubled up, which of course gives the "member function already defined or declared" compile error.
Every time I repeat this, the functions are added again. Problem also happens even if I double click to add the member function, but immediatly click cancel.
Any suggestions?
Thanks in advance!
Mike
|
|
|
|
|
VC6 was some time ago, but do you have the correct "insertion point comments" in your message map?
|
|
|
|
|
Hi Niklas - thanks for helping.
This is what my generated message map looks like after trying to add a member:
// Generated message map functions
//{{AFX_MSG(CDanuDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
virtual void OnOK();
afx_msg void OnButton1();
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
virtual void OnOK();
afx_msg void OnButton1();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
its slightly different from what you suggested, as it has //{{AFX_MSG(CDanuDlg) - I think this is right however.
Cheers
Mike
|
|
|
|
|
The ones I suggested should be inside your message map, between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP in the cpp-file.
One idea could be to generate a new MFC dialog class, and compare all those generated comments to the ones in your dialog.
|
|
|
|
|
Hi Niklas
I have got to the bottom of this now (after a spending the day trying to work out where it was going wrong)!
In my message map, I had something like this declared:
ON_COMMAND_RANGE(IDC_BUTTON_1, IDC_BUTTON_4, OnMyFunction)
OnMyFunction had been declared as a normal function (void OnMyFunction()). As soon as I moved it to the right message map (afx_msg void OnMyFunction()) problem was solved!
AAAAAGGGGHHHH what a waste of time!
Thanks for your input though!
Mike
|
|
|
|
|
In Process Explorer software
have function view handles of process
i don't know how to get handles same that function
someone give me idea>?
thanks so much
sorry if my english is not good
|
|
|
|
|
Maybe check this[^] as a starting point, it has source code for you to examine.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
thanks
very clearly ..
i'll try
|
|
|
|
|
If you want to retrieve the number of opened handles by given process you can use GetProcessHandleCount[^]. Note that minimum supported clients for this function are Windows Vista and Windows XP with SP1.
If you want to support older windows versions you can use NtQuerySystemInformation[^]. Look for SYSTEM_PROCESS_INFORMATION class and read the documentation carefully before using this function.
I hope this helps.
|
|
|
|
|
thanks.
i 'll research...do you have a help document for me?
|
|
|
|
|
Well I already gave you the link to the documentations of two APIs.
The usage of GetProcessHandleCount is trivial, documentation says everything you need.
For NtQuerySystemInformation you can check out this[^] thread, where you will find a sample code that actually retrieves Handle Count, Thread Count, etc.
The example code actually uses ZwQuerySystemInformation[^] function but in fact this does not change anything for you, the usage is exactly the same.
P.S. If you actually want to know the difference between 'Nt' and "Zw' prefixed native API functions, have a look at this interesting article[^].
|
|
|
|
|
Hi, I'm writting a simple client/server program using microsoft RPC. The client should specify server's system user name and valid password in each RPC procedure, otherwise server reject the RPC request. I do not know how to do it. Please give me some advise. Thank you.
|
|
|
|
|
Can I put DllName.OtherName.OtherName.dll as my Win32 dll name.
|
|
|
|
|
Yes.
I am a HUMAN. I have that keyword in my name........
_AnsHUMAN_
|
|
|
|
|
Hi ,
i have an interger x=10; i want to write this by assigning it to const unsigned char variable.
whenever i tried to write in file it increase the file offset by 2. for e.g if before writing file offset was 152 after writing it become 154.
But i wrote 9 or 11 or any other number than 10 ,it increase offset by 1 means offset increase from 152 to 153.
it works fine on Linux but giving issue on windows.
Regards,
Sachin
|
|
|
|
|
The value 10 in binary means a new line character.
In Windows, a new line is converted to a new line / carriage return character pair.
Linux and Unix do not do this.
Thats the reason for this behavior.
|
|
|
|
|
Thanks Santosh for quick reply ,
Can you please help me to write a value 10 in a file .I have an integer with value 10.I do typecasting to store in unsigned char which i pass in fwrite() as parameter.
If in windows writing 10 to file treat as different operation as mentioned above, Can you please suggest me alternate way to write value 10 in file i.e. in which format I should pass parameter to fwrite()
Regards,
Sachin
|
|
|
|
|