Jump to content
Tuts 4 You

How to control CMD console?


LCF-AT

Recommended Posts

Posted

Hi again,


 


hmmm sorry Ted but again I have no clue what do to with your example code.Sorry but I am really new with this coding stuff and just can use WinASM only at the moment more or less.


 


@ simple


 


Thanks for your new code.Ok I tried it and added the code into my source + some adjustings and now its working (Yeah Baby!). :) Almost I lost already the entire overview in my source so there are much codes just to handle this LV stuff.


 


Ok there is one another thing to handle where I got problems.All is working if I drag & drop from bottom to top but from top to bottom is does not work correctly so there I have to drag my selected line to one more line below.


 


Example: I got 5 lines in my Listview now I select any line from number 1 or 2 or 3 or 4 and wanna drop this to line 5 then nothing happens.If I select any line from 1-3 and move them to line 5 then it does insert this new entrys to line 4 instead to insert this at line 5.Also if I select more than one line (maybe 2) and drag them above or below then tha app crashs.So these problems are also to see in your created app you have send to me MasmGui.rar = same trouble.


 


PS: Ok I fixed the first problem with moving to exact line now. :) Also I added a check to prevent crashing on problem 2  + check to move more selected lines at same time but this is working a little strange.If you also got ideas how to handle this then tell me again.


 


Thanks


Posted

Yeah like I said it's not production code (yet). Good to see u fixed those bugs, you might have missed this -- When dragging and scrolling at the same time image can get stuck. To fix this u need scroll manually via SendMessage(WM_VSCROLL). You also have to make sure mouse position is inside the listview before dragging
in WM_MOUSEMOVE, because right now it drags anywhere in the parent windowYou are a coder now lcf so I think u got this : )
 

Posted

Hi again,


 


question: So I see there are some little problems with the representation of Listview + Tabcontrol.First problem I see is if I use a created Listview via resources + using another Listview created by CreateWindowEx API with same style & ExStyle and also create same columns (all same) and give them also same names then both listview using a different font size.The font size of created listview by API is a little bit smaller.Why this?


 


Next problem: Also the tab line at bottom get always forced if I move with the mouse over the tab then the tab line does overlap the top line of my listview what does not look very good.I can fix this only again if I just resize the dialog window (with mouse) or if I just minimize & maximize the dialog window again. :( Just wanna ask whether there is any kind of refresh API xy which I could use to update the dialog window again to represent the right good looking listview top line (to prevent overlapping)?


 


Thanks


Posted

Hi,


 


one simple question: How to use MessageBox API with lines on lpText?I mean textline then a free line then next textline.



invoke MessageBox,0,chr$("Do you wanna delete this tab?"),chr$("Info"),MB_OKCANCEL

I tried to use \r\n but its not working so what to use here?


 


So in edi I have a pointer to dynamic string text which I wanna show at a line below like this...



Do you wanna delete this tab? Tab 3

Should be something like...



invoke MessageBox,0,chr$("Do you wanna delete this tab?")+\r\n\r\n (edi)",chr$("Info"),MB_OKCANCEL

...but not working of course and on the internet I find just any C+ or VB examples.Maybe you can show me again what to use in that case. :)


 


Thanks


Posted (edited)

String db "Delete this?", 0ah, 0ah, 0h ; = /n/n

Formatter db "%s%s", 0

Tab3 db "Tab 3", 0

buffer db 256 dup (?)

invoke wsprintf, offset buffer, addr Formatter, addr String, addr Tab3

invoke MessageBox, NULL, addr buffer, addr Tab3, MB_OK

Edited by simple
Posted

Hi,


 


nahhhhh!Whats this again? :) So much stuff just to add any free lines?Ok it works but less would be better but I think its again any ASM issue right.


 


Ok one another question: So I got all working so far and only problem I have now is again how to set a Tab xy to selected?So each time if I delete any tab then no tab is selected (pressed) anymore so that I have to select it manually again.


 


PS: About LVIS_DROPHILITED.So I tried to add this into SetItemHighlight routine and now the lines get blue selected (as I want it) but if I press on any other line then the selection goes no more away. :(


 


greetz


Posted

There's a million ways to concatenate a string lcf, u can do this



Tab3 db "Tab3", 0
String db "Delete this?", 0ah, 0ah
BlankSpace db 256 dup (?) ; make writable space after &String
; this will look a bit different and be even more dangerous if u use local vars on the stack mov eax, dword ptr ds:[Tab3] ; cpu cuts ptr at 1st space so no spaces in string
mov ecx, offset String
xchg eax, [ecx + LENGTHOF String]
invoke MessageBox, NULL, addr String, addr Tab3, MB_OK

U can also use rep movsb instruction. Then there's strcpy, strcat, and 10000 others. Doing stuff like this is bad for 2 reasons:


 


1. It's prone to exceptions (especially rep movsb).


 


2. It's prone to exploits. String format/management is one of the classic ways coders get pwnd. Stuff like strcpy/cat, sprintf, static arrays, manual memory management is safe when done right, but when done wrong will f$%k everything up bad so heads up.


 


In the binary I sent you there's already code to change tab selection.


Posted

Hi again,


 


question: I have created a listview & checkbox and if I now select a line in the listview then it gets highlighted (normal so far) and if I now check the checkbox (on/off) then the highlighted line is gone complete (no highlight and also not grayed).


 


1.) How can I keep the selected line highlighted or how to set the highlight back after I have pressed any checkbox for example?


 


2.) Also same for the grayed mark so how can I set this too?


 


So I tried already some commands as LVM_GETSELECTIONMARK & LVM_SETSELECTIONMARK & LVM_GETSELECTEDCOLUMN & LVM_SETSELECTEDCOLUMN after pressing the checkbox but the line gets not highlighted again. :( So there is also no command as GET / SETCURSEL for Listviews which I could use easier.


 


Or have I to choose any special style or Exslytes?At the moment I just use these..



WS_EX_CLIENTEDGE
WS_CHILD or LVS_REPORT or WS_VISIBLE or WS_TABSTOP

Maybe anyone can help a little again.


 


Thank you


Posted

the answers here are easy, and theyre -very- similar to other answers already in this thread. try harder.


Posted

Remember that I told you already that also your SetItemHighlight part does not highlight the line also if it works to keep selected hidden (Move Up & Down) but I want to keep the highlight ALSO visible and thats the reason why I ask.Whats wrong now?


 


PS: "Try harder" - Nice joke simple.Better answers of my questions would be more helpfully instead.


 


Thanks


Posted

No joke. dont expect there to be a copy/paste code example or ready made winapi solution - there almost never is. between here and pm's u have many pages of basic questions. u have to start answering your own questions


  • Like 1
Posted

Question: Is there any import or plugin in Olly 1 where I can get all names of the windows.inc file in Olly to see?


 


Exsample:



0040CE58 PUSH EDI ; /lParam = 0x0
0040CE59 PUSH EDI ; |wParam = 0x0
0040CE5A PUSH 0x1032 ; |Message = MSG(0x1032)
0040CE5F PUSH EAX ; |hWnd = 0x40067C
0040CE60 CALL DWORD PTR DS:[0x41D290] ; \SendMessageA 0x1000 = LVM_FIRST equ 1000h
0x0032 = LVM_GETSELECTEDCOUNT equ LVM_FIRST + 50 dec

Is there anything to get all names to see (not only some)?


 


@ simple


 


I just aked a little question about how to highlight a line which you also not answered before.Also I do nothing else as to read the entire commands description of MSDN + testing them but without success in that case.I think its not too much to ask to get some help also in that case but you seems to think in a other direction now than me (no idea why).


 


I just try to find any command for Listview which does the same as the command for Listbox called LB_Setcursel so this command does highlight the lines xy I want and I am just looking for any similar command for the listview.


 


EDIT: Great!Just need to use the API SetFocus.


 


greetz


Posted

Hi,


 


There is a book by Charles Petzold - Programming Windows, which has a section on the Listbox class which perhaps you might find helpful.


Posted

Hi,


 


thanks for the hint. :) Thats really a large pdf file.


 


So I got my Listview problems etc fixed so far after many testings but now it works.


 


One easy question: I tried to color my listview single rows but I only get the entire listview background colored but I only just wanna color one entire row (also if nothing was filled) so how to do this?The one day I got it working but have forgotten what I had done. :(


 


Thanks


Posted

Hi guys,

 

I have some new questions and maybe anyone can help again.

 

1.) How can I check what item does belong to which row / column in a Listview?

 

Exsample:

Row 1 | Row 2 | Row 3 |-----------------------1     | A1    | A2-----------------------2     | B1    | B2-----------------------3     | C1    | C2-----------------------

Now I do double click with the mouse on any line then I can find out which line one was selected so thats clear so far for me but how to check now which field was clicked to find out which field belongs to which row etc you know what I mean right.So if I click on field 1 / Row 1 then I should get results for iItem = 0 and iSubItem = 0 or field C1 iItem = 2 & iSubItem = 1 etc.I tried already to play with the LV_HITTESTINFO struct but anyhow does it not work for me.

local LVH:LV_HITTESTINFO...	.elseif eax == WM_NOTIFY	        mov edi, lParam	        mov eax, (NMHDR ptr [edi]).code	        .if eax == NM_DBLCLK	        	            invoke SendMessage,hListView,LVM_GETNEXTITEM,-1,LVNI_SELECTED	            mov edi, eax	            	            invoke GetCursorPos,addr point	            mov eax, point.x	            mov ecx, point.y	            mov LVH.pt.x, eax	            mov LVH.pt.y, ecx	            mov LVH.flags,LVHT_ONITEMICON or LVHT_ONITEMLABEL or LVHT_NOWHERE	            mov LVH.iItem,edi   ; iItem	            mov LVH.iSubItem,0  ; wanna check first sub	            invoke SendMessage,hListView,LVM_HITTEST,0,addr LVH

First I check which line is selected to get iItem value which I then enter into struct below and as iSubItem I do enter 0 to check whether the first iSubItem was clicked.So can you see the problem above?
 

Thanks

Posted

Do you know the number of columns you have?


You can try using LVM_GETITEMCOUNT, loop through each item and check with LVM_GETITEMSTATE if it is selected and focused ( mask is LVIS_FOCUSED).


  • Like 1
Posted

Hi GaBoR and thanks your reply,


 


so today I found a solution how to get item & subitem which I clicked. :)



; edi my Listview handle mov myLVHitTest.flags, LVHT_ONITEM OR HHT_ONHEADER
invoke GetMessagePos
mov ebx, eax
mov eax,ebx
and eax,0FFFFh
mov myLVHitTest.pt.x, eax
mov eax,ebx
shr eax,10h
mov myLVHitTest.pt.y, eax
invoke ScreenToClient, edi, ADDR myLVHitTest.pt
invoke SendMessage, edi, LVM_SUBITEMHITTEST, 0, ADDR myLVHitTest

Its coolio and working.Yeah.Now I added 2 icons in my columns which does change if I click it like On / Off.Just needed to find out the right subitem on click (wanted 0 for icon change) and the other subitems (Name etc) have other functions like editing etc.Below you can see a small pic of my LV.


 


PS: I tried LVIS_FOCUSED already before but also with that I only get the line xy.


 


greetz


post-27695-0-54649900-1428257392.png

  • 4 weeks later...
Posted

Hi again,


 


short new question about Listview again.


 


1.) How can I disable the autokey function if I press any key on keyboard to prevent jumping to a line which does start with that key xy?


 


Problem: So the problem is I have a LV with three rows and in the first I have stored a counter (1,2,3,etc) for each entry I do add.If I press now any number key then it jumps to the line which has this number (you know what I mean).Normaly its good (also if its working just sometimes) but I wanna use this keyboard keys on the same way just with my LV row two and not for the first row.Is there any way to say the system to do this with row 2 instead row 1?


 


On the other hand I wrote already a code to read the key strokes and to check this with all entry in my LV row 2 + jumping on next if there in loop and its also working so far but the problem here is if I have any number in any entry at row 2 then the system does take again the control and does check row 1 and does jump to a found.So how can I disable this doing by system itself?


 


2.) Problem with command WM_KEYDOWN / WM_CHAR / etc.First I got the problem that this commands was not called in my code so I just use Dialogboxparam call same way as you can see in the template exsample codes Templates\Dialog\Base.asm or bones.asm which are looking something like this..



start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke DialogBoxParam, hInstance, 101, 0, ADDR DlgProc, 0
invoke ExitProcess, eax
; -----------------------------------------------------------------------
DlgProc proc hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD .if uMsg == WM_COMMAND
.if wParam == IDC_OK
; -----------------------------------------------------------------------
; TODO
; -----------------------------------------------------------------------
.elseif wParam == IDC_IDCANCEL
invoke EndDialog,hWin,0
.endif
.elseif uMsg == WM_CLOSE
invoke EndDialog,hWin,0
.endif xor eax,eax
ret
DlgProc endp end start

....the question now is how to get the uMsg commands WM_KEYDOWN in this DlgProc routine if I press any key?So it will not work.So is there any method to get also the WM_KEYDOWN message directly in this DlgProc routine (calling any API before etc) without to create a another extra routine with any GetMessage / TranslateMessage loop?Thats all so far for the moment.Maybe you can help to answer my questions. :)


 


Thank you


Posted

To catch WM_KEYDOWN while listview has focus, u have to subclass it via SetWindowLong() api. from here u can define custom behavior on keypress events inside listview. works for me


 


ps - for your post #92, this is a better solution. u also have to use this way (read structs from stack) when painting custom backgrounds & controls to listview


 


if [edi].code == NM_DBLCLICK
                MOV EAX, DWORD PTR SS:[EBP+14h]
                MOV DWORD PTR SS:[EBP-174h], EAX
                MOV EAX, DWORD PTR SS:[EBP-174h]
                MOV EAX, DWORD PTR DS:[EAX+12d]
                MOV Row, EAX ; store row number
                
                MOV EAX, DWORD PTR SS:[EBP-174h]
                MOV EAX, DWORD PTR DS:[EAX+10h]
                MOV Column, EAX ; store column number

Posted

Hi again,


 


how and why to subclass it?Sounds a little bit strange that I have to do this just only to catch WM_KEYDOWN in a other procedere.So gets the main provedere not the WM_KEYDOWN or any others WM_xy as all other WM_SIZE WM_whatever etc?


 


Next problem is that I then have to subclass all Listviews which gets created (they are created dynamic if user wanna have a new from 1 - endless) so how should I do this then?You know what I mean right?Sounds again like much work just to get this WM_X. :( Is there no other simple way?


 


PS: So normaly I don't wanna use any asm commands if I can also use direct struct word commands. :)


 


Question: Is there no way to create any procedere somewhere at the end which does do some stuff to get all WM_xy etc?Normaly I don't wanna create this GetMessage / Tansl.../ IsDialogm.. loop thing at the top and I don't wanna use CreateDialogParam.


 


Thanks again for your answer so far and maybe you have some more ideas for me next time.


 


greetz


Posted

Hi again,


 


so I can't subclass all LVs which the user does add & delete on that way just to get this WM_KEYDOWN message.So is there not other simple way?Its already strange that not all message commands will send to my main proc.I think I have no choice and need to use this stupid loop stuff. :(


 


Yes I have seen C does also use this switch / case stuff (ASM too) so this I like to use.


 


greetz


Posted

so I can't subclass all LVs which the user does add & delete on that way just to get this WM_KEYDOWN message.So is there not other simple way?Its already strange that not all message commands will send to my main proc.

All "message commands" will get send to your windows callback handler . if you dont handle them , they will get passed back to windows (it has a default handler for it which process most of the message). You need to check them. Do you need to check all the messages ? mostly not. here comes optimization ,instead of ifelse, compiler uses switch to jump over the required handler .

About your WM_KEYDOWN , its a state of the keyboard messages. Means at any instance when a keyboard input is send, they key can be either down or up or being hold . You can check that for any keyboard message You just need to differentiate from the input messages and use mask to check the bits . 

This explains the idea a bit 

 

https://www-user.tu-chemnitz.de/~heha/petzold/ch06c.htm

 

Unfortunately, how they handle the message inside the kernel isnt documented and i have very scarce idea about it . I will request you to switch over to higher level languages as in the world of gui programming, they dont really care about the performance and rather focus on the functionality they provide (trying to minimize the performance impact without losing the benefits of new features) . You will end up having to code thousand lines of raw asm if you need a good implementation or a buggy gui if you try to do a minimal coding.

Posted

Maybe useful to note, you can let windows execute the default handler by returning False... (even if you already executed your code)

Posted (edited)

That's not really correct Conquest, each "message command" gets sent to a certain hWnd. They don't all get send to 1 place (besides frame/border/x buttons, dont think there's any "default handler" either).Each control has it's own hWnd - each hWnd has it's own callback handler.If I SendMessage(ListViewhWnd, WM_KEYDOWN,..) to ListView control, toplevel hWnd will not see it because they have diff. hWnd, different message handlers (current "problem").In this case, SetWindowLong() (aka subclass) lets the coder change all that EASILY. It can be dynamically subclassed, there are no extra loops, etc.

//globalWNDPROC OriginalListViewCallbackFunction;LRESULT ListViewCustomHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){   switch (msg)   {      case WM_KEYDOWN:           MessageBox(NULL, "i get shown when listview has focus", "it took a whole 11 extra lines of C...", MB_ICONEXCLAMATION | MB_OK);         }   return CallWindowProc(OriginalListViewCallbackFunction, hWnd, msg, wParam, lParam);}LRESULT CALLBACK WndProcMainWindow(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){        case WM_CREATE:        {                  HWND ListViewHandle = CreateWindowEx (NULL, WC_LISTVIEW, NULL, WS_VISIBLE | WS_CHILD | LVS_REPORT | WS_BORDER , 10, 120, 230, 20, hwnd, (HMENU) 5, GetModuleHandle(NULL), NULL);             OriginalListViewCallbackFunction = (WNDPROC)SetWindowLongPtr(ListViewHandle, GWLP_WNDPROC, (LONG_PTR)ListViewCustomHandler);             break;        }        case WM_KEYDOWN:        {             MessageBox(NULL, "me and other controls like listview", "dont share msg handlers, so i only get shown when parent hwnd has focus", MB_OK);             break;        }}

 

ps - I'm not an expert, but I don't think the kernel has much to do w/GUI stuff. key/mouse move/press events start as IRP as scancodes, converted to virtual key codes, sent to user space via SendMessage based on mouse position, window focus, etc. Apart from native control's default msg handler, unhandled messages should just die on the stack.pss - Qt is the way. Look at x64dbg, very high quality GUI w/main window in < 1k lines of code. It's not much less work than winapi, but it looks 10x better, no performance loss. only downside is ~3mb exe's, imo small price.

 

edit - I hear delphi has a pretty easy to use GUI framework that keeps everything in native code too

Edited by simple

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...