Hmm I noticed a bug in my code which I never had before when using it so I'll have to figure out what it is yet.. I'll post the correct code soon.

Thomas
Posted on 2001-11-11 03:30:43 by Thomas
I already found it.. if that wasn't soon :)


RestrictWindowSize PROTO STDCALL :DWORD, :DWORD, :DWORD, :DWORD
;===============================================================================
; Restrict Window Size
;===============================================================================
; Place this procedure in the WM_SIZING handler (and pass wParam & lParam)
;
; Written by Thomas Bleeker [exagone]. [url]http://exagone.cjb.net[/url]
;
RestrictWindowSize proc wParam:DWORD, lParam:DWORD, minWidth:DWORD, minHeight:DWORD
; wParam contains a WMSZ_? constant indicating which edge is being
; resized. lParam is a pointer to a RECT structure with the new
; size of the window.
mov ecx, wParam
mov edx, lParam
assume edx:PTR RECT

; --- get height ---
mov eax, [edx].bottom
sub eax, [edx].top

; --- Check if height is less than minHeight ---
sub eax, minHeight
.IF SIGN?
; --- Yes, so ajust size ---
.IF ecx==WMSZ_TOP || ecx==WMSZ_TOPLEFT || ecx==WMSZ_TOPRIGHT
add [edx].top, eax ;note that eax is negative here (height-minHeight)
.ELSE
sub [edx].bottom, eax ;same here
.ENDIF
.ENDIF

; --- get width ---
mov eax, [edx].right
sub eax, [edx].left

; --- Check if width is less than minWidth ---
sub eax, minWidth
.IF SIGN?
; --- Yes, so ajust size ---
.IF ecx==WMSZ_LEFT || ecx==WMSZ_TOPLEFT || ecx==WMSZ_BOTTOMLEFT
add [edx].left, eax ;note that eax is negative here (width-minWidth)
.ELSE
sub [edx].right, eax ;same here
.ENDIF
.ENDIF
assume edx:nothing
ret
RestrictWindowSize endp


Thomas
Posted on 2001-11-11 03:33:29 by Thomas
Thomas,

I liked your idea so I implemented it as two macros so that width and height could be controlled seperately. The attached file has the two macros which I have added to the macros.asm file in MASM32.

Regards and thanks.

hutch@movsd.com
Posted on 2001-11-12 03:23:01 by hutch--
I require ExitWindowsEx example in next version.
There is now one in Example1 directory (Qexit) and
source code section WindowShutdown.

But the problem is that tey don't ask right's do do so.
So they fail in XP/NT/W2K computers.

I try to convert ty C code to asm, but it isin't
was big suprice that it cracsh every time.
Posted on 2001-11-12 18:13:10 by Torak
Torak,

Operating system specific code is not really what the examples are about, if you wish to run this type of code on NT4, Win2k or XP, you will need to know how to set the access rights in the specific version you are using. From memory this access is only for Administrators so you will have to set up your version to do this.

Regards,

hutch@movsd.com
Posted on 2001-11-12 22:12:17 by hutch--
http://jkoontz.com/cgi-bin/load.cgi?asm/shutdown.zip

This simple example shows how to shutdown the computer in nt/2k/xp.
Good day
Posted on 2001-11-13 01:46:07 by Betrayed
; Get Priviledge for current process

getpriviledge proc, prvlig
local htoken, tkp:TOKEN_PRIVILEGES

; Open a token for current process.
invoke GetCurrentProcess
mov edx, eax
invoke OpenProcessToken, edx,
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, addr htoken

; Get the LUID for the passed privilege.
invoke LookupPrivilegeValue, 0, prvlig, addr tkp.Privileges[0].Luid;
mov tkp.Privileges[0].Attributes, SE_PRIVILEGE_ENABLED;
mov tkp.PrivilegeCount, 1
invoke AdjustTokenPrivileges, htoken, FALSE, addr tkp, 0, 0, 0
hclose htoken
ret
getpriviledge endp


To get shutdown priviledge:

invoke getpriviledge, "SeShutdownPrivilege"
Posted on 2001-11-13 02:11:03 by gfalen
Oops- that "hclose" should be CloseHandle
Posted on 2001-11-13 02:18:57 by gfalen
Wow, that code looks freaky :). But what's this deal about AdjustTokenPrivileges?
Can it be used to get any privileges, and thus overriding nt/2k security
(I think/hope not...) And if not, why is it required to shut down the system?
Posted on 2001-11-13 07:13:40 by f0dder
Yeah fodder, I guess the code seems a little strange. I use a lot of macros and I forgot to convert to pure masm syntax when posting.

The "hclose htoken" is actually - invoke CloseHandle, htoken

and of course you can't pass a literal string to invoke getpriviledge!


As for the AdjustTokenPrivileges, what can I say? That's how it works.
Check out the docs.
Posted on 2001-11-13 13:12:17 by gfalen
hi there...

in the attached zip you'll find 3
(more or less) "usefull" progs...
the interesting parts in those progs are
commented.

the zip contains:

custom_shape - ... without unreferenced vars :)
win_cgi - cgi via win32asm
port_code - "nonstandart code" ;)

hope you'll like it...
thank you

drcmda now mob who cares
Posted on 2001-11-15 11:23:03 by mob
mob,

Thanks for the additional examples, I will download them and have a look at them a bit later. They sound like interesting stuff.

LATER: Compliments on the technology in the noimports asm file, this is clever technology, shape demo works well and the cgi data and file are very useful.

Huh,

Will you email me with your preferred name and email address so I can put the credit for the macro you designed in the macro file in MASM32. I have also incorporated its variation into the Prostart code wizard so it a good idea for people to know who designed it in the first place.

Regards,

hutch@movsd.com
Posted on 2001-11-15 16:48:02 by hutch--
There's a little point that's very important. You *MUST* import
kernel32, or something that ends up importing it, if you want to
run under all win32 versions.

For k32 scanning, it's okay to use the value that's initially at ,
it works on all win32 versions I know of. You should align the address
to 4k before scanning backwards though. You can probably align
to 64k, because that's the alignment you get on virtualalloc... but to
be a bit more safe, use 4k alignment and scanning.

Even better, since you need at least one import from kernel32, make
that kernel32!exitprocess (that way you can exit cleanly if you aren't
able to find k32 base), and use the exitprocess addy to scan back,
instead of the value-on-stack.

The importing method could also be done a bit more elegantly,
but that's not as important :).
Posted on 2001-11-15 17:40:40 by f0dder
Hutch, if you want it, I have a little piece of code that shows how
to interface with htmlhelp, subclass an edit control, and do some
custom window drawing. It's in C right now, but it shouldn't be too
much of a problem for me to convert it to assembler.
Posted on 2001-11-15 17:41:44 by f0dder
fodder, do you really think that i waste my time
just to write "the perfect" messagebox? in this
time i work on my newest project, a procpatcher
so i just wanted to give a example on how to
write portable code so no imports needed here.
and sure the routines are very "unoptimized" :)
thery're a year old i think, i wrote them in full
learning-by-doing mode... i'll clean them up in
the next time...

ahm hutch, gfx makes more fun than i ever dreamed
of right now so here's my newest work, my own
version of a region creation routine...

bye
Posted on 2001-11-15 19:15:38 by mob
Cute...


Hey Hutch, just a heads up... I will e-mail you the OOP stuff tomorrow night sometime... (only time this week that i have available).. Thanx for your patience..

nAn
Posted on 2001-11-15 19:31:10 by NaN
mob, I was just offering advice on how to make your code work on
all win32 versions...

and the "The importing method could also be done a bit more elegantly,
but that's not as important ." was said with a smile, indicating that
indeed that part isn't as important as the rest.

Ok, if your code fragment is going to be injected, you don't have
to worry about kernel32 import. But just as much as I was commenting
on your code, I was reflecting (or whatever) on how you have to
do it in general.

Please take it as constructive criticism, mm'kay? I spent quite some
hours debugging weird code because of the kernel32 import issue,
and I wouldn't want other people to go through that if I can help
them not to with a few simple lines of text =).
Posted on 2001-11-15 19:39:19 by f0dder
Nan,

Thanks for the update, I am just starting to put the install together so the timing looks good.

Mob,

I just added the later one as well, thanks for contributing these examples, they are interesting technology.

Regards,

hutch@movsd.com
Posted on 2001-11-15 22:56:57 by hutch--
f0dder,

There is already a tool in MASM32 for subclassing any control but the code to interface with htmlhelp would be a good example that people who like the later help file format would find useful, if you can pop this one reasonably quickly, I would like to see it.

Regards,

hutch@movsd.com
Posted on 2001-11-15 23:00:05 by hutch--
Hi ,hutch,
I studied masm32 first when I attached Windows programming
and think it's very helpful to give me a way understanding widnows programming fastly,Thanks for your masm32 environment first.
I have written some small progs and put it in my homepage http://www.jingtao.org. The "once-app" and "asm-cut" were both written in masm32 and I think them very interstring although they may have several errors.
smallwaves.
Posted on 2001-11-16 05:36:35 by smallwaves