开发者

Confusing Function in C++ Dialogs

开发者 https://www.devze.com 2023-02-12 03:38 出处:网络
Hi could anyone explain to me what this function is doing, I am currently reading a programming book and am struggling to follow this function.

Hi could anyone explain to me what this function is doing, I am currently reading a programming book and am struggling to follow this function.

From what I can gather the function take in a handle to a window (in this case a dialog box), then information is passed in the second param and the third param being a pointer to the actual object.

To give some context I'm trying to populate a combo box with the adapters that a computer has.

void AddItem(HWND hWnd, char *ch, void *pData) 
{
  WPARAM nI = (WPARAM)((int)(DWORD)SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)c开发者_JAVA百科h));

  SendMessage(hWnd,CB_SETITEMDATA, nI, (LPARAM)pData);
}

here is an example call:

for (UINT a=0; a<m_dwNumAdapters; a++) 
{
   AddItem(m_hADAPTER, m_xAdapterInfo[a].d3dAdapterIdentifier.Description,
           &m_xAdapterInfo[a]);
}

Thanks.


I used earlier something like this to add items to combo box, I might be of help.

SendDlgItemMessage(hwnd, IDC_COMBOSTATUS, CB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "Available");

Where hwnd is handle to dialog, IDC_COMBOSTATUS is resource ID, and other is pretty much clear.

Try SendDlgItemMessage function rather SendMessage.

Regards,

Vajda


It adds a string value and associated integer to a combo box.

The aspect you may be missing is that list boxes, combos etc. store an integer value (the same size as a pointer) in a list parallel to the list of text labels. You can put whatever you like in the integer value. For example you could put in a pointer to some struct containing further information.

When you need to respond to the user's selection, you simply read out the selected integer value, cast it to a pointer, and do something with that information.

Of course, many lists and combos don't need any of this (a simple string suffices) and so 0 would typically be passed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号