News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Minimized window

Started by Magnum, March 20, 2011, 07:19:41 PM

Previous topic - Next topic

Magnum

I am trying to modify this to run a batch file when I plug in my thumbdrive.

I think I can figure that part out.

I would like the window minimized if possible.




invoke GetModuleHandle,NULL
mov hInstance,eax

      invoke InitCommonControls
      invoke DialogBoxParam,hInstance,IDD_DIALOG,NULL,addr DlgProc,NULL
      invoke ExitProcess,0

DlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
local dbt_h : DEV_BROADCAST_HDR
local dbt_v : DEV_BROADCAST_VOLUME

      .if uMsg==WM_INITDIALOG

    .elseif uMsg == WM_DEVICECHANGE
            .if wParam == DBT_DEVICEARRIVAL
                   mov ebx, lParam
                assume ebx:ptr DEV_BROADCAST_HDR
                .if [ebx].dbch_devicetype == DBT_DEVTYP_VOLUME
                    invoke SetDlgItemText,hWnd, IDC_INFO,CTEXT ("USB-Drive found")
                    mov edx,lParam
                    assume edx:ptr DEV_BROADCAST_VOLUME
                    invoke GetVolumeName,[edx].dbcv_unitmask
                    push eax
                    invoke wsprintf,offset szBuf,offset szDrivePath,eax,0
                    invoke GetDriveType,offset szBuf
                    .if eax == DRIVE_REMOVABLE
                        invoke Sleep, 1500
                        pop eax
                     invoke SetDlgItemText,hWnd, IDC_INFO,offset szBuf

                    .endif
                    assume edx:nothing
                .endif
                assume ebx:ptr nothing
            .elseif wParam == DBT_DEVICEREMOVECOMPLETE
                    invoke SetDlgItemText,hWnd, IDC_INFO,CTEXT ("USB-Drive Removed")
            .endif
.elseif uMsg==WM_COMMAND

.elseif uMsg==WM_CLOSE
@Exit:
invoke EndDialog,hWnd,0
.else
mov eax,FALSE
ret
.endif
      mov eax,TRUE
ret

DlgProc endp

GetVolumeName proc flag:DWORD
push esi
push ecx
mov ecx, 26
mov esi,flag
@@:
test esi,1h
jnz @f
shr esi,1h
dec ecx
test ecx,ecx
jnz @b
@@:
mov eax,5Bh
sub eax,ecx
pop ecx
pop esi
ret
GetVolumeName endp

Have a great day,
                         Andy

Slugsnack

you can try to minimize it with showwindow() in wm_initdialog

dedndave

you could even hide the window altogether with SW_HIDE
you might try autorun.inf to execute the program
you can even give the drive an icon   :bg
[autorun]
open=setup.exe
icon=setup.exe,0

qWord

which window should be hide? - the console window of your batch, your dialog or windows AutoPlay dialog (for flash drives)?

BTW: their may be an stack corruption while handling the WM_DEVICECHANGE message
FPU in a trice: SmplMath
It's that simple!

Gunner

Also, you will get errors or strange results on some OS's... the dialg proc is a callback function, and you are modifying ebx without saving it first... your proc should be:
DlgProc proc uses ebx hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

Magnum

Quote from: dedndave on March 20, 2011, 09:13:24 PM
you could even hide the window altogether with SW_HIDE
you might try autorun.inf to execute the program
you can even give the drive an icon   :bg
[autorun]
open=setup.exe
icon=setup.exe,0


SP3 disabled autorun.inf files.

Have a great day,
                         Andy

Magnum

Thanks for all the help.

Gunner, I incorporated your suggestion.

There is probably some more stuff that I could cut out that I am not using.

I included a version control block since it might be flagged as suspicious.  :U


Have a great day,
                         Andy

Magnum

There is a new problem.

My window still shows up and takes up space in other windows.

I tried SW_HIDE but no difference.

Is there a way to give it screen co-ordinates that are off screen ?
Have a great day,
                         Andy

Gunner

Quote from: Magnum on March 20, 2011, 11:47:15 PM
There is a new problem.

My window still shows up and takes up space in other windows.

I tried SW_HIDE but no difference.

Is there a way to give it screen co-ordinates that are off screen ?

Sure there is, set the x an y params for MoveWindow with negative values.... but that is ugly....
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

Magnum

Thanks, it makes a very small 4 pixel window that is close to hidden as I could get.

Good enuf.

invoke MoveWindow,hWnd,-23,-24,5,3,TRUE
Have a great day,
                         Andy

Gunner

Quote from: Magnum on March 21, 2011, 12:12:06 AM
Thanks, it makes a very small 4 pixel window that is close to hidden as I could get.

Good enuf.

invoke MoveWindow,hWnd,-23,-24,5,3,TRUE

change -23 and -24 to something like -1000 and it will move the window off screen...  if your window width is 100 and you move it off screen by -23 then you will still see 77 pixels
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

Magnum

I am confused as to what's what here.

Is any of this relate to the co-ordinates in MoveWindow ?

IDD_DLG DIALOGEX 6,5,75,28 ; last 2 are width and height
;                    ^^should match control line value
CAPTION " USB Watcher"
FONT 8,"MS Sans Serif",0,0
STYLE 0x10C808C0
EXSTYLE 0x00000088

BEGIN
  CONTROL "",IDC_EDT2,"Edit",0x50010801,10,5,75,13,0x00000200
;                                            ^^
END
Have a great day,
                         Andy

Gunner

Quote from: Magnum on March 21, 2011, 12:49:55 AM
I am confused as to what's what here.

Is any of this relate to the co-ordinates in MoveWindow ?

IDD_DLG DIALOGEX 6,5,75,28 ; last 2 are width and height
;                    ^^should match control line value
CAPTION " USB Watcher"
FONT 8,"MS Sans Serif",0,0
STYLE 0x10C808C0
EXSTYLE 0x00000088

BEGIN
  CONTROL "",IDC_EDT2,"Edit",0x50010801,10,5,75,13,0x00000200
;                                            ^^
END

No actually it shouldn't... IDD_DLG defines a dialog in the rc file and CONTROL defines just that.... controls in the above example your dialog will have an edit box with left = 10 top = 5 width = 75 and height = 13 ALL measurements are in Dialog Units and NOT pixels as create window is...

the 6 (left) and 5(top) are the coords of your dialog,
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

MichaelW

Quote from: Magnum on March 21, 2011, 12:49:55 AM
Is any of this relate to the co-ordinates in MoveWindow ?

For dialogs that use the system font you can convert from dialog template units to pixel units with the GetDialogBaseUnits function.

Depending on what you are trying to do, you could get the pixel units for the dialog with GetWindowRect, in your WM_INITDIALOG handler.
eschew obfuscation

dedndave

there is probably a better way, but you can use
        INVOKE  GetSystemMetrics,SM_CXSCREEN
        mov     ScnWidth,eax

to get the screen width, set that as the X position value, and use 0 (or any reasonable value) for the Y position value

for normal windows, if you use CW_USEDEFAULT as the X position, the Y position may be SW_HIDE
this applies for overlapped windows created with the WS_VISIBLE style bit set

QuoteIf an overlapped window is created with the WS_VISIBLE style bit set and the x parameter is set to CW_USEDEFAULT,
then the y parameter determines how the window is shown. If the y parameter is CW_USEDEFAULT, then the window
manager calls ShowWindow with the SW_SHOW flag after the window has been created. If the y parameter is some
other value, then the window manager calls ShowWindow with that value as the nCmdShow parameter.