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.

Posted on 2003-12-01 11:46:56 by 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!

Posted on 2003-12-01 11:57:48 by 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:

mov eax,lParam
invoke memfill,ADDR sInfo,0,SIZEOF SCROLLINFO
mov sInfo.fMask,SIF_ALL
invoke GetScrollInfo,lParam,SB_CTL,ADDR sInfo
mov eax,wParam
mov eax,sInfo.nMax
mov sInfo.nPos,eax
mov sInfo.nTrackPos,eax
inc sInfo.nPos
inc sInfo.nTrackPos
dec sInfo.nPos
dec sInfo.nTrackPos
mov eax,sInfo.nPage
add sInfo.nPos,eax
add sInfo.nTrackPos,eax
mov eax,sInfo.nPage
sub sInfo.nPos,eax
sub sInfo.nTrackPos,eax
mov eax,sInfo.nTrackPos
mov sInfo.nPos,eax
mov eax,sInfo.nTrackPos
mov sInfo.nPos,eax
mov sInfo.nPos,0
mov sInfo.nTrackPos,0

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.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
Posted on 2003-12-01 12:00:35 by donkey
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)

Thanks a million. Will look into it.
Posted on 2003-12-02 02:39:24 by roticv
May I ask why you inc/dec the value in nTrackPos during pagedown/pageup/linedown/lineup?


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.
Posted on 2003-12-05 12:17:33 by roticv

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.
Posted on 2003-12-05 12:21:30 by f0dder
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 ;)
Posted on 2003-12-05 12:23:55 by Bruce-li
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. ;)
Posted on 2003-12-05 13:11:04 by donkey
f0dder, you right. What I am staring at is actually the iat of notepad. :stupid:
Posted on 2003-12-05 21:28:49 by roticv
Now I run into some problems. I use the following code:

cmp [ebx]._linesineditor, esi
ja @F
invoke GetWindowLong,hwnd, GWL_STYLE
or eax, WS_VSCROLL
invoke SetWindowLong,hwnd, GWL_STYLE, eax
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?
Posted on 2003-12-05 23:55:19 by roticv
Hi Roticv,

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+\

Posted on 2003-12-06 00:23:46 by donkey
Thanks... Finally fixed the scrollbar issue. Now for me to work on another issue.
Posted on 2003-12-06 00:57:48 by roticv