Hi all,
Been trying to work on a custom control for my disassembler (as shown in the image attached). I have successfully managed to use DrawText and drew text on the window. Now come the part which I was stuck. I do not know how to add a scrollbar to the "edit" which is actually the white part in the middle of the program. Do I need to create another control just for the scrollbar? Also what messages do I handle when the scrollbar is pressed or what so ever.
roticv is pretty poor with GUI, and does not have much experience when it comes to GUI.
PS: The exe that is disassembled as shown in the image attached is notepad.exe Microsoft does use weird code. I see hlt in a ring3 application.
Regards,
roticv
Been trying to work on a custom control for my disassembler (as shown in the image attached). I have successfully managed to use DrawText and drew text on the window. Now come the part which I was stuck. I do not know how to add a scrollbar to the "edit" which is actually the white part in the middle of the program. Do I need to create another control just for the scrollbar? Also what messages do I handle when the scrollbar is pressed or what so ever.
roticv is pretty poor with GUI, and does not have much experience when it comes to GUI.
PS: The exe that is disassembled as shown in the image attached is notepad.exe Microsoft does use weird code. I see hlt in a ring3 application.
Regards,
roticv
Taking a look on Tomasz' (the author of FASM) AsmEdit control which is used in FASMW, you will understand how it's used. I think you have to add WS_VSCROLL to the style parameter in the CreateWindowEx call (or something similar to that, edit the style when the control is created ...?). And then you can use the WM_VSCROLL to get the information you need and redraw the window... I don't know in details how to do it, but in general this is the way to do it (I think)... ;)
Your work seems to be cool! I'm looking forward to test it! ;) Keep it up!
Regards,
Tommy
Your work seems to be cool! I'm looking forward to test it! ;) Keep it up!
Regards,
Tommy
Hi Roticv,
You can make the scrollbars children of the custom control then process the WM_HSCROLL and WM_VSCROLL messages from within the control. Res2Dlg has scroll bars that are handled by the program though they are children of the main dialog the handling is essentially the same:
You can look at the source for Res2Dlg to see the particulars for the message handling. You must initially set the scroll bar information to make it useful:
You can make the scrollbars children of the custom control then process the WM_HSCROLL and WM_VSCROLL messages from within the control. Res2Dlg has scroll bars that are handled by the program though they are children of the main dialog the handling is essentially the same:
.ELSEIF uMsg == WM_VSCROLL
mov eax,lParam
invoke memfill,ADDR sInfo,0,SIZEOF SCROLLINFO
mov sInfo.cbSize,SIZEOF SCROLLINFO
mov sInfo.fMask,SIF_ALL
invoke GetScrollInfo,lParam,SB_CTL,ADDR sInfo
mov eax,wParam
.IF ax == SB_BOTTOM
mov eax,sInfo.nMax
mov sInfo.nPos,eax
mov sInfo.nTrackPos,eax
.ELSEIF ax == SB_LINEDOWN
inc sInfo.nPos
inc sInfo.nTrackPos
.ELSEIF ax == SB_LINEUP
dec sInfo.nPos
dec sInfo.nTrackPos
.ELSEIF ax == SB_PAGEDOWN
mov eax,sInfo.nPage
add sInfo.nPos,eax
add sInfo.nTrackPos,eax
.ELSEIF ax == SB_PAGEUP
mov eax,sInfo.nPage
sub sInfo.nPos,eax
sub sInfo.nTrackPos,eax
.ELSEIF ax == SB_THUMBPOSITION
mov eax,sInfo.nTrackPos
mov sInfo.nPos,eax
.ELSEIF ax == SB_THUMBTRACK
mov eax,sInfo.nTrackPos
mov sInfo.nPos,eax
.ELSEIF ax == SB_TOP
mov sInfo.nPos,0
mov sInfo.nTrackPos,0
.endif
mov sInfo.fMask,SIF_POS or SIF_TRACKPOS
invoke SetScrollInfo,lParam,SB_CTL,ADDR sInfo,TRUE
invoke GetWindowRect,hDisplayDialog,ADDR lpRECT
mov eax,lpRECT.left
mov pt.x,eax
mov eax,lpRECT.top
mov pt.y,eax
invoke ScreenToClient,hPrevBox,ADDR pt
mov eax,10
sub eax,sInfo.nPos
invoke SetWindowPos,hDisplayDialog,NULL,pt.x,eax,0,0,SWP_NOSIZE or SWP_NOZORDER
You can look at the source for Res2Dlg to see the particulars for the message handling. You must initially set the scroll bar information to make it useful:
mov sInfo.cbSize,SIZEOF SCROLLINFO
mov sInfo.fMask,SIF_ALL
mov sInfo.nMin,0
mov sInfo.nPage,277
mov sInfo.nMax,277
mov sInfo.nPos,0
mov sInfo.nTrackPos,0
invoke SetScrollInfo,vScroll,SB_CTL,ADDR sInfo,TRUE
Tommy,
Actually I have been looking into asmedit's source code. That's where I learnt that I have to use DrawText to paint the disassembly (The real disassembly is done when processing WM_PAINT)
Donkey,
Thanks a million. Will look into it.
Actually I have been looking into asmedit's source code. That's where I learnt that I have to use DrawText to paint the disassembly (The real disassembly is done when processing WM_PAINT)
Donkey,
Thanks a million. Will look into it.
Donkey,
May I ask why you inc/dec the value in nTrackPos during pagedown/pageup/linedown/lineup?
nTrackPos
Specifies the immediate position of a scroll box that the user is dragging. An application can retrieve this value while processing the SB_THUMBTRACK notification message. An application cannot set the immediate scroll position; the SetScrollInfo function ignores this member.
May I ask why you inc/dec the value in nTrackPos during pagedown/pageup/linedown/lineup?
nTrackPos
Specifies the immediate position of a scroll box that the user is dragging. An application can retrieve this value while processing the SB_THUMBTRACK notification message. An application cannot set the immediate scroll position; the SetScrollInfo function ignores this member.
PS: The exe that is disassembled as shown in the image attached is notepad.exe Microsoft does use weird code. I see hlt in a ring3 application.
Does that look like program code at all to you? - seems more likely you're disassembling data.
PS: The exe that is disassembled as shown in the image attached is notepad.exe Microsoft does use weird code. I see hlt in a ring3 application.
Well, the entire code looks completely odd, if you ask me.
The same lines twice in a row for example (xchg and xchg back?).
Completely illogical conditional jumps, without any actual flags being set...
So I don't think it's actual program code that we see here. And we don't need to worry about Microsoft just yet ;)
Hi Rotcv,
The snippet is pretty bad now that I take a look at it, it was one of the first things I ever wrote for Win32 and certainly the first time I ever tried scrollbars. The settings for nTrackPos are not necessary. I guess that more than year later when I redid the extraction section I should have redone the UI as well. ;)
The snippet is pretty bad now that I take a look at it, it was one of the first things I ever wrote for Win32 and certainly the first time I ever tried scrollbars. The settings for nTrackPos are not necessary. I guess that more than year later when I redid the extraction section I should have redone the UI as well. ;)
f0dder, you right. What I am staring at is actually the iat of notepad. :stupid:
Now I run into some problems. I use the following code:
My question would be how to update the style of the window?
cmp [ebx]._linesineditor, esi
ja @F
invoke GetWindowLong,hwnd, GWL_STYLE
or eax, WS_VSCROLL
invoke SetWindowLong,hwnd, GWL_STYLE, eax
mov SC.cbSize, SIZEOF SCROLLINFO
mov SC.fMask, SIF_RANGE or SIF_PAGE or SIF_POS
and SC.nMin, 0
mov SC.nMax, esi
mov eax, [ebx]._startline
and SC.nPos,eax
mov eax, [ebx]._linesineditor
mov SC.nPage, eax
invoke SetScrollInfo,hwnd,SB_VERT,ADDR SC, TRUE
@@:
My question would be how to update the style of the window?
Hi Roticv,
When you change the style to add a scroll bar you must execute a SetWindowPos with the SWP_FRAMECHANGED flag.
When you change the style to add a scroll bar you must execute a SetWindowPos with the SWP_FRAMECHANGED flag.
invoke SetWindowPos,[hWin],HWND_TOP,0,0,0,0,SWP_NOMOVE+\
SWP_NOZORDER+SWP_NOSIZE+SWP_FRAMECHANGED
Thanks... Finally fixed the scrollbar issue. Now for me to work on another issue.