Jump to content
Tuts 4 You

Keygen Graphics


Guest Tundra

Recommended Posts

Guest Tundra

I've found a nice-looking keygen background bmp, with name/serial fields included on it.

The problem is, when I add a text field in with WinASM's resource editor, the text field is white and covers up the background bmp. I've gotten rid of the borders, but I want the text field to be transparent. How would I do this?

Also, is it possible to change the font/size of a text field?

Thanks for the help.

Link to comment

To make the background of an EditControl transparent you need to process the WM_CTLCOLOREDIT message. If the text field is readonly, you process WM_CTLCOLORSTATIC instead.

.elseif uMsg==WM_CTLCOLOREDIT

mov eax, lParam

.if eax == hEditName ; handle to edit control

invoke SetBkMode,wParam,TRANSPARENT;Background of Text

RGB TextRed, TextGreen, TextBlue ;eax = Text colour

invoke SetTextColor,wParam, eax ;TextColor

invoke GetStockObject,NULL_BRUSH ;return Transparent text background brush

ret

.endif

Setting the font can be done using the API CreateFont then use

SendMessage, hEditControl, WM_SETFONT, hFont, 0

Check out the parameters for the message WM_SETFONT and API CreateFont

Hope this helps

BTW your post should be in programming & coding

Ziggy

Link to comment
Guest Tundra

hmm, I think there's another problem.

The text field is transparent like I want it, but when I try to delete a character, the character remains on the screen. Its value is deleted in the text field, but it still shows up on the screen. How do I fix this?

Link to comment
hmm, I think there's another problem.

The text field is transparent like I want it, but when I try to delete a character, the character remains on the screen. Its value is deleted in the text field, but it still shows up on the screen. How do I fix this?

After you use SetWindowText to write to the edit control you need to trigger painting by using

invoke InvalidateRect, hWin, addr stRectSerial, 1

stRectSerial can be NULL so the whole window is painted or a Rect structure which just defines the window

area including the edit control. Check out the windows API help.

Ziggy

Link to comment
Guest Tundra

Yay! Text fields work perfectly now!

One last question ;)

I'm trying to add a custom "clickable" button, so I need to be able to display bitmaps from within my code. This is what I have so far:

.elseif uMsg == WM_PAINT
invoke BeginPaint, hWnd, addr ps
invoke LoadBitmap, hInstance, IDB_CLOSE
mov hButton, eax
invoke GetDC, hWnd
mov hdc, eax
invoke CreateCompatibleDC, hdc
mov hMemDC, eax
invoke SelectObject, hMemDC, hButton
invoke GetClientRect, hWnd, addr rect
invoke BitBlt, hdc, 0, 0, rect.right, rect.bottom, hMemDC, 0, 0, SRCCOPY
invoke DeleteDC, hMemDC
invoke EndPaint, hWnd, addr ps

This works fine when used with an empty window; however, I've included my background picture as an image in my .rc file, and the background overlaps the button I'm trying to display. How can I bring my bitmap to the top?

Edited by Tundra
Link to comment

I think your on the wrong bus with this code :D

Custom buttons using bitmaps are coded different way. Take a look at the examples which come with the MASM package. There is a couple of examples of bitmap up/down buttons in there.

If you just want to display a bitmap on a background use something like

invoke StaticBMP,NULL,hWin ,x,y,sx,sy, BitMapResID

mov hStatBMP, eax

invoke LoadBitmap,hInstance,BitMapResID

mov hBMP1, eax

invoke SendMessage,hStatBMP,STM_SETIMAGE,IMAGE_BITMAP,hBMP1

BTW since you are learning by trying things it would be helpful to others to post some code snippets or tutorials you have found useful.

Cheers

Ziggy

Link to comment
Guest Tundra

hmm, after searching around a bit, I found out that masm comes with a procedure to do this.

invoke DisplayBmp, hParent, bmpID, x, y, backgroundID

You have to include masm32.inc and masm32.lib for this to work.

Link to comment

And the code in the MASM library is just basically the same APIs

; ########################################################################

DisplayBmp proc hParent:DWORD,bmpID:DWORD,x:DWORD,y:DWORD,ID:DWORD

LOCAL hModule:DWORD

LOCAL hBmp :DWORD

LOCAL hImage :DWORD

invoke GetModuleHandle,NULL

mov hModule, eax

invoke CreateWindowEx,WS_EX_LEFT,

ADDR stWin,NULL,

WS_CHILD or WS_VISIBLE or SS_BITMAP,

x,y,10,10,hParent,ID,

hModule,NULL

mov hImage, eax

invoke LoadBitmap,hModule,bmpID

mov hBmp, eax

invoke SendMessage,hImage,STM_SETIMAGE,IMAGE_BITMAP,hBmp

mov eax, hImage

ret

DisplayBmp endp

; ########################################################################

end

There is MASM library code for bitmap buttons as well "BmpButton" which is what I thought you were wanting to do.

Cheers

Ziggy

Link to comment

To Ziggy,

Thanks for the information on transparency.

I want to ask 2 questions

1) What exactly does "invoke GetStockObject, NULL_BRUSH" do? What does the parameter mean?

2) In your "KeygenGuide.doc" file, there is a keygen template below the "LAYOUT" title (just before "SIZE" title). It is a "Name/Serial" type keygen. Its editcontrols look as if they are semi-transparent. We can see the background but editcontrols have a different color. How can I make such an editcontrol? If you attach a sample project with the source, it will be more helpful.

Thankz.

Link to comment
1) What exactly does "invoke GetStockObject, NULL_BRUSH" do? What does the parameter mean?

2) In your "KeygenGuide.doc" file, there is a keygen template below the "LAYOUT" title (just before "SIZE" title). It is a "Name/Serial" type keygen. Its editcontrols look as if they are semi-transparent. We can see the background but editcontrols have a different color. How can I make such an editcontrol? If you attach a sample project with the source, it will be more helpful.

1) When you process the CTL_COLOREDIT (or STATIC) message you must return a handle to a brush to paint the background. (You can check out the processing requirements at msdn.microsoft.com). A NULL_BRUSH is just a special brush handle which says "don't paint over the background". So the background looks transparent. You can see at msdn there are a number of other stock objects for particular situations.


/>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_1t10.asp

2) The semi-transparent effect on that particular keygen template has been done in Photoshop. I don't know of any way that windows can provide a semi-transparent editcontrol. It would be possible to overlay another semi-transparent window (same size as the editcontrol) over the background. Then you could use the CTL_COLOUR... processing so the whole effect looks like a semi-transparent editcontrol - but a lot of stuffing around. Photoshop much simpler.

Z

Link to comment

Thanks Ziggy

You suggested Tundra that he should use InvalidateRect function for his problem. With which WM_ message should we process this function?

Link to comment
Guest Tundra

I use it with WM_COMMAND to see when the Name field is updated:

.elseif uMsg == WM_COMMAND

mov eax, wParam

.if ax == IDC_NAME

shr eax, 16

.if ax == EN_CHANGE

; Call generate serial procedure

; InvalidateRect

Link to comment
Thanks Ziggy

You suggested Tundra that he should use InvalidateRect function for his problem. With which WM_ message should we process this function?

You can use InvalidateRect any time you want to trigger painting. Use it as Tundra shows for a name change or maybe after setWindowText for a readonly edit control.

Z

Link to comment

Thanks for your helps.

Tundra your code works well. But it has a problem. When you select some text in the editcontrol and then change the selection by selecting some other text in the same edit control, the first selected text still remains selected with second selected text.(the editcontrol isnt updated during second selection)

Tundra, could you write the whole invalidateRect function call with its parameters? Because I wonder whether you call it to paint the whole application window or just the editcontrol? ( if you repaint the whole application window it flickers :( )

How will we improve this?

Until next time...

Link to comment
Guest Tundra

I do it like this:

invoke SetRect, addr rect, 176, 127, 176+150, 164+15
invoke InvalidateRect, hWnd, addr rect, 1

This way, I only update the name+serial fields (they're right above each other).

And I've noticed the same problem with selecting text, but I haven't found a way around it yet.

Link to comment
Thanks for your helps.

Tundra your code works well. But it has a problem. When you select some text in the editcontrol and then change the selection by selecting some other text in the same edit control, the first selected text still remains selected with second selected text.(the editcontrol isnt updated during second selection)

Tundra, could you write the whole invalidateRect function call with its parameters? Because I wonder whether you call it to paint the whole application window or just the editcontrol? ( if you repaint the whole application window it flickers :( )

How will we improve this?

Until next time...

.elseif (uMsg == WM_CTLCOLOREDIT) || (uMsg == WM_CTLCOLORSTATIC)

invoke GetDlgCtrlID,lParam

.if (ax == IDC_xx)

invoke SetTextColor,[wParam],000000AAh

invoke SetBkMode,[wParam],TRANSPARENT

invoke GetBrushOrgEx,[wParam],ADDR pt ;<--------| LOCAL pt:POINT

xor edi,edi

sub edi,xx ;<--------------------------------| x control position

xor esi,esi

sub esi,xx ;<--------------------------------| y control position

invoke SetBrushOrgEx,[wParam],edi,esi,ADDR pt

mov eax,hbgBrush ;<------------------------| PatternBrush stored in eax

ret

Link to comment
  • 1 year later...

hey guys... I found this thread very helpful but I have one problem...

How do I get it to update ONLY the text box? Currently if I use invoke InvalidateRect, hWnd,NULL,1 - it works fine, but it updating my whole form. So I tried using SetRect - if I place this like it is below, it doesn't work - it's as if nothing is there. If I use SetRect in WM_CTLCOLOREDIT, the text is properly edited, but it is no longer transparent. If I put GetStockObject below the SetRect in WM_CTLCOLOREDIT it keeps the box transparent but does not update the text properly.

I don't really understand why it's doing this - since SetRect should just be setting a region and nothing else?

.elseif uMsg==WM_CTLCOLOREDIT

invoke GetDlgCtrlID,lParam

.if ax == IDC_NAME ; handle to edit control

invoke SetBkMode,wParam,TRANSPARENT;Background of Text

invoke SetTextColor,wParam, 0ffffffh ;TextColor

invoke GetStockObject,NULL_BRUSH ;return Transparent text background brush

;invoke SetRect, addr hName, 114, 39, 114+233, 39+19

ret

.endif

.elseif eax==WM_COMMAND

mov eax,wParam

.if ax==IDC_NAME

shr eax,16

.if ax==EN_CHANGE

; invoke Generate,hWnd

invoke SetRect, addr hName, 114, 39, 114+233, 39+19

invoke InvalidateRect, hWnd, addr hName, 1

;invoke InvalidateRect, hWnd,NULL,1

Link to comment
How do I get it to update ONLY the text box?

invoke InvalidateRect, hName, NULL, TRUE

..for updating only the editbox, if that's what u meant. I didn't read this thread, yet..

Link to comment
How do I get it to update ONLY the text box?

invoke InvalidateRect, hName, NULL, TRUE

..for updating only the editbox, if that's what u meant. I didn't read this thread, yet..

That doesn't seem to work for me?

Should this work?

.elseif eax==WM_COMMAND

mov eax,wParam

.if ax==IDC_NAME

shr eax,16

.if ax==EN_CHANGE

; invoke Generate,hWnd

invoke SetRect, addr hName, 114, 39, 114+233, 39+19

invoke InvalidateRect, hWnd, hName, 1

.endif

That code above keeps it transparent but does not *clear* the text

Edit: I was setting my rect wrong, but it still doesn't work; should be;

invoke SetRect, addr hName, 39, 118, 262, 134

Edit:

SILLY MISTAKE;

this worked fine in EN_CHANGE;

invoke SetRect, addr hName, 39, 118, 262, 134

invoke InvalidateRect, hWnd, addr hName, 1

forgot addr on hName

Edited by zart
Link to comment

invoke InvalidateRect, lParam, 0, true

The last param makes it erase the BG if set to true, dunno if you actually need that...

If I'm not mistaken it can be false as well

true = 1 and false = 0 of course...

Link to comment
  • 2 years later...

Hey, everyone I have been working on a game trainer and found ziggy's post about the edit control transparency most enlightening. However, I have run into a problem with setting the font size properly. I do work with other languages frequently and have checked the win32.hlp API docs and searched Google. Maybe Ziggy could expound on this or someone could tell me whats wrong with my code. Everything works except changing the font. Thanks in advance.

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\user32.lib
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.libDlgProc proto :DWORD,:DWORD,:DWORD,:DWORD.data
addy dd 014890C4h
windowname db '{0xdb637c87}',0
value dd 3D090h
errorCapOne db 'Unable to Find Window',0
errorCapTwo db 'No Such Address',0
pointerVal dd 0000008Ch
font db "Times New Roman".data?
pid dd ?
addressBuffer dd ?
hInstance dd ?
pHandle dd ?
valueBuffer db 40 dup(?)
valueBuffTwo dd ?
hFont dd ?.const
IDD_DLG equ 1001
IDC_EDIT equ 1004
IDC_MONEY equ 1003
IDC_CLOSE equ 1007.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke DialogBoxParam, hInstance, IDD_DLG, NULL, addr DlgProc, NULL
invoke ExitProcess,eax
DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg == WM_INITDIALOG
invoke SetFocus,eax
invoke CreateFont,64,64,0,0,400,0,0,0,OEM_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,DEFAULT_PITCH, addr font
mov hFont,eax
invoke SendMessage,hWnd, WM_SETFONT,hFont,1
.elseif uMsg == WM_CTLCOLOREDIT
invoke GetDlgCtrlID, lParam
.if eax == IDC_EDIT ; handle to edit control
invoke SetBkMode,wParam,TRANSPARENT;Background of Text
invoke SetTextColor,wParam, 000000h ;TextColor
invoke GetStockObject,NULL_BRUSH ;return Transparent text background brush
ret
.endif
.elseif uMsg==WM_COMMAND
mov eax,wParam
.if ax==IDC_EDIT
shr eax,16
.if ax==EN_CHANGE
invoke InvalidateRect, hWnd, NULL, 1
.endif
.elseif eax==IDC_MONEY
invoke FindWindow,addr windowname,NULL
.if eax==0h
invoke MessageBox,NULL, addr errorCapTwo, addr errorCapOne,MB_OK
.endif
invoke GetWindowThreadProcessId,eax,addr pid
invoke OpenProcess,PROCESS_ALL_ACCESS,FALSE,pid
mov pHandle,eax
invoke ReadProcessMemory,pHandle,addy,addr addressBuffer,4,NULL
mov ecx,addressBuffer
mov esi,pointerVal
add ecx,esi
invoke WriteProcessMemory,pHandle,ecx,addr value,4,NULL
invoke GetDlgItemInt,hWnd,IDC_EDIT,0,0
mov valueBuffTwo, eax
invoke ReadProcessMemory, pHandle, addy, addr addressBuffer, 4, NULL
mov ecx, addressBuffer
mov esi,pointerVal
add ecx,esi
invoke WriteProcessMemory, pHandle, ecx,addr valueBuffTwo, 4, NULL
.endif
.if eax==IDC_CLOSE
invoke EndDialog,hWnd,0
.endif
.endif
xor eax,eax
ret
DlgProc endp
end start

Spoke too soon lol sorry. Found out I had to get a handle to the edit control first

With GetDlgItem in the dialog initialization. thanks

Edited by red436
Link to comment

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...