How do I use SetWindowLong?

BlitzMax Forums/BlitzMax Programming/How do I use SetWindowLong?

xlsior(Posted 2007) [#1]
I'm trying to programmatically change the window settings of other applications, but nothing seemed to be happening. Can anyone shed some light on what I'm doing wrong here?

(I had hoped to get the other app to maximize itself in this example, but nothing appears to be happening)

Just run notepad.exe in the background, this is the window it will try to change.

Global hwnd:Int

Extern "Win32"

	Function FindWindow( lpClassName$z, lpWindowName$z ) = "FindWindowA@8"
	Function FindWindowEx( hwnd1:Int, hwnd2:Int, lpsz1$z, lpsz2$z ) = "FindWindowExA@16"
	Function SetWindowLong:Int(HWND:Int,nIndex:Int,dwNewLong:Int) = "SetWindowLongA@12"
	Function GetWindowLong:Int(HWND:Int,nIndex:Int) = "GetWindowLongA@8"	
End Extern

hwnd=FindWindow( "NotePad", "Untitled - Notepad" )

Print GetWindowLong(hwnd, GWL_STYLE)
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_MAXIMIZE) 
Print GetWindowLong(hwnd, GWL_STYLE)


It does appear to communicate with the application, because if use WS_CHILD instead of WS_MAXIMIZE then the menubar disappears from the notepad session, as expected.

Is there a differeny API call I should be using altogether to maximize/minimize/restore an existing window?

(Note: It appears that the forum is inserting the '\' in the code above as part of its javascript filter... Remove these characters or the code won't even compile)


xlsior(Posted 2007) [#2]
Nevermind -- it looks like it's another API altogether.

Global hwnd:Int

Extern "Win32"

	Function FindWindow( lpClassName$z, lpWindowName$z ) = "FindWindowA@8"
	Function FindWindowEx( hwnd1:Int, hwnd2:Int, lpsz1$z, lpsz2$z ) = "FindWindowExA@16"
	Function SetWindowLong:Int(HWND:Int,nIndex:Int,dwNewLong:Int) = "SetWindowLongA@12"
	Function GetWindowLong:Int(HWND:Int,nIndex:Int) = "GetWindowLongA@8"	
	Function ShowWindow:Int(HWND:Int,nCmdShow:Int) 
End Extern

hwnd=FindWindow( "NotePad", "Untitled - Notepad" )

ShowWindow(hwnd,SW_MAXIMIZE)
Delay 2000
ShowWindow(hwnd,SW_RESTORE)
Delay 2000
ShowWindow(hwnd,SW_MINIMIZE)
Delay 2000
ShowWindow(hwnd,SW_RESTORE)