Windows NT ( 2)

       

DLLCALL


DLLCALL DLL- DLLDemo.DLL, .

DLLCALL File . 3.7.

. 3.7. DLLCALL

File Find App Window, Find Application Window, . 3.8.

. 3.8. Find Application Window

Enter application window title to find . , , (. 3.9).

. 3.9. ,

DLL-, DLLCALL, , . 3.10.

. 3.10. DLL-

DLLCALL DLL-, , . 3.11.

. 3.11. DLL-



DLLCALL 3.4.

3.4. dlldemo\dllcall\dllcall.c

// ==================================================

// DLLCall

// DLL-

//

// () .., 1996

// Email: frolov@glas.apc.org

// ==================================================

#define STRICT

#include <windows.h>

#include <windowsx.h>

#include "resource.h"

#include "afxres.h"

#include "dllcall.h"

// :

typedef HWND (WINAPI *MYDLLPROC)(LPSTR);

// ,

// DLL-

MYDLLPROC GetAppWindow;

// ,

//

char szWindowTitle[512];

// DLL-

HANDLE hDLL;

HINSTANCE hInst;

char szAppName[] = "DLLCallApp";


char szAppTitle[] = "DLL Call Demo";

// -----------------------------------------------------

// WinMain

// -----------------------------------------------------

int APIENTRY

WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

LPSTR lpCmdLine, int nCmdShow)

{

WNDCLASSEX wc;

HWND hWnd;

MSG msg;



//

hInst = hInstance;

// ,

hWnd = FindWindow(szAppName, NULL);

if(hWnd)

{

// ,

//

if(IsIconic(hWnd))

ShowWindow(hWnd, SW_RESTORE);

SetForegroundWindow(hWnd);

return FALSE;

}

//

memset(&wc, 0, sizeof(wc));

wc.cbSize = sizeof(WNDCLASSEX);

wc.hIconSm = LoadImage(hInst,

MAKEINTRESOURCE(IDI_APPICONSM),

IMAGE_ICON, 16, 16, 0);

wc.style = 0;

wc.lpfnWndProc = (WNDPROC)WndProc;

wc.cbClsExtra = 0;

wc.cbWndExtra = 0;

wc.hInstance = hInst;

wc.hIcon = LoadImage(hInst,

MAKEINTRESOURCE(IDI_APPICON),

IMAGE_ICON, 32, 32, 0);

wc.hCursor = LoadCursor(NULL, IDC_ARROW);

wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);

wc.lpszMenuName = MAKEINTRESOURCE(IDR_APPMENU);

wc.lpszClassName = szAppName;

if(!RegisterClassEx(&wc))

if(!RegisterClass((LPWNDCLASS)&wc.style))

return FALSE;



//

hWnd = CreateWindow(szAppName, szAppTitle,

WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,

NULL, NULL, hInst, NULL);

if(!hWnd) return(FALSE);

//

//

ShowWindow(hWnd, nCmdShow);

UpdateWindow(hWnd);

while(GetMessage(&msg, NULL, 0, 0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

// -----------------------------------------------------



// WndProc

// -----------------------------------------------------

LRESULT WINAPI

WndProc( HWND hWnd, UINT msg, WPARAM wParam,

LPARAM lParam)

{

switch(msg)

{

HANDLE_MSG(hWnd, WM_COMMAND, WndProc_OnCommand);

HANDLE_MSG(hWnd, WM_DESTROY, WndProc_OnDestroy);

default:

return(DefWindowProc(hWnd, msg, wParam, lParam));

}

}

// -----------------------------------------------------

// WndProc_OnDestroy

// -----------------------------------------------------

#pragma warning(disable: 4098)

void WndProc_OnDestroy(HWND hWnd)

{

PostQuitMessage(0);

return 0L;

}

// -----------------------------------------------------

// WndProc_OnCommand

// -----------------------------------------------------

#pragma warning(disable: 4098)

void WndProc_OnCommand(HWND hWnd, int id,

HWND hwndCtl, UINT codeNotify)

{

switch (id)

{

case ID_FILE_EXIT:

{

//

PostQuitMessage(0);

return 0L;

break;

}



case ID_FILE_FINDWINDOW:

{

//

// ,

//

if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DLGFIND),

hWnd, DlgProc))

{

// DLL-:

//

/*

// ,

//

if(FindApplicationWindow(szWindowTitle) != NULL)

MessageBox(NULL, "Application window was found",

szAppTitle, MB_OK | MB_ICONINFORMATION);



else

MessageBox(NULL, "Application window was not found",

szAppTitle, MB_OK | MB_ICONINFORMATION);

*/

// DLL-:

// DLL- LoadLibrary



// DLL-

hDLL = LoadLibrary("DLLDEMO.DLL");

// ,

//

if(hDLL != NULL)

{

//

GetAppWindow =

(MYDLLPROC)GetProcAddress(hDLL,

"FindApplicationWindow");

// ,

if(GetAppWindow != NULL)

{

// ,

//

if(GetAppWindow(szWindowTitle) != NULL)

MessageBox(NULL, "Application window was found",

szAppTitle, MB_OK | MB_ICONINFORMATION);

else

MessageBox(NULL,

"Application window was not found",

szAppTitle, MB_OK | MB_ICONINFORMATION);

}



// DLL-

FreeLibrary(hDLL);

}

}



break;

}



case ID_HELP_ABOUT:

{

MessageBox(hWnd,

"DLL Call Demo\n"

"(C) Alexandr Frolov, 1996\n"

"Email: frolov@glas.apc.org",

szAppTitle, MB_OK | MB_ICONINFORMATION);

return 0L;

break;

}

default:

break;

}

return FORWARD_WM_COMMAND(hWnd, id, hwndCtl, codeNotify,

DefWindowProc);

}

// -----------------------------------------------------

// DlgProc

// -----------------------------------------------------

LRESULT WINAPI

DlgProc( HWND hdlg, UINT msg, WPARAM wParam,

LPARAM lParam)

{

switch(msg)

{

HANDLE_MSG(hdlg, WM_INITDIALOG, DlgProc_OnInitDialog);

HANDLE_MSG(hdlg, WM_COMMAND, DlgProc_OnCommand);

default:

return FALSE;

}

}

// -----------------------------------------------------



// DlgProc_OnInitDialog

// -----------------------------------------------------

BOOL DlgProc_OnInitDialog(HWND hdlg, HWND hwndFocus,

LPARAM lParam)

{

return TRUE;

}

// -----------------------------------------------------

// DlgProc_OnCommand

// -----------------------------------------------------

#pragma warning(disable: 4098)

void DlgProc_OnCommand(HWND hdlg, int id,

HWND hwndCtl, UINT codeNotify)

{

switch (id)

{

case IDOK:

{

// OK,

//

// szWindowTitle

GetDlgItemText(hdlg, IDC_EDIT1, szWindowTitle, 512);



//

EndDialog(hdlg, 1);

return TRUE;

}

// Cancel,

//

case IDCANCEL:

{

//

EndDialog(hdlg, 0);

return TRUE;

}

default:

break;

}

return FALSE;

}

dllcall.h ( 3.5) , DLLCALL.

3.5. dlldemo\dllcall\dllcall.h

// -----------------------------------------------------

//

// -----------------------------------------------------

LRESULT WINAPI

WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

void WndProc_OnCommand(HWND hWnd, int id,

HWND hwndCtl, UINT codeNotify);

void WndProc_OnDestroy(HWND hWnd);

HWND FindApplicationWindow(LPSTR lpszWindowTitle);

LRESULT WINAPI

DlgProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam);

BOOL DlgProc_OnInitDialog(HWND hdlg, HWND hwndFocus,

LPARAM lParam);

void DlgProc_OnCommand(HWND hdlg, int id,

HWND hwndCtl, UINT codeNotify);

dllcall.rc ( 3.6) DLLCALL. , , , .



3.6. dlldemo\dllcall\dllcall.rc

// Microsoft Developer Studio generated resource script.

//

#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS

//////////////////////////////////////////////////////////////

//

// Generated from the TEXTINCLUDE 2 resource.

//

#include "afxres.h"

//////////////////////////////////////////////////////////////

#undef APSTUDIO_READONLY_SYMBOLS

//////////////////////////////////////////////////////////////

// Russian resources

#if !defined(AFX_RESOURCE_DLL) defined(AFX_TARG_RUS)

#ifdef _WIN32

LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT

#pragma code_page(1251)

#endif //_WIN32

//////////////////////////////////////////////////////////////

//

// Menu

//

IDR_APPMENU MENU DISCARDABLE

BEGIN

POPUP "&File"

BEGIN

MENUITEM "F&ind App Window", ID_FILE_FINDWINDOW

MENUITEM SEPARATOR

MENUITEM "E&xit", ID_FILE_EXIT

END

POPUP "&Help"

BEGIN

MENUITEM "&About...", ID_HELP_ABOUT

END

END

#ifdef APSTUDIO_INVOKED

//////////////////////////////////////////////////////////////

//

// TEXTINCLUDE

//

1 TEXTINCLUDE DISCARDABLE

BEGIN

"resource.h\0"

END

2 TEXTINCLUDE DISCARDABLE

BEGIN

"#include ""afxres.h""\r\n"

"\0"

END

3 TEXTINCLUDE DISCARDABLE

BEGIN

"\r\n"

"\0"

END

#endif // APSTUDIO_INVOKED

//////////////////////////////////////////////////////////////

//

// Icon

//

// Icon with lowest ID value placed first to ensure

// application icon

// remains consistent on all systems.

IDI_APPICON ICON DISCARDABLE "Dllcall.ico"

IDI_APPICONSM ICON DISCARDABLE "Dllcalsm.ico"

//////////////////////////////////////////////////////////////



//

// Dialog

//

IDD_DLGFIND DIALOG DISCARDABLE 0, 0, 247, 74

STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU

CAPTION "Find Application Window"

FONT 8, "MS Sans Serif"

BEGIN

EDITTEXT IDC_EDIT1,21,31,152,16,ES_AUTOHSCROLL

DEFPUSHBUTTON "OK",IDOK,190,7,50,14

PUSHBUTTON "Cancel",IDCANCEL,190,24,50,14

GROUPBOX "Enter application window title to find",

IDC_STATIC,13,13,167,49

END

//////////////////////////////////////////////////////////////

//

// DESIGNINFO

//

#ifdef APSTUDIO_INVOKED

GUIDELINES DESIGNINFO DISCARDABLE

BEGIN

IDD_DLGFIND, DIALOG

BEGIN

LEFTMARGIN, 7

RIGHTMARGIN, 240

TOPMARGIN, 7

BOTTOMMARGIN, 67

END

END

#endif // APSTUDIO_INVOKED

#endif // Russian resources

//////////////////////////////////////////////////////////////

#ifndef APSTUDIO_INVOKED

//////////////////////////////////////////////////////////////

//

// Generated from the TEXTINCLUDE 3 resource.

//

//////////////////////////////////////////////////////////////

#endif // not APSTUDIO_INVOKED

resource.h ( 3.7) .

3.7. dlldemo\dllcall\resource.h

//{{NO_DEPENDENCIES}}

// Microsoft Developer Studio generated include file.

// Used by DLLCall.rc

//

#define IDR_MENU1 101

#define IDR_APPMENU 101

#define IDI_APPICON 102

#define IDI_APPICONSM 103

#define IDD_DLGFIND 104

#define IDC_EDIT1 1000

#define ID_FILE_EXIT 40001

#define ID_HELP_ABOUT 40002

#define ID_FILE_FINDWINDOW 40003

// Next default values for new objects

//

#ifdef APSTUDIO_INVOKED

#ifndef APSTUDIO_READONLY_SYMBOLS

#define _APS_NEXT_RESOURCE_VALUE 105

#define _APS_NEXT_COMMAND_VALUE 40004

#define _APS_NEXT_CONTROL_VALUE 1001

#define _APS_NEXT_SYMED_VALUE 101

#endif

#endif

DLLCALL.