Troubles with ListView and Toolbar

This is a discussion on Troubles with ListView and Toolbar within the Windows Programming forums, part of the Platform Specific Boards category; Hi guys its me again, and i've got another problem... again. In my main Window of my program i have ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    17

    Troubles with ListView and Toolbar

    Hi guys its me again, and i've got another problem... again.

    In my main Window of my program i have a menu, a toolbar and a listview.

    The listview is filled correctly. Now i tried to make it resize automatically. This works. But if i klick on an element of the toolbar, the listview is completle changed an only the header is visible... Any idea why this happens?
    If i resize the window, after the listview disappeared, it appears again if as nothing had happend.

    Do you know what the problem is?
    do i have to redraw the listview if the toolbar is accessed?
    How do i redraw the listview?

    Thank you

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    52
    Try using UpdateWindow() with the listview being the hwnd in there perhaps?
    - Daniel Wallace

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    17
    No, doesnt work unfortunately, but thanks anyway.
    I belive that the size of the listView is set new, if the toolbar is accessed.
    Any ideas how to avoid this? Any idea why this is like that?

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    52
    I assume that the toolbar might be resizing, thus hiding the listview, though I'm only stabbing in the dark here, you could try using SetWindowPos() on the listview and making it HWND_TOPMOST, though it could be going in the wrong direction, maybe the list is being destroyed or something, and you need to re-add the data into the listview/

    What style is the listview, report, icon, etc? and take a look at the function regarding the toolbar for anything unusual
    - Daniel Wallace

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    I use toolbars and multiple listviews.

    Never had an issue like that, apart from the height of the toolbar not being excluded from the client area. ie top of client is covered by the toolbar.

    Post some code, sounds like you are mixing ID numbers or HWNDs.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Oct 2005
    Posts
    17
    Code:
    /*
     *	Callback function for the MainWindow
     */
    LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
    	switch(msg){
    		case WM_CREATE:
    			actualConfiguration = readConfiguration();
    			break;
    		
    		case WM_TRAYICONMSG:
    			switch(lParam){
    				case WM_LBUTTONDBLCLK:
    					showWindow(hwnd);
    					break;
    				case WM_RBUTTONDOWN:
    				case WM_CONTEXTMENU:
    					showContextMenu(hwnd);
    			}
    			break;
    		
    		case WM_CLOSE:
    			hideWindow(hwnd);
    			return 0;
    
    		case WM_COMMAND:
    			switch(LOWORD(wParam)) {
    				
    				case TOOLBAR_UPDATE:
    					{
    						char editItem[BUFFER_SIZE];
    						SendDlgItemMessage(hwndToolbar, 
                                           ID_TOOLBAR_EDIT, 
                                           EM_GETLINE, 
                                           (WPARAM) 0,       // line 0 
                                           (LPARAM) editItem);
    						int maxIdleTime = atoi(editItem);
    						updateUsers(maxIdleTime);
    					}
    					break;
    				case MAIN_FILE_CLOSE:
    					hideWindow(hwnd);
    					break;
    
    				case SWM_CONF:
    				case MAIN_EDIT_CONF:
    					DialogBox(NULL, MAKEINTRESOURCE(DIALOG_CONFIG), hwnd, ConfigDlgProc);
    					break;
    
    				case MAIN_HELP_ABOUT:
    					DialogBox(NULL, MAKEINTRESOURCE(DIALOG_ABOUT), hwnd, AboutDlgProc);
    					break;
    
    				case SWM_SHOW:
    					showWindow(hwnd);
    					break;
    
    				case SWM_HIDE:
    					hideWindow(hwnd);
    					break;
    
    				case SWM_RECON:
    					checkOnError();
    					break;
    
    				case SWM_EXIT:
    					WSACleanup();
    					destroyWindow(hwnd);
    					break;
    			}
    			case WM_SIZE:
    				SendMessage(hwndToolbar, TB_AUTOSIZE, 0, 0);
    				MoveWindow(hwndList,0,30,LOWORD(lParam),HIWORD(lParam),TRUE);
    				SendMessage(hwndList,LVM_ARRANGE,LVA_ALIGNLEFT,0);
    				break;
    		default:
    			return DefWindowProc(hwnd, msg, wParam, lParam);
    	}
    
    	return 0;
    }
    This is the code for my callback function.
    In the TOOLBAR_UPDATE case, the toolbar is accessed, some data is read from an edit box in the toolbar and the function updateUsers is called.
    The WM_SIZE message is sended, when the toolbar is accessed... i dont know why this happens.
    Maybe i have to change something in the handle of the WM_SIZE message... any ideas?

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    >>MoveWindow(hwndList,0,30,LOWORD(lParam),HIWORD(l Pa ram),TRUE);

    What values are in the LOWORD(lParam) and HIWORD(lParam)?
    Are they what you expect?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Registered User
    Join Date
    Oct 2005
    Posts
    17
    Quote Originally Posted by novacain
    What values are in the LOWORD(lParam) and HIWORD(lParam)?
    Are they what you expect?
    Yes they are what im expecting, as long as i only resize the window.
    If i'm accessing the toolbar, a new WM_SIZE message is send, and the value of this message is not what im expecting. There are some strange values, which are the reason that the listview size is changed.
    But i dont know, how i can avoid these messages.
    I mean... there must be a solution for this... windows also can resize a report listview with toolbar and menu without a problem...

  9. #9
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    		case WM_COMMAND:
    			switch(LOWORD(wParam)) {
    				
    				case TOOLBAR_UPDATE:
    					{
    						char editItem[BUFFER_SIZE];
    						SendDlgItemMessage(hwndToolbar, 
                                           ID_TOOLBAR_EDIT, 
                                           EM_GETLINE, 
                                           (WPARAM) 0,       // line 0 
                                           (LPARAM) editItem);
    						int maxIdleTime = atoi(editItem);
    						updateUsers(maxIdleTime);
    					}
    					break;
    				case MAIN_FILE_CLOSE:
    					hideWindow(hwnd);
    					break;
    
    				case SWM_CONF:
    				case MAIN_EDIT_CONF:
    					DialogBox(NULL, MAKEINTRESOURCE(DIALOG_CONFIG), hwnd, ConfigDlgProc);
    					break;
    
    				case MAIN_HELP_about:
    					DialogBox(NULL, MAKEINTRESOURCE(DIALOG_ABOUT), hwnd, AboutDlgProc);
    					break;
    
    				case SWM_SHOW:
    					showWindow(hwnd);
    					break;
    
    				case SWM_HIDE:
    					hideWindow(hwnd);
    					break;
    
    				case SWM_RECON:
    					checkOnError();
    					break;
    
    				case SWM_EXIT:
    					WSACleanup();
    					destroyWindow(hwnd);
    					break;
    			}
    
    /* Whoops, we need a break statement here. Otherwise, we fall through to
     * the WM_SIZE with garbage values. */
    
    			case WM_SIZE:
    				SendMessage(hwndToolbar, TB_AUTOSIZE, 0, 0);
    				MoveWindow(hwndList,0,30,LOWORD(lParam),HIWORD(lPa  ram),TRUE);
    				SendMessage(hwndList,LVM_ARRANGE,LVA_ALIGNLEFT,0);  
    				break;
    Also, you need to take account of the toolbar height when you set the size of your list-view:
    Code:
    			case WM_SIZE:
    			{
    				RECT  ToolbarRect;
    				DWORD ToolbarHeight;
    
    				/* Auto-size the toolbar. */
    				SendMessage(hwndToolbar, TB_AUTOSIZE, 0, 0);
    
    				/* Get height of toolbar. */
    				GetWindowRect(hwndToolbar, &ToolbarRect);
    				ToolbarHeight = ToolbarRect.bottom - ToolbarRect.top;
    
    				/* Size the list-view, taking into account the toolbar height. */
    				MoveWindow(hwndList, 0, ToolbarHeight,
    				           LOWORD(lParam), HIWORD(lParam) - ToolbarHeight, TRUE);
    
    				SendMessage(hwndList,LVM_ARRANGE,LVA_ALIGNLEFT,0);
    				break;
    			}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Listview and Toolbar--Resizing Help Please!
    By Stan100 in forum Windows Programming
    Replies: 3
    Last Post: 07-01-2005, 03:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21