May 09, 2024, 03:50:05 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


What's the difference?

Started by LarryMc, April 07, 2008, 04:55:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

April 07, 2008, 04:55:21 PM Last Edit: April 07, 2008, 04:58:07 PM by Larry McCaughn
Attached in the zip are 2 source files.

dlg_version.eba is a source file given to me by Sapero which demonstates resizing and dragging controls in a dialog.

win_version.eba is the dialog version with the absolute minimum of changes to make the dialog into a window.  Everything else is the same.

in the dlg version the resizing of the edit control works properly.

in the win version the edit control will expand out when the drag handles are clicked.  Once that is done the control can't be resized to any smaller than that arbitrary size which is larger than the original created size.

Other controls work the same in either a dialog or window.

What's the difference and how do I fix it?

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Can't actually compile them because I don't use Saperos headers.   However it isn't just the edit control.  The combo box and list box do the same thing.

One thing that you have to remember is that a dialog and a window are not the same, controls interact differently with a dialog parent then they do with a window based parent.  A dialog has a special message handler for one.

Without doing more research, and being able to compile it, I really won't be of much help.  Some of my guesses:

1.  The Microsoft handler for those controls might be using a minimum size rectangle (WM_GETMINMAXINFO) for the control when the parent is not a dialog.  Could be a MSDN KB thing.  Never ran into it myself though. 

2. Might be something to do with the font of the control...something to think about as all measuements in a dialog are based on the size of the dialogs font.  (those dialog units I've mentioned before).

3.  Your EnsureAlignment function might be mucking things up when used with a window parent.  align = ((1<<(align-1)) - 1) || -1 was a bit confusing, I don't have time to decipher that one ;) 

Also that function does print the correct size of the control in the caption when it is popped to that minimum.

Paul.
Ionic Wind Support Team

LarryMc

Paul,
Thanks for taking the time to look at it.  That #3 is something Sapero did and I don't have a clue what it really does.  But the size problem is still there when that ensure alignment is bypassed.

Maybe Sapero can/will look at it and be able to tell something.

I ain't got the smarts to solve it.  At best I might accidently stumble across something if I played with it long enough; MAYBE!

Anyway, thanks again.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

((1<<(align-1)) - 1) || -1  creates a bitmask with align - least significant bits set to zero.

For align = 1, the result is 0xFFFFFFFE (...11111110)
For align = 4, the result is 0xFFFFFFF0 (...11110000)

The result is used to clear x-LSB bits of current width/height/position of the control, in order to align it to grid. This is optional tool.

LarryMc

Attached is the drag and resize that Sapero gave me but does not use Sapero's windows.inc files.

I still can't figure out how to fix the problem with the minimum resizing of the listbox, listview, and edit controls.

Any help would be appreciated.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

As I get time I will look at it.  Patience though as I am very preoccupied at the moment.

One thought did occur to me.  Try using SetSize to manually size one of those controls to something small and see if it pops back to that fixed minimum size. 

Paul.
Ionic Wind Support Team

LarryMc

That will be fine.  I've got 2 roof repairs (rotten boards) to work on in the meantime.

Seems that when my mother-in-law had a new roof put on in 1999 that the fly-by-night roofing company pulled the flashing away from the brick and didn't bother to put it back properly and seal it off.

I had tried the setsize and just re-verified that if I put the setsize command in the @IDLBUTTONDOWN case that when I click the left button the edit window does move and shrinks to a smaller size and stays that size.

So it appears that drag handles and returning the hittest codes is what triggers it.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Well it turns out I was correct.   Processing the WM_GETMINMAXINFO message works.  The field of interest in the minmaxinfo structure is ptMinTrackSize which specifies the minimum rectangle you wish a window to be sized to.  I set both x and y to 0 in this example.

Paul.


'$include "windows.inc" ' sdk headers
DECLARE IMPORT, _SetProp ALIAS SetPropA(hwnd AS INT,lpString AS STRING,hData AS INT),INT
DECLARE IMPORT, _SetWindowLong ALIAS SetWindowLongA(hwnd AS INT,nIndex AS INT,dwNewLong AS INT),INT
DECLARE IMPORT, _EnumChildWindows ALIAS EnumChildWindows(hWndParent AS INT,lpEnumFunc AS INT,lParam AS INT),INT
DECLARE IMPORT, _EnableWindow ALIAS EnableWindow(hwnd AS INT,fEnable AS INT),INT
DECLARE IMPORT, _GetProp ALIAS GetPropA(hwnd AS INT,lpString AS STRING),INT
DECLARE IMPORT, _RemoveProp ALIAS RemovePropA(hwnd AS INT,lpString AS STRING),INT
DECLARE IMPORT, _SetFocus ALIAS SetFocus(hwnd AS INT),INT
DECLARE IMPORT, _DefWindowProc ALIAS DefWindowProcA(hwnd AS INT,wMsg AS INT,wParam AS INT,lParam AS INT),INT
DECLARE IMPORT, _TrackPopupMenu ALIAS TrackPopupMenu(hMenu AS INT,wFlags AS INT,x AS INT,y AS INT,nReserved AS INT,hwnd AS INT,lprc AS WINRECT),INT
DECLARE IMPORT, _DestroyMenu ALIAS DestroyMenu(hMenu AS INT),INT
DECLARE IMPORT, _GetFocus ALIAS GetFocus(),INT
DECLARE IMPORT, _SetCursor ALIAS SetCursor(hCursor AS INT),INT
DECLARE IMPORT, _LoadCursor ALIAS LoadCursorA(hInstance AS INT,lpCursorName AS STRING),INT
DECLARE IMPORT, _GetSysColor ALIAS GetSysColor(nIndex AS INT),INT
DECLARE IMPORT, _InvalidateRect ALIAS InvalidateRect(hwnd AS INT,lpRect AS pointer,bErase AS INT),INT
DECLARE IMPORT, _ShowWindow ALIAS ShowWindow(hwnd AS INT,nCmdShow AS INT),INT
DECLARE IMPORT, _CallWindowProc ALIAS CallWindowProcA(lpPrevWndFunc AS INT,hWnd AS INT,Msg AS INT,wParam AS INT,lParam AS INT),INT
DECLARE IMPORT, _GetWindowRect ALIAS GetWindowRect(hwnd AS INT,lpRect AS WINRECT),INT
DECLARE IMPORT, _MapWindowPoints ALIAS MapWindowPoints(hwndFrom AS INT,hwndTo AS INT,lppt AS POINTER,cPoints AS INT),INT
DECLARE IMPORT, _GetWindowDC ALIAS GetWindowDC(hwnd AS INT),INT
DECLARE IMPORT, _SelectObject ALIAS SelectObject(hdc AS INT,hObject AS INT),INT
DECLARE IMPORT, _GetStockObject ALIAS GetStockObject(nIndex AS INT),INT
DECLARE IMPORT, _CreatePen ALIAS CreatePen(nPenStyle AS INT,nWidth AS INT,crColor AS INT),INT
DECLARE IMPORT, _Rectangle ALIAS Rectangle(hdc AS INT,X1 AS INT,Y1 AS INT,X2 AS INT,Y2 AS INT),INT
DECLARE IMPORT, _CreateSolidBrush ALIAS CreateSolidBrush(crColor AS INT),INT
DECLARE IMPORT, _DeleteObject ALIAS DeleteObject(hObject AS INT),INT
DECLARE IMPORT, _ReleaseDC ALIAS ReleaseDC(hwnd AS INT,hdc AS INT),INT
declare LOWORD(xa:INT),INT
declare HIWORD(aa:INT),INT

CONST GWL_WNDPROC = (-4)
CONST WM_NCLBUTTONDOWN = 0xA1
CONST WM_LBUTTONDOWN = 0x201
CONST WM_LBUTTONUP = 0x202
CONST WM_LBUTTONDBLCLK = 0x203
CONST HTCAPTION = 2
CONST MF_STRING = 0
CONST TPM_RETURNCMD = 0x100
CONST HTCLIENT = 1
CONST IDC_SIZEALL = 32646
CONST COLOR_BTNFACE = 15
CONST SW_HIDE = 0
CONST SW_SHOW = 5
CONST WM_PAINT = 0xF
CONST WM_DESTROY = 0x2
CONST WM_CONTEXTMENU = 0x7B
CONST WM_NCHITTEST = 0x84
CONST WM_SETCURSOR = 0x20
CONST WM_SIZING = 0x214
CONST WM_EXITSIZEMOVE = 0x232
CONST WM_KILLFOCUS = 0x8
CONST WM_GETMINMAXINFO = 0x24
CONST NULL_BRUSH = 5
CONST PS_SOLID = 0
CONST HTLEFT = 10
CONST HTTOPLEFT = 13
CONST HTBOTTOMLEFT = 16
CONST HTRIGHT = 11
CONST HTTOPRIGHT = 14
CONST HTTOP = 12
CONST HTBOTTOMRIGHT = 17
CONST HTBOTTOM = 15
const TRUE = 1

type MINMAXINFO
    POINT ptReserved
    POINT ptMaxSize
    POINT ptMaxPosition
    POINT ptMinTrackSize
    POINT ptMaxTrackSize
ENDTYPE


$main
window w1
openwindow w1,0,0,465,293,0,0,"Caption",&w1_handler
CONTROL w1,@SYSBUTTON,"click me",14,14,93,21,0x50000000,1000
CONTROL w1,@CHECKBOX,"click me",14,44,70,20,0x50000003,1001
CONTROL w1,@RADIOBUTTON,"click me",14,73,70,20,0x50000009,1002
CONTROL w1,@COMBOBOX,"",14,102,70,80,0x50800603,1003
CONTROL w1,@LISTBOX,"",124,18,70,60,0x50800140,1004
CONTROL w1,@SCROLLBAR,"",122,84,70,20,0x50000000,1005
CONTROL w1,@SCROLLBAR,"",202,20,20,70,0x50000001,1006
CONTROL w1,@LISTVIEW,"",234,24,70,60,0x50000001,1007
CONTROL w1,@TREEVIEW,"",308,24,70,60,0x50800007,1008
CONTROL w1,@GROUPBOX,"Group",124,118,70,60,0x50000007,1009
CONTROL w1,@EDIT,"Edit1",218,106,70,20,0x50800000,1010
CONTROL w1,@STATIC,"Static",222,138,70,20,0x5000010B,1011
centerwindow w1


' subclass the controls
for a=1000 to 1011
InitDragSize(GetControlHandle(w1, a))
next a

while w1.hwnd
wait
wend

end
'--------

SUB w1_handler
SELECT @MESSAGE
CASE @IDCREATE
CASE @IDCLOSEWINDOW
Closewindow w1
ENDSELECT
RETURN
ENDSUB




'--------------------------------------------------------
$define LPFNPROP "A8VD76"

sub InitDragSize(int hwnd)
_SetProp(hwnd, LPFNPROP, _SetWindowLong(hwnd, GWL_WNDPROC, &MyControlProc))
' disable any child control: listview header...
_EnumChildWindows(hwnd, &DisableChildEnumProc, 0)
return
endsub

'--------------------------------------------------------
sub DisableChildEnumProc(int hwnd,int lParam),int
_EnableWindow(hwnd, false)
return true
endsub

'--------------------------------------------------------
sub MyControlProc(int hwnd,UINT uMsg,int wParam,int lParam),int
int proc
proc = _GetProp(hwnd, LPFNPROP)

select uMsg

case WM_DESTROY:
' remove subclass and delete window property
_SetWindowLong(hwnd, GWL_WNDPROC, proc)
_RemoveProp(hwnd, LPFNPROP)
' do any cleanup here

case WM_GETMINMAXINFO
pointer pMinmax:pMinmax = lParam+0
#<MINMAXINFO>pMinmax.ptMinTrackSize.x=0
#<MINMAXINFO>pMinmax.ptMinTrackSize.y=0
RETURN TRUE
'
' mouse
'
case  WM_LBUTTONDOWN
_SetFocus(hwnd)
' enable moving
_DefWindowProc(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
' if here, left button was released
' optional - align control position on n-th pixel
DrawSizingTools(hwnd, 0)
return 0

case WM_LBUTTONUP
DrawSizingTools(hwnd, 0)
return 0

case WM_LBUTTONDBLCLK
' fire properties dialog
return 0

case WM_NCLBUTTONDOWN
' static control is killing this message with result: resize disabled
return _DefWindowProc(hwnd, WM_NCLBUTTONDOWN, wParam, lParam)

case WM_CONTEXTMENU
' create custom menu (for any control)
'wParam = CreateMenu(1)
'APPENDMENU(wParam,"Properties",MF_STRING,10000)

'if (_TrackPopupMenu(wParam, TPM_RETURNCMD, LOWORD(lParam), HIWORD(lParam), 0, hwnd, NULL) = 10000)
' fire properties dialog
'endif
'_DestroyMenu(wParam)
'return 0

'
' cursor
'
case WM_NCHITTEST
return HandleHittest(hwnd, LOWORD(lParam), HIWORD(lParam))

case WM_SETCURSOR
' if the control is focused and the cursor is inside control's client area
' set cursor to four-pointed arrow
if ((_GetFocus() = hwnd) and (LOWORD(lParam) = htclient))
int cur
cur=_LoadCursor(NULL, "IDC_SIZEALL")
_SetCursor(cur)
return 0
endif

'
' drawing
'
case  WM_SIZING
case& WM_EXITSIZEMOVE
DrawSizingTools(hwnd, _GetSysColor(COLOR_BTNFACE))
'_InvalidateRect(hWnd, NULL, TRUE)

case WM_KILLFOCUS
_ShowWindow(hwnd, SW_HIDE)
_ShowWindow(hwnd, SW_SHOW)

case WM_PAINT
' do default, then redraw sizing tools
_CallWindowProc(proc, hwnd, WM_PAINT, 0, 0)
if (_GetFocus() = hwnd)
DrawSizingTools(hwnd, 0)
endif
return 0


endselect
return _CallWindowProc(proc, hwnd, uMsg,wParam,lParam)
endsub


sub DrawSizingTools(int hwnd, int penColor)
uint dc
uint hbr
uint   pen
WINRECT rc
_GetWindowRect(hwnd, rc)
_MapWindowPoints(0, hwnd, &rc, 2) /*left and right is zero*/

dc = _GetWindowDC(hwnd)
' transparent brush
hbr = _SelectObject(dc, _GetStockObject(NULL_BRUSH))
' black pen
pen  = _SelectObject(dc, _CreatePen(PS_SOLID, 1, penColor))
' draw sizing border
_Rectangle(dc, 0, 0, rc.right, rc.bottom)

' now make ready for 8 rectangles
const SMRCSIZE = 5
int midx, midy
midx = (rc.right - SMRCSIZE)>>1
midy = (rc.bottom - SMRCSIZE)>>1
_SelectObject(dc, _CreateSolidBrush(penColor))
' left-top
_Rectangle(dc, 0, 0, SMRCSIZE, SMRCSIZE)
' left-bottom
_Rectangle(dc, 0, rc.bottom-SMRCSIZE, SMRCSIZE, rc.bottom)
' middle-top
_Rectangle(dc, midx, 0, midx+SMRCSIZE, SMRCSIZE)
' middle-bottom
_Rectangle(dc, midx, rc.bottom-0, midx+SMRCSIZE, rc.bottom-SMRCSIZE)
' left-middle
_Rectangle(dc, 0, midy, SMRCSIZE, midy+SMRCSIZE)
' right-middle
_Rectangle(dc, rc.right-SMRCSIZE, midy, rc.right, midy+SMRCSIZE)

' right-top
_Rectangle(dc, rc.right-SMRCSIZE, 0, rc.right, SMRCSIZE)
' right-bottom
_Rectangle(dc, rc.right-SMRCSIZE, rc.bottom-SMRCSIZE, rc.right, rc.bottom)

'restore and delete pen
_DeleteObject(_SelectObject(dc, pen))
'restore brush
_DeleteObject(_SelectObject(dc, hbr))

_ReleaseDC(hwnd, dc)
return
endsub


sub HandleHittest(int hwnd, int x, int y),int
WINRECT rc
int code
point pt
pt.x = x
pt.y = y
_GetWindowRect(hwnd, rc)
_MapWindowPoints(0, hwnd, &rc, 2) /*left and right is zero*/
_MapWindowPoints(0, hwnd, &pt, 1)
x = pt.x
code = HTCLIENT

const BORDERMAGIN = 5

if (_GetFocus() = hwnd)

if (x <= BORDERMAGIN) /* left side */
code = HTLEFT
' can be left, left-top, left-bottom
if (y <= BORDERMAGIN)
code = HTTOPLEFT
else
if (y >= (rc.bottom-BORDERMAGIN))
code = HTBOTTOMLEFT
endif
endif
else
if (x >= (rc.right-BORDERMAGIN)) /* right side */
code = HTRIGHT
if (y <= BORDERMAGIN)
code = HTTOPRIGHT
else
if (y >= (rc.bottom-BORDERMAGIN))
code = HTBOTTOMRIGHT
endif
endif
else
' middle-top or middle-bottom
if ((y <= BORDERMAGIN))
code = HTTOP
else
if (y >= (rc.bottom-BORDERMAGIN))
code = HTBOTTOM
endif
endif
endif
endif
endif

return code
endsub

sub LOWORD(xa:INT),INT
   return xa&0xFFFF
endsub
sub HIWORD(aa:INT),INT
   return aa>>16
endsub
Ionic Wind Support Team

LarryMc

Quote from: Paul Turley on April 09, 2008, 11:19:09 PM
Well it turns out I was correct. 
It has been my experience that you usually are. ;)

Thanks for bailing me out again.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library