לסלע, לגלעד ולכל השאר
כנראה שלא הסברתי את עצמי כמו שצריך. הדבר היחיד שיש לי הוא HANDLE והיכולת לעשות SEND MESSAGE. זהו.
אני פועל בכלל מתוך Service, שבין השאר יוצר חלון בצורה כזו:
m_hWnd = CreateWindow("LISTBOX", sCaption, WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL| LBS_NOINTEGRALHEIGHT|WS_THICKFRAME|WS_VISIBLE, 500,0,525,740,NULL,NULL,NULL,NULL); if( m_hWnd ) { SendMessage(m_hWnd, WM_SETFONT, (WPARAM)GetStockObject(OEM_FIXED_FONT), TRUE); unsigned long dwStyle( GetClassLong(m_hWnd, GCL_STYLE) ); if( dwStyle ) { // Disables Close on the window menu. dwStyle = dwStyle | CS_NOCLOSE | CS_SAVEBITS; SetClassLong(m_hWnd, GCL_STYLE, dwStyle); } return true; }
והנה הכתיבה אליו:
if( ! m_hWnd && ! CreateDebugWin() ) return ; int nCount = SendMessage( m_hWnd, LB_GETCOUNT, 0, 0 ); int nTopIndex = SendMessage( m_hWnd, LB_GETTOPINDEX, 0, 0 ) ; if ( nCount > 300 ) { SendMessage( m_hWnd, LB_DELETESTRING, 0, 0 ) ; nCount-- ; if ( nTopIndex ) nTopIndex-- ; } int nCurrentSelection( SendMessage(m_hWnd, LB_GETCURSEL, 0, 0) ); SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)message); if( nCount > 0 && nCurrentSelection == nCount - 1 ) { // The last element is nCount because we have added a line. SendMessage(m_hWnd, LB_SETCURSEL, nCurrentSelection + 1, 0); nTopIndex++ ; } else SendMessage(m_hWnd, LB_SETCURSEL, nCurrentSelection, 0); // Ensure that the current selection is visible (-1 is after the string delete SendMessage(m_hWnd, LB_SETTOPINDEX, nTopIndex, 0 ) ; HDC hDC = GetWindowDC(m_hWnd); SelectObject(hDC, GetStockObject(OEM_FIXED_FONT)); SIZE size; GetTextExtentPoint32(hDC, message, strlen(message), &size); ReleaseDC(m_hWnd, hDC); int ext(SendMessage(m_hWnd, LB_GETHORIZONTALEXTENT, 0, 0)); if( ext < size.cx ) SendMessage(m_hWnd, LB_SETHORIZONTALEXTENT, size.cx, 0);
אני יכול לעשות SUBCLASSING ל-LISTBOX, אבל אני מעדיף שלא. יש דרך לעשות את מה שביקשתי בלי להסתבך?