Authorware UCD Development Big Secret (8)

xiaoxiao2021-03-06  41

Authorware's external message interface

For developing Authorware's UCD, how is the most difficult thing to intercepting Authorware to our useful news, C programmers may not hesitate: Use the hook function, put the message one by one; DEPHI program Members may say: Use the DEPHI message trigger; VB programmers say: Use the window callback function; C Bulider programmer will say: DEPHI brothers say how I will do it; VFP programmer said:? ? ? ? ? ? ? ? ? ? ? ? ? (Is there anything wrong with it?) In fact, for receiving the processing message, Dephi is the best hand. But there are three ways to come together:

1 Using the DEPHI itself Message trigger function But this feature can only be used by the form and control and is not suitable for receiving an external program.

2 Methods using window subclass. That is, the window callback function is used, and the message is received and processed by inserting a legal window process to the specified window.

3 Use the system hook function. The benefits of system hook functions can be monitored for all current applications, you can get the news you want, as far as I know, there is a famous system tool "Keyboard Ghost" to use this technology. The system hook is mainly used to monitor keyboards and mouse messages.

Here, I will explain how to receive messages that processes Authorware through the second and third methods.

One window subclassification technology

When a Windows application is running, the program creates a window process for receiving the processing message. When we want to process a message in the program that is not processed during the program, you can build a window process. Make us handle what we want to handle. For Authorware like a secondary development platform, we cannot take the initiative to compile our window in the Authorware program because we are not Authorware developers, and Authorware is not a visualization program development platform, it is just a multimedia rapid development. Tools, but fortunately it provides an interface to support dynamic connection library DLL, which is UCD, which gives us a good opportunity to do with third-party development tools. Here I will make a brief explanation. How to use window subclassics to intercept the news in Authorware.

The role of this example is: After running the Authorware program has a screen saver.

Analysis: One screenship should have such a feature:

1 It must run full screen, independent of the current resolution, and no title bar, menu bar

2 It must hide the mouse and must be able to recover the mouse after exiting

3 It must be able to respond to the mouse and keyboard message, and the program must be closed after the response

4 It must only run once, can't run two programs at the same time

Here, the third article is the point of reflecting the type of window subclassification technology.

This function implements the code as follows:

Function x_coolscrsav (awparam: awparam_ptr): boolean; stdcall; // cool screensaver

VAR

Oldpoint: tpoint;

ScreenHeight, ScreenWidth: Integer;

OldStyle: longint;

HMENU: THANDLE;

Begin

AwHandle: = awparam.hwnd;

If awfulim.authoring = true kil

Begin

MessageBox (awhandle, 'Please use it after packaging!', 'prompt', MB_OK); // If the current status is currently not running EXIT;

Result: = FALSE;

END;

GetCursorpos (OldPoint);

Oldx: = OldPoint.x;

Oldy: = OldPoint.y; // Get the current mouse pointer position

ScreenHeight: = Screen.height;

ScreenWidth: = Screen.Width; // Using the Screen object to get the current screen width and high

Showcursor (false); // Hide mouse

SystemParametersInfo (SPI_SETSCREENSAVEACTIVE, 0, 0); / / Notification of the system to the system is // running to prevent multiple instances from running

ShowWindow (FindWindow ('shell_traywnd', '', sw_hide); // Hidden Task Bar

OldStyle: = getWindowlong (awhandle, gwl_exstyle);

OldStyle: = OldStyle and not WS_SYSMENU AND NOT WS_CAPTION;

SetWindowlong (awhandle, gwl_style, oldstyle); // remove the title bar and menu bar (if any)

Setwindowpos (awhandle, hwnd_topmost, 0, 0, screenwidth, screenheight, swp_showwindow); // Settings window is full screen

preWndProc: = Pointer (getWindowlong (awhandoor, gwl_wndproc); // Get the original window process pointer

OldWndproc: = Pointer (SetWindowlong (awhan, gwl_wndproc, longint (@newwinproc)); // Set new window procedure

RESULT: = true;

END;

New window process:

Function NewWinProc (Handle: Thandle; MSG, WPARAM, LPARAM: long): longint; stdcall;

VAR

Processid, CPID: cardinal

NEWX, NEWY: Integer;

NewPoint: tpoint;

DX, DY: Integer;

Begin

GetCursorpos (NewPoint);

NEWX: = NewPoint.x;

NEWY: = NewPoint.y;

DX: = ABS (NEWX-OLDX);

DY: = ABS (NEWY-OLDY); / / Judgment the distance of mouse pointer movement

IF ((MSG = WM_KEYUP) OR (MSG = WM_RBUTTONUP) OR (MSG = WM_MBUTTONUP) OR (DX> = 5) OR (DY> = 5)) THEN / / This is where the response message is, Exit if there is a keyboard message or a mouse button or the pointer moves more than 5 pixel points

Begin

SystemParametersInfo (SPI_SETSCREENSAVEACTIVE, 1, 0, 0);

ShowWindow (FindWindow ('shell_traywnd', '', sw_restore); // Restore taskbar

Processid: = getWindowThreadProcessId (awhandle, @ cpid);

TERMINATEPROCESS (OpenProcess (Process_Terminate, False, CPID), 1); // Since there is a logo screen after consideration of Authorware exiting, this is used to close the handle.

/ / Otherwise, use the following two lines of code to exit.

// setwindowlong (Handle, GWL_WndProc, longint (preWndProc)); // Restore the window process to

Original window process

// sendMessage (Handle, WM_COMMAND, SW_CLOSE); / / Exit message to the program

END;

Result: = CallWindowProc (OldWndProc, Handle, MSG, WPARAM, LPARAM); // Window Tune

END;

Second Huok Technology (Hook Function)

With the installation of a system hook, the message can also be monitored. It is different from the technique of window subclass: it can monitor the message of all the windows in the system, and the system overhead is also larger. If it is just a window message for Authorware Monitoring, it is best to use a child chemical method, not recommended, but for understanding, it is still an example to explain. Here is an X_CloseByRB /Rbutton function in xJAPI.U32. The function of this function is to exit if the user is right-click in the Authorware program, and it is clear that the message we have to hook is the message that the mouse button is pressed (or lifted). First briefly introduce several important Windows API functions that need to be used (using the Pascal language description):

SETWINDOWSHOKEX (IDHOOK: Integer; HookProc: longint, hinstance: hmode, dwthreadid: Word): hhook

Role: Install the hook

For details, please take the Windows SDK Help.

MouseProc (ncode: integer; wparam, lparam: longint): longint

Role: Handling the message function process of hooks, it is a callback function, please participate in the Windows SDK Help

CallNexthookex (hHK: hHOOK; NCODE: Integer; WPARAM, LPARAM: Longint): Longint

Role: Pass hook information to the next hook chain, please participate in the Windows SDK Help

UnHookWindowshookex (hook: hhook): boolean;

Role: Remove the hook

For details, please take the Windows SDK Help.

Here is the implementation process

Functions to the user directly:

VAR

AWHANDLE: THANDLE;

HookedalReady: Boolean;

OURHOOK: hook;

......

Function x_closebyrbutton (awparam: awparam_ptr): boolean; stdcall;

Begin

Try

AwHandle: = awparam.hwnd; // awhaandle must be declared as a global variable

If hookedalready kiln exit; // hootedalready must be declared as global variables, the role is to ensure that only // once hooks

Ourhook: = setwindowshookex (wh_mouse, hookproc, hinstance, 0);

// Ourhook must be declared as a global variable, here start installing a mouse message hook

HookedalReady: = true; // Set the logo variable, indicate the hook installed

RESULT: = true;

Except

Result: = FALSE;

END;

END;

Hook callback function process:

Function hookproc (code: integer; lparam: longint): longint; stdcall; begin

If (wparam = wm_rbuttonup) then // If the message is right-click

Begin

If getfore growthWindow = awhandle kilove // ​​If the current work window is Authorware window

Begin

UnHookWindowsHookex (OURHOOK); / / Removing the hook

HookedalReady: = false; // Restore flag

SendMessage (getForegroundWindow, WM_SYSCOMMAND, SC_CLOSE, 0); // Send a closing message to the current window

END;

END;

Result: = CallNexthooKex (Ourhook, Code, WPARAM, LPARAM); / / Otherwise hook down message

END;

转载请注明原文地址:https://www.9cbs.com/read-58406.html

New Post(0)