Win32 Tips/Techniques for MASM Part #2 by `Ates (ates@anet.net.tr)
Q1. How can i set/kill a timer to my program ?
Q2. How can i get username of current user ?
Q3. How can i convert integer to string and show them using MessageBox ?
Q4. How can i change/set the cursor speed ?
Q5. How can i switch mouse buttons ?
Q6. How can I make Stay On DOWN Windows ?
Q7. How can i set the monitor to power-save mode ?;
Q8. How can i change the appearance of a forms caption bar from active to inactive (flashing)?
Q9. How can i download a file from Internet ?
Q10. How can i run ScreenSaver with code ?
Q11. How can i bring Applets in Control Panel with code ?
Q12. How can i move a window without using caption bar ?
Q13. How can i change Screen Resolution ?
Q14. How can i change Wallpaper ?
Q15. How can i disable Close in a window or my window ?
- How can i set/kill a timer to my program ?
invoke SetTimer, hWin, NULL, 3000, NULL ; 3000 ms = 3 secs
.if uMsg == WM_TIMER
; Timer triggers here
invoke KillTimer, hWin, NULL ; Kill timer here else it continues
- How can i get username of current user ?
.data
lpBuffer db 127 dup (?)
nSize dd sizeof lpBuffer
mcap db UserName",0
.code
invoke GetUserName, addr lpBuffer,addr nSize
invoke MessageBox,hWin,addr buffer, addr mcap, MB_OK
<TOP>
- How can i convert integer to string and show it using MessageBox() ?
.data
mystr db 10 dup(?)
myint dd 15
caption db "Convertion Example",0
format db "%d",0
invoke wsprintf, addr mystr, addr format, myint
invoke MessageBox, NULL, addr mystr, addr caption, MB_OK or MB_ICONINFORMATION
- How can i change/set cursor speed ?
invoke SetCaretBlinkTime, 1F4h ; sets it to 500 ms
- How can I switch mouse buttons ?
invoke SystemParametersInfo, SPI_SETMOUSEBUTTONSWAP, 1, NULL, NULL
invoke SystemParametersInfo, SPI_SETMOUSEBUTTONSWAP, 0, NULL, NULL ; For default
- How can I make stay on DOWN windows ?
.if uMsg == WM_CREATE
invoke SetWindowPos, hWin, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE
.elseif uMsg == WM_WINDOWPOSCHANGED
invoke SetWindowPos, hWin, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE
- How can i set the monitor to power-save mode ?
invoke SendMessage, hWin, WM_SYSCOMMAND, SC_MONITORPOWER, NULL ; Turn monitor off
invoke SendMessage, hWin, WM_SYSCOMMAND, SC_MONITORPOWER, -1; Turn monitor on
- How can i change the appearance of a forms caption bar from active to inactive (flashing) ?
invoke FlashWindow, hWin, TRUE ; hWin is the handle of window to be flashed
- How can i download a file from Internet ?
include \MASM32\INCLUDE\wininet.inc
includelib \MASM32\LIB\wininet.lib
.data
fileUrl db "http://delphi.about.com/library/forminbpl.zip",0
fileSave db "saved.zip",0
msgOk db "Downloaded Success!",0
msgErr db "Download Failed!",0
mcap db "Result",0
.data?
AppName db 127 dup(?)
fHand dd ?
bwrite dd ?
.code
GetInetFile proc
LOCAL Buffer[1024]: BYTE
LOCAL hSession: DWORD
LOCAL hUrl: DWORD
LOCAL Bufferlen: DWORD
invoke GetModuleFileName, hInstance, addr AppName, sizeof AppName
invoke InternetOpen, addr AppName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL
mov hSession, eax
.if hSession == INVALID_HANDLE_VALUE
mov eax, FALSE
ret
.endif
invoke InternetOpenUrl, hSession, addr fileUrl, NULL, NULL, NULL, NULL
mov hUrl, eax
.if hUrl == INVALID_HANDLE_VALUE
mov eax, FALSE
ret
.endif
invoke CreateFile, addr fileSave, GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ,\
NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL
mov fHand, eax
.if fHand == INVALID_HANDLE_VALUE
mov eax, FALSE
ret
.endif
invoke SetFilePointer, fHand, NULL, NULL, FILE_BEGIN
download:
invoke InternetReadFile, hUrl, addr Buffer, sizeof Buffer, addr Bufferlen
.if Bufferlen != 0
invoke WriteFile, fHand, addr Buffer, Bufferlen, ADDR bwrite, NULL
jmp download
.endif
invoke CloseHandle, fHand
invoke InternetCloseHandle, hUrl
invoke InternetCloseHandle, hSession
mov eax, TRUE
ret
GetInetFile endp
; Call this like...
invoke GetInetFile
.if eax == TRUE
invoke MessageBox, hWin, addr msgOk, addr mcap, MB_OK
.else
invoke MessageBox, hWin, addr msgErr, addr mcap, MB_OK
.endif
- How can i run ScreenSaver with code ?
invoke GetDesktopWindow
invoke PostMessage, eax, WM_SYSCOMMAND, SC_SCREENSAVE, NULL
- How can i bring Applets in Control Panel with code ?
; Exampels of AppletFileNames:
; ---------------------------------------------
; Timedate.cpl : Time and date
; Joy.cpl : Game controlers0
; Telephon.cpl : TAPI
; bdeadmin.cpl : BDE administrator
; odbccp32.cpl : 32 bit ODBC setup
; directx.cpl : DirectX
; Appwiz.cpl : Add and remove programs
; Desk.cpl : Desktop and Screen
; Inetcpl.cpl : Internet
; Intl.cpl : International settings
; Main.cpl : Mouse
; Mmsys.cpl : Multimedia
; Modem.cpl : Modem
; Netcpl.cpl : Network
; Password.cpl : Password
; Powercfg.cpl : Power configuration
; ---------------------------------------------
.data
cplCommand db "rundll32.exe shell32.dll,Control_RunDLL ",0 ; don't forget to put a space after Control_RunDLL
cplName db "Modem.cpl",0
.code
invoke lstrcat, addr cplCommand, addr cplName
invoke WinExec, addr cplCommand, SW_SHOWNORMAL
- How can i move a window without using caption bar ?
; by Iczelion
.elseif uMsg==WM_NCHITTEST
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
.if eax==HTCLIENT
mov eax, HTCAPTION
.endif
ret
- How can i change Wallpaper ?
.data
NewPic db "c:\windows\blah.bmp",0
invoke SystemParametersInfo, SPI_SETDESKWALLPAPER, NULL, addr NewPic, SPIF_UPDATEINIFILE
- How can i disable Close in a window or my window ?
.data?
hwndMenu HMENU ?
.code
invoke GetSystemMenu, hWin, FALSE
mov hwndMenu, eax
Designed By Atilla Yurtseven