some help with window, toolbar, statusbar and listview

Started by dacid, January 31, 2010, 10:38:57 PM

Previous topic - Next topic

dacid

So I create a Window (CreateWidow) a Status Bar (CreateStatusWindow)  a Tool Bar (CreateToolbarEx) and a ListView (CreateWindow)... I use this code to "resize" the listview when the user resizes the window:

     .ELSEIF uMsg == WM_SIZE

            invoke SendMessage,hStatusBar,uMsg,wParam,lParam
            invoke SendMessage,hToolBar,uMsg,wParam,lParam

            invoke GetWindowRect,hToolBar,addr rc
   
            mov    rc2.left,0
            mov    rc2.top,30                     ; toolbar size
           
            mov    eax,lParam                ; low order of lParam = new width, high order = new height
            and    eax,0ffffh
            mov    rc2.right,eax
   
            mov    eax,lParam                ; high order of lParam = new heigh
            shr    eax,16
             mov    edx,rc.bottom                       ; bottom = new height - ((taskbar.bottom - taskbar.top)
             mov    ecx,rc.top
             sub    edx,ecx                     ; edx=hoogte taskbar = 14h of 20d pixels
             sub    eax,edx                     ; nieuwe windowhoogte-hoogte taskbar
            sub    eax,22                                                 ; size of status bar
             mov    rc2.bottom,eax

            invoke SetWindowPos,hListView,NULL,rc2.left,rc2.top,rc2.right,rc2.bottom, SWP_NOZORDER


As you can see I do a little dirty tricks using fixed values to tool bar and status bar... Can anyone give me a hand here doing it "well done"? I think I should get the size and not assuming it (not matter that it works..).

donkey

I always write my resizers and splitters as "one shots" specific to each application but for a generic "well done" approach you can look at EWayne's splitter control, which use a DLL based control to resize the windows by the user moving a splitter bar. I have to admit I haven't looked at them for years but he does excellent work and I would always recommend his examples.

http://asmedit.massmind.org/

Select "Other Programs" and scroll down, I would suggest you look at Splitter32 however all of the examples have something to offer.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable


Gunner

actually use CreateWindow(Ex) to create your statusbar.

QuoteCreateStatusWindow Function

--------------------------------------------------------------------------------

Creates a status window, which is typically used to display the status of an application. The window generally appears at the bottom of the parent window, and it contains the specified text.

Note   This function is obsolete. Use CreateWindow instead.

Syntax

~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

donkey

Actually CreateWindow doesn't really exist as an export from User32.DLL, it is usually wrapped around CreateWindowEx by a macro type mechanism (try to call GetProcAddress for it). Use CreateWindowEx instead if you need extended styles, if you aren't using them the wrapper will use 0 so it makes no difference.

Show Exports from WinExplorer of user32.dll version 6.0.6002.18005

"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

dacid

Uh, Im using CreateWindowEx ... just tried to save some bytes typing heh.

donkey: so do you see ok to use the actual code im using? its "one shot" using the specific sizes of toolbar and statusbar in the current app. It works ok... I will look at the examples you mention and see if It is too complicated a "well-done" routine.

Uh, Im didnt know about CreateStatusWindow gets obsoleted.. I will use CreateWindowEx instead.

Please excuse my poor english.

japheth

Quote from: dacid on January 31, 2010, 10:38:57 PM
As you can see I do a little dirty tricks using fixed values to tool bar and status bar... Can anyone give me a hand here doing it "well done"? I think I should get the size and not assuming it (not matter that it works..).

Here's a code fragment which handles WM_SIZE for a quite similiar app ( it has an additional treeview window ).


// on WM_SIZE adjust client windows

int CExplorerView::ResizeClients(HWND hWnd)
{
RECT rect;
RECT rectTV;
RECT rectSB;
RECT rectTB;
HDWP hdwp;

GetClientRect(hWnd,&rect);

GetWindowRect(m_hWndToolbar,&rectTB);
rectTB.bottom = rectTB.bottom - rectTB.top;

GetWindowRect(m_hWndStatusBar,&rectSB);
rectSB.bottom = rectSB.bottom - rectSB.top;

GetWindowRect(m_hWndTreeView,&rectTV);
rectTV.right = rectTV.right - rectTV.left;

if (rectTV.right == 0) {
int aWidths[2];
rectTV.right = MulDiv(rect.right,1,3) - 2;
aWidths[0] = rect.right / 3;
aWidths[1] = -1;
SendMessage (m_hWndStatusBar, SB_SETPARTS, 2, (LPARAM)aWidths);
}

iToolbarHeight = rectTB.bottom;

hdwp = BeginDeferWindowPos(5);

// set the status bar

DeferWindowPos(hdwp, m_hWndStatusBar, NULL,
0,rect.bottom - rectSB.bottom,
rect.right,rectSB.bottom,
SWP_NOZORDER | SWP_NOACTIVATE);

// set the toolbar control

DeferWindowPos(hdwp, m_hWndToolbar, NULL,
0,0,rect.right,rectTB.bottom,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

// set the tree view control

DeferWindowPos(hdwp, m_hWndTreeView, NULL,
0, rectTB.bottom, rectTV.right,
rect.bottom - rectSB.bottom - rectTB.bottom,
SWP_NOZORDER | SWP_NOACTIVATE);

// set the tab control

rect.left = rectTV.right + 4;
rect.top = rectTB.bottom;
rect.right = rect.right - rectTV.right - 4;
rect.bottom = rect.bottom - rectSB.bottom - rectTB.bottom;

DeferWindowPos(hdwp, m_hWndTabCtrl, NULL,
rect.left,
rect.top,
rect.right,
rect.bottom,
SWP_NOZORDER | SWP_NOACTIVATE);


// set the list view control

TabCtrl_AdjustRect(m_hWndTabCtrl, FALSE, &rect);

DeferWindowPos(hdwp, m_hWndListView, HWND_TOP,
rect.left, rect.top,
rect.right - rect.left + rectTV.right +  4,
rect.bottom - rect.top + rectTB.bottom,
SWP_NOACTIVATE);

EndDeferWindowPos(hdwp);
return 1;
}


The code - written in C as you may have notived - makes no assumptions about the heights of status and toolbar window and instead uses the current values.

donkey

Quote from: dacid on February 01, 2010, 09:14:05 AM
Uh, Im using CreateWindowEx ... just tried to save some bytes typing heh.

donkey: so do you see ok to use the actual code im using? its "one shot" using the specific sizes of toolbar and statusbar in the current app. It works ok... I will look at the examples you mention and see if It is too complicated a "well-done" routine.

Uh, Im didnt know about CreateStatusWindow gets obsoleted.. I will use CreateWindowEx instead.

Please excuse my poor english.

Hi dacid,

The code looks fine to me, actually not too distant from what I usually do, not that I'm prone to the "right way" which is why I didn't post any of my code. I posted the link to EWayne's site to give you some examples of how to do a more automated and reusable version. I have noticed that once someone starts using re-sizable windows they tended to get more and more elaborate with every application (3 or 4 way splits etc...) and eventually either write a lot of "one shots" like me or do it the smart way and use something like EWayne's examples.

For the CreateWindow thing, I didn' get the joke by jj2007 until just now. Very funny  :bg

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable