Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[ARCHIVED THREAD] SciTE4AutoHotkey v2 Stable - Released.


  • This topic is locked This topic is locked
154 replies to this topic
fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

What errors are there to detect? You shouldn't be passing it an invalid window handle; if in doubt, use IsWindow. (Edit: I see you already do.)

I've finished adding the IsHungAppWindowProc() checking and replacing
SendMessageTimeout() with a regular SendMessage(), so this is finished :)
// SciTE4AutoHotkey v2 LUA message pumper 1.0
// Build with: gcc -shared -o module.dll -I..\lualib\src main.c scite.la
// You've got to have a LUA distribution at ..\lualib (creates the src folder)
// for this to work.
// Also copy the scite.* files from http://luaforge.net/frs/download.php/3293/scite-debug.zip (scite.la, scite.def and scite.lib)

// Includes
#include <windows.h> // Windows include
#include "lauxlib.h" // LUA include

// Some defines
#define DllExport __declspec(dllexport)
#define RET_OK 1
#define RET_FAIL 0
#define MAX_TITLE 255
#define ADDFUNC(a) lua_register(L, #a, lib_##a)

// Those defines may not be present
#ifndef PROCESS_VM_OPERATION
#define PROCESS_VM_OPERATION 0x0008
#endif
#ifndef PROCESS_VM_READ
#define PROCESS_VM_READ 0x0010
#endif
#ifndef PROCESS_VM_WRITE
#define PROCESS_VM_WRITE 0x0020
#endif
#ifndef MEM_COMMIT
#define MEM_COMMIT 0x1000
#endif
#ifndef PAGE_READWRITE
#define PAGE_READWRITE 4
#endif
#ifndef MEM_RELEASE
#define MEM_RELEASE 0x8000
#endif

// Global variables
HWND cWindow = 0, tWindow = 0;
const char* cWinTitle; // variable pointer to constant char

// For IsHungAppWindowProc()
typedef BOOL (*IWAPtype)(HWND);
IWAPtype IsHungAppWindowProc;

// Dummy function that always returns false
BOOL _lib_ishungapp(HWND hWnd){ return 0; }

// Initializes the IsHungAppWindow() function.
void _lib_initprocs(){
	HMODULE user32 = LoadLibrary("user32");
	IsHungAppWindowProc = (IWAPtype) GetProcAddress(user32, "IsHungAppWindow");
	if(!IsHungAppWindowProc)
		IsHungAppWindowProc = (IWAPtype) _lib_ishungapp;
}

// Private callback function to enumerate the windows.
BOOL CALLBACK _lib_winsearchproc(HWND hWnd, LPARAM lParam){
	char wTitle[MAX_TITLE+1];
	// Get window title
	GetWindowText(hWnd, wTitle, MAX_TITLE);
	if(!strncmp(wTitle, cWinTitle, lParam)){
		// Window found.
		cWindow = hWnd;
		return 0; // Cancel the enumeration
	}
	return 1; // Continue enumerating the windows
}

// localizewin(wintitle) -- Localizes the window with the specified window title to
//  further send messages to it. True = sucess, false = failure.
int lib_localizewin(lua_State* L){
	// set the global variables
	cWinTitle = luaL_checkstring(L, 1);
	tWindow = cWindow, cWindow = 0;

	// look for the window
	EnumWindows((WNDENUMPROC)_lib_winsearchproc, strlen(cWinTitle));
	if(!cWindow){ // no window found?
		// just restore the old window and return false.
		cWindow = tWindow;
		lua_pushboolean(L, RET_FAIL);
		return 1;
	}
	// return true.
	lua_pushboolean(L, RET_OK);
	return 1;
}

// pumpmsg(msg, wparam, lparam) -- Sends a message to the current window.
//  Timeout of 8 seconds. It returns the value that the window returns.
int lib_pumpmsg(lua_State* L){
	// get the parameters
	int iMsg = luaL_checkint(L, 1);
	int wParam = luaL_checkint(L, 2);
	int lParam = luaL_checkint(L, 3);

	if(!IsWindow(cWindow)) // invalid window?
		return luaL_error(L, "Invalid window handle.");
	if(IsHungAppWindowProc(cWindow))
		return luaL_error(L, "The window appears to be hung. Aborting...");

	// just dispatch the message to the window
	int result;
	result = (int) SendMessage(cWindow, (UINT)iMsg, (WPARAM)wParam, (LPARAM)lParam);
	
	// return the number that the window gave to us
	lua_pushnumber(L, result);
	return 1;
}

// pumpmsg(msg, wparam, lparam) -- Sends a message with lparam as string to the current window.
//  Timeout of 8 seconds. It returns the value that the window returns.
int lib_pumpmsgstr(lua_State* L){
	// get the parameters
	int iMsg = luaL_checkint(L, 1);
	int wParam = luaL_checkint(L, 2);
	const char* lParam = luaL_checkstring(L, 3);
	// get the string length
	int lParamSize = strlen(lParam);

	if(!IsWindow(cWindow)) // invalid window?
		return luaL_error(L, "Invalid window handle.");
	if(IsHungAppWindowProc(cWindow))
		return luaL_error(L, "The window appears to be hung. Aborting...");

	// inject the string at the process.
	DWORD pID;
	GetWindowThreadProcessId(cWindow, &pID);
	HANDLE hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, 0, pID);
	if(!hProcess)
		return luaL_error(L, "Couldn't open the memory of the window!");
	void* rlParam = VirtualAllocEx(hProcess, 0, lParamSize, MEM_COMMIT, PAGE_READWRITE);
	if(!rlParam)
		return luaL_error(L, "Couldn't allocate the memory at the window!");
	if(!WriteProcessMemory(hProcess, rlParam, lParam, lParamSize, NULL))
		return luaL_error(L, "Couldn't inject the string parameter at the window!");

	// just dispatch the message to the window
	int result;
	result = (int) SendMessage(cWindow, (UINT)iMsg, (WPARAM)wParam, (LPARAM)lParam);

	// free the memory used by the string
	if(!VirtualFreeEx(hProcess, rlParam, 0, MEM_RELEASE))
		return luaL_error(L, "Failed to free the memory at the window!");
	if(!CloseHandle(hProcess))
		return luaL_error(L, "Couldn't close the process handle!");

	// return the number that the window gave to us
	lua_pushnumber(L, result);
	return 1;
}

int DllExport libinit(lua_State* L){
	// initialize the IsHungAppWindowProc() function
	_lib_initprocs();
	// add the following functions to the LUA engine
	ADDFUNC(localizewin);
	ADDFUNC(pumpmsg);
	ADDFUNC(pumpmsgstr);
	return 0;
}


fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007
Ok, I'm making a new toolbar for SciTE4AutoHotkey v2 that uses the
code that Lexikos provided me in conjunction with the Toolbar module by
majkinetor:
Posted Image
And now a random screenshot showing a pre-Stable private build running on Windows 98:
Posted Image
:)

Talisman2
  • Members
  • 16 posts
  • Last active: Jan 07 2011 08:58 AM
  • Joined: 27 Nov 2008
I prefer a command-line approach to editors, hence, I prefer a black background...
If you do too, replace your ahk.style.properties file innards with the following:

# Syntax-highlighting properties for AutoHotkey scripts
# Putting this in a separate file makes it easier to replace
# and mantain
#
# March 1, 2009 - fincs
#

# The current line
caret.line.back=#444444

# Base (background, base font)
style.ahk1.32=back:#030003,font:Courier New

# Default (everything not below: spaces, untyped parameters)
#style.ahk1.0=fore:#707070,bold
style.ahk1.0=fore:#8f8f8f,bold

# Line comment (; syntax)
#style.ahk1.1=fore:#008000,italics
style.ahk1.1=fore:#ff7fff,italics

# Block comment (/*...*/ syntax)
#style.ahk1.2=fore:#406040,italics
style.ahk1.2=fore:#bf9fbf,italics

# Escape (`x)
#style.ahk1.3=fore:#FF8000,bold
style.ahk1.3=fore:#007fff,bold

# Operator
#style.ahk1.4=fore:#7F200F,bold
style.ahk1.4=fore:#80dff0,bold

# Expression assignement operator
#style.ahk1.5=fore:#FF4F00,bold
style.ahk1.5=fore:#00b0ff,bold

# String
#style.ahk1.6=fore:#404040,bold
style.ahk1.6=fore:#bfbfbf,bold

# Number
#style.ahk1.7=fore:#2F4F7F,bold
style.ahk1.7=fore:#d0b080,bold

# Identifier (variable & function call)
# Not used by the lexer but by the style below and by hotkeys
#style.ahk1.8=fore:#CF2F0F
style.ahk1.8=fore:#30D0F0

# Variable dereferencing %varName%
#style.ahk1.9=$(style.ahk1.8),back:#E4FFE4,bold
style.ahk1.9=$(style.ahk1.8),back:#1B001B,bold

# Label & Hotstrings (& Function definition?). Also defines a bit of style for hotkeys.
#style.ahk1.10=fore:#000000,back:#FFFFA1
style.ahk1.10=fore:#FF00FF,back:#00005e

# Keyword - Flow of control
#style.ahk1.11=fore:#480048,bold,italics
style.ahk1.11=fore:#B7FFB7,bold,italics

# Keyword - Commands
#style.ahk1.12=fore:#004080,bold
style.ahk1.12=fore:#FFBF7F,bold

# Keyword - Functions
#style.ahk1.13=fore:#0F707F,italics
style.ahk1.13=fore:#F08F80,italics

# Keyword - Directives
#style.ahk1.14=fore:#F04020,bold,italics
style.ahk1.14=fore:#0FBFDF,bold,italics

# Keyword - Keys & buttons
#style.ahk1.15=fore:#FF00FF,bold
style.ahk1.15=fore:#00FF00,bold

# Keyword - Built-in Variables
#style.ahk1.16=fore:#CF00CF,bold,italics
style.ahk1.16=fore:#30FF30,bold,italics

# Keyword - special parameters ("Keywords")
#style.ahk1.17=fore:#0000FF
style.ahk1.17=fore:#FFFF00

# Keyword - User defined
#style.ahk1.18=fore:#800020,bold
style.ahk1.18=fore:#7FFFDF,bold

# Variable keyword (built-in) dereferencing %A_xxx%
#style.ahk1.19=$(style.ahk1.16),back:#F9F9FF
style.ahk1.19=$(style.ahk1.16),back:#060600

# Error (unclosed string, unknown operator, invalid dereferencing, etc.)
#style.ahk1.20=back:#FFC0C0
style.ahk1.20=back:#003F3F

Note: I've commented out all the original fincs style entries, so if you don't like something, change it back.

Moru
  • Members
  • 43 posts
  • Last active: Mar 07 2012 01:58 PM
  • Joined: 24 Mar 2009
For me: The best one

Thanks a lot !!

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

For me: The best one

Thanks a lot !!


You're welcome :)

Montu
  • Members
  • 142 posts
  • Last active: Jan 01 2010 03:10 AM
  • Joined: 11 Feb 2009
I love this software but,

How canI can setup the default text zoom level to 150% in your program?

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

I love this software but,

How canI can setup the default text zoom level to 150% in your program?


I found this on the SciTE documentation:

magnification - Sets the initial magnification factor of the edit pane. This is useful when you want to change the size of text globally, such as after changing the screen resolution without having to touch every style setting. 0 is default, negative values makes the size smaller and positive values make it larger.


So what you have to do is add the following line:
magnification = put number here
to the SciTEGlobal.properties file.

Montu
  • Members
  • 142 posts
  • Last active: Jan 01 2010 03:10 AM
  • Joined: 11 Feb 2009

I love this software but,

How canI can setup the default text zoom level to 150% in your program?


I found this on the SciTE documentation:

magnification - Sets the initial magnification factor of the edit pane. This is useful when you want to change the size of text globally, such as after changing the screen resolution without having to touch every style setting. 0 is default, negative values makes the size smaller and positive values make it larger.


So what you have to do is add the following line:
magnification = put number here
to the SciTEGlobal.properties file.



thanks it wokred,
go to Option > User Options file
there is already magnification =1 line in it
I changed it to =2
and it works great!

tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
I was wondering how to change the caret color.
for the dark theme, it is quite hard to see where it is.

Great app BTW.

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


Charon the Hand
  • Members
  • 8 posts
  • Last active: Feb 24 2010 02:16 AM
  • Joined: 07 Aug 2007
Thank you very much for putting this all together, Fincs. After years of using jujuedit, I finally made the plunge to a new editor,
and it's splendid. I had only one problem, which I finally solved after hours of puttering around. I thought I would share the
solution, in case anyone else was as annoyed as I was.

When using 'Go' (F5) on a persistent script, SciTE would just wait for the script to end, which it never does. To relaunch the
script with changes, I would have to manually stop the old instance. Of course, the solution is so simple, it took me forever
to figure out. Just add this line: 'command.go.subsystem.$(file.patterns.ahk)=2' in the ahk.properties file and SciTE will make
the 'Go' command available at all times, instead of greying it out while a script is running.

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

Thank you very much for putting this all together, Fincs. After years of using jujuedit, I finally made the plunge to a new editor,
and it's splendid. I had only one problem, which I finally solved after hours of puttering around. I thought I would share the
solution, in case anyone else was as annoyed as I was.

When using 'Go' (F5) on a persistent script, SciTE would just wait for the script to end, which it never does. To relaunch the
script with changes, I would have to manually stop the old instance. Of course, the solution is so simple, it took me forever
to figure out. Just add this line: 'command.go.subsystem.$(file.patterns.ahk)=2' in the ahk.properties file and SciTE will make
the 'Go' command available at all times, instead of greying it out while a script is running.


Oh, thanks a lot! I was also being annoyed by that behavior :p

almex
  • Members
  • 10 posts
  • Last active: Aug 25 2009 08:10 PM
  • Joined: 16 Oct 2007
Excellent work, fincs!

JohnnyTwoTone
  • Members
  • 45 posts
  • Last active: Mar 29 2011 02:51 AM
  • Joined: 10 May 2009
increased my productivity a LOT.

thanks a lot.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I've finally posted a link to SciTE4AutoHotkey on the download page.

So that users have a place to post feedback, you might consider linking from <!-- w -->www.autohotkey.net/~fincs/SciTE4AutoHotkey_2/web/<!-- w --> to this topic here.

Thanks for all the work that went into this impressive project.

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

I've finally posted a link to SciTE4AutoHotkey on the download page.

So that users have a place to post feedback, you might consider linking from <!-- w -->www.autohotkey.net/~fincs/SciTE4AutoHotkey_2/web/<!-- w --> to this topic here.

Thanks for all the work that went into this impressive project.

Oh, what an honor! :oops:
I will link to this topic, don't worry :D

EDIT: Linking done.