Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Manipulate and Record Objects in a Dialog with XML
#1
Project:
Creating movable, re-sizable objects that are defined and displayed using data in an external file that will also record changes in those objects.

Information:
An XML file that contains information (size and position..x y cx cy) about rectangles (A B C D).
Rectangles "snap" to a grid that is 25x25.
Rectangles can only be sized in increments of 25.
Rectangles cannot overlap.
Rectangles contain editable text that will be displayed in the top left corner of the rectangle.
New rectangles can be created and defined.
Existing rectangles can be moved and edited.
Changes will be updated in XML file immediately (AutoSave)
A right click menu on rectangle with options to delete, copy, edit the rectangle. (on Edit menu selection Edit Dialog to define the x y cx cy and text of the rectangle will be called. Data in Edit Dialog updates data in XML file and rectangle displays changes immediatley.)

I'm pretty sure all this can be done. Just look at the Dialog Editor for QM. Pretty much what I am defining here.

I'll be working on this over the next couple days, any help or ideas would be totally rad! Especially a point to get started at.

Thanks,
Jimmy Vig
#2
Gintaras...Example using something like DE_Grid and DE_Drag outside of the Dialog Editor?
#3
Function Dialog69
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str e3
if(!ShowDialog("Dialog69" &Dialog69 &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54231044 0x200 4 30 96 48 ""
;4 Static 0x54000000 0x0 4 4 76 22 "Move with Shift[]Resize with Ctrl"
;END DIALOG
;DIALOG EDITOR: "" 0x2030001 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
,
,case WM_SETCURSOR ;;use it to detect left button down. Don't use WM_LBUTTONDOWN because it is sent to the control, not to the dialog.
,sel lParam>>16 ;;mouse message
,,case WM_LBUTTONDOWN ;;left down
,,sel GetDlgCtrlID(wParam) ;;control id
,,,case 3 ;;edit control
,,,int m=GetMod
,,,sel m
,,,,case [1,2] ;;Shift or Ctrl
,,,,PostMessage hDlg WM_APP wParam m ;;don't use loop on WM_SETCURSOR. Do it async.
,,,,ret DT_Ret(hDlg 1)
,
,case WM_APP
,MoveSizeControlLoop hDlg wParam lParam 1
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

Function MoveSizeControlLoop
Code:
Copy      Help
;/
function hDlg hctrl action mouseButton ;;action: 1 move, 2 resize.  mouseButton: 1 left, 2 right

MSG m; int mb;

RECT r; GetWindowRect hctrl &r
sel action
,case 1
,POINT po; xm po; po.x-r.left; po.y-r.top ;;get mouse offset in control
,case 2
,mou r.right r.bottom ;;move mouse to right-bottom

int hcur=LoadCursor(0 +IDC_CROSS)

SetCapture(hDlg);
rep
,if(GetCapture()!=hDlg || GetMessage(&m, 0, 0, 0)<=0) break
,if(m.message==WM_KEYDOWN && m.wParam==VK_ESCAPE) ReleaseCapture(); break

,mb=0;
,sel(m.message)
,,case WM_MOUSEMOVE:
,,POINT p; xm p
,,sel action
,,,case 1
,,,ScreenToClient hDlg &p
,,,mov p.x-po.x p.y-po.y hctrl
,,,case 2
,,,siz p.x-r.left p.y-r.top hctrl
,,SetCursor(hcur);
,,continue;
,,case WM_LBUTTONUP: mb=MK_LBUTTON
,,case WM_RBUTTONUP: mb=MK_RBUTTON

,if(mb==mouseButton)
,,ReleaseCapture();

,DispatchMessage(&m);
#4
Thanks a bunch...I really got the ball rolling with that bit you sent me Gentaras!

Here's what I worked out so far.


.qml   Objects in a Dialog with XML.qml (Size: 3.3 KB / Downloads: 625)


I am having troubles getting the position of the edit box to be relative to the dialog window. It always comes out a little off.

Also, what designates Ctr and Shift in the bit you sent? I can't seem to quite see that...so I can't change it.

Thanks again for all your help,
Jimmy Vig
#5
GetMod returns 1 for Shift, 2 for Ctrl.

in XML_Data_Position x y
x and y are mouse coordinates in hDlg. That is, you save mouse coordinates, not control coordinates. Control coordinates are retrieved by GetWinXY.
#6
I also played with it a little.
Now supports multiple objects, Add, Delete, text.


Attached Files
.qml   Objects in a Dialog with XML.qml (Size: 4.65 KB / Downloads: 303)
#7
Totally rad...this would make a good quick note board...

I like how you made the XML update when the mouse is released. I was going to work on that next...but you beat me to it Smile

Holy cow...looking at this thing more...I'm going to have to spend the next week breaking the code down. I'm sure I'll have a lot of small little questions...like for example, I have no clue what this is doing:
for(idctrl 100 1000000) if(!id(idctrl hwnd)) break

I am determined to figure it out!


Now I'm going to try to tackle the grid thing!

Thanks for all your help!
#8
In my code, edit controls have different id, starting from 100: 100, 101, 102,...
The code finds the first id that is not assigned to an edit control.


Forum Jump:


Users browsing this thread: 1 Guest(s)