Visit Iczelion's Win32 Assembly Homepage

 Updated at: 14 Sep 2000

Win32 Tips/Techniques for MASM Part #1 by `Ates (ates@anet.net.tr)


Q1. How can i hide/show taskbar ?
Q2. How can i Disable/Enable/Show/Hide Start Button ?
Q3. How can i make a real Stay On Top window ?
Q4. How can i create a hotkey ? like CTRL + ALT + A
Q5. How can i get Windows and System Directory ?
Q6. How can I open the Start-menu from my program ?
Q7. How can i close active program ? 
Q8. How can i remove caption of my window ?
Q9. How can i understand if window is in taskbar/visible or not ?
Q10. How can i hide a window ?
Q11. How can i make a window Windows foreground window ?
Q12. How can i restrict CTRL+ALT+DEL,ALT+TAB+CTRL+ESC keys ?
Q13. Is Windows taskbar's auto hide feature enabled ?
Q14. How can i open my default browser or mail program ?
Q15. How to bring up the network connections dialog using Win32 API ?

- 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 

<TOP>


- 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

<TOP>


- 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

<TOP>


- 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

<TOP>


- 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

<TOP>


- How can I open the Start-menu from my program?

invoke SendMessage,hWnd,WM_SYSCOMMAND,SC_TASKLIST,NULL

<TOP>


- How can i close active program ? 

.data
fwin dd ?

.code
invoke GetForegroundWindow
mov fwin,eax
invoke SendMessage, fwin, WM_CLOSE,NULL

<TOP>


- 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

<TOP>


- 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

<TOP>


- How can i hide a window ?

.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

<TOP>


- How can i make a window Windows foreground window ?

invoke SetForegroundWindow, mhand

<TOP>


- 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

<TOP>


- Is Windows taskbar's auto hide feature enabled ?

.data
AppBar APPBARDATA {} ; {} means use defaults... Thanks to TTom

.code
mov AppBar.cbSize, sizeof AppBar
invoke SHAppBarMessage, ABM_GETSTATE, addr AppBar ; ShellApi command
and eax, ABS_AUTOHIDE
.if eax == TRUE
    ; Taskbar is hidden
.else
    ; Taskbar is not hidden
.endif

<TOP>


- 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

<TOP>


- 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

<TOP>


Designed By Atilla Yurtseven