Win32 Tips/Techniques for MASM Part #1 by `Ates (ates@anet.net.tr)
- How can i hide/show taskbar ?
shell db "Shell_TrayWnd",0 ; this is taskbar's ClassName
invoke FindWindow,addr shell,NULL ; Get handle first then hide it.
.if eax != 0
invoke ShowWindow,eax,SW_HIDE ; use SW_SHOW to show it again
.endif
- How can i Disable/Enable/Show/Hide Start Button ?
.data?
buffer db 127 dup(?)
.data
shell db "Shell_TrayWnd",0
sbar db "BUTTON",0
child dd ?
slen dd ?
.code
invoke FindWindow,addr shell,NULL ; Get TrayBar Handle
mov tray, eax
invoke GetWindow,tray, GW_CHILD ; Get Child of Tray Bar if exists
mov child, eax
.if child != 0
invoke GetClassName,child,offset buffer, sizeof buffer ; Get the classname of
Child window
.if eax > 0
invoke lstrlen, offset buffer ; get length of classname
mov slen,eax
invoke CharUpperBuff,offset buffer,slen ; convert to uppercase
invoke lstrcmp,addr buffer, addr sbar ; Compare classname with
BUTTON
.if eax == 0
invoke ShowWindow,child,SW_HIDE ; Hide StartButton
; invoke ShowWindow,child,SW_SHOW ; Show StartButton
; invoke EnableWindow,child,FALSE ; Disable StartButton
; invoke EnableWindow,child,TRUE ; Enable StartButton
.endif
.endif
.endif
- How can i make a real Stay On Top window ?
invoke SetWindowPos,hWin, HWND_TOPMOST,NULL,NULL,NULL,NULL,SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE
- How can i create a hotkey ? like CTRL + ALT + A
.data
hmsg db "HotKey CTRL + ALT + A Works good!",0
hcap db "Hotkey Example",0
.code
.if uMsg == WM_CREATE
invoke RegisterHotKey,hWnd,065h,MOD_CONTROL or MOD_ALT, 041h ; CTRL + ALT + A (041h is 65 - 065h is 101)
.elseif uMsg == WM_HOTKEY
invoke MessageBox,hWin,addr hmsg,addr hcap, MB_OK or MB_ICONINFORMATION
.elseif uMsg == WM_DESTROY
invoke UnregisterHotKey,hWin,065h
invoke PostQuitMessage,NULL
return 0
.endif
- How can i get Windows and System Directory ?
.data
buffer db 50 dup(?)
hCap db "WindowsDirectory",0
.code
invoke GetWindowsDirectory, addr buffer, sizeof buffer ; Getting windows directory into buffer
; invoke GetSystemDirectory, addr buffer, sizeof buffer ; Getting system directory into buffer
invoke MessageBox,hWnd, addr buffer, addr hCap, MB_OK or MB_ICONINFORMATION
- How can I open the Start-menu from my program?
invoke SendMessage,hWnd,WM_SYSCOMMAND,SC_TASKLIST,NULL
- How can i close active program ?
.data
fwin dd ?
.code
invoke GetForegroundWindow
mov fwin,eax
invoke SendMessage, fwin, WM_CLOSE,NULL
- How can i remove caption of my window ?
invoke GetWindowLong,hWnd,GWL_STYLE ; Get current window long
and eax,not WS_CAPTION ; remove WS_CAPTION
invoke SetWindowLong,hWnd,GWL_STYLE,eax ; Set it
- How can i understand if window is in taskbar/visible or not ?
invoke IsWindowVisible,hWin
.if eax == TRUE
; Window is visible here
.else
; Window is invisible here
.endif
.data
mirc db "mIRC32",0
mhand dd ?
.code
invoke FindWindow,addr mirc, NULL ; we are looking for mIRC32
mov mhand,eax
.if mhand != 0 ; got handle ?
invoke ShowWindow,mhand,SW_SHOW ; Shows window
; invoke ShowWindow,mhand,SW_HIDE ; Hides window
.else
; mIRC32 is not working...
.endif
- How can i make a window Windows foreground window ?
invoke SetForegroundWindow, mhand
- How can i restrict CTRL+ALT+DEL,ALT+TAB+CTRL+ESC keys ?
invoke SystemParametersInfo,SPI_SCREENSAVERRUNNING,1,NULL,NULL
; Windows98 only 1 disables 0 enables
- How can i open my default browser or mail program ?
.data
lpPage db "http://win32asm.cjb.net",0
lpMail db "ates@anet.net.tr",0
lpOperation db "open",0
.code
invoke ShellExecute,hWin,addr lpOperation, addr lpPage, NULL, NULL, SW_SHOWNORMAL
invoke ShellExecute,hWin,addr lpOperation, addr lpMail, NULL, NULL, SW_SHOWNORMAL
- How to bring up the network connections dialog using Win32 API ?
include \MASM32\INCLUDE\mpr.inc
includelib \MASM32\LIB\mpr.lib
invoke WNetConnectionDialog,hWnd,RESOURCETYPE_DISK
Designed By Atilla Yurtseven