-1

首先,让我明白我的观点:

这是一个紧急警报系统,它来自我们在后台操作的网站,程序可以最小化但不能关闭(很容易,至少没有人会知道如何使用它)。如您所见,如果程序关闭,则不会看到/听到紧急警报......这是一个问题。我必须在 200 多台计算机上部署此应用程序,因此我希望它简单,我不想创建计划任务等以保持其运行。我只是希望它不容易关闭。

请参阅我的代码,如下:

/* example.c

This is a Win32 C application (ie, no MFC, WTL, nor even any C++ -- just plain C) that demonstrates
how to embed a browser "control" (actually, an OLE object) in your own window (in order to display a
web page, or an HTML file on disk). The bulk of the OLE/COM code is in DLL.c which creates a DLL that
we use in this simple app. Furthermore, we use LoadLibrary and GetProcAddress, so our DLL is not
actually loaded until/unless we need it.

NOTE: The DLL we create does not normally use UNICODE strings. If you compile this example as UNICODE,
then you should do the same with DLL.C.
*/


#include <windows.h>
#include "..\CWebPage.h"    /* Declarations of the functions in DLL.c */





// A running count of how many windows we have open that contain a browser object
unsigned char WindowCount = 0;

// The class name of our Window to host the browser. It can be anything of your choosing.
static const TCHAR  ClassName[] = "EAS";

// Where we store the pointers to CWebPage.dll's functions
EmbedBrowserObjectPtr       *lpEmbedBrowserObject;
UnEmbedBrowserObjectPtr     *lpUnEmbedBrowserObject;
DisplayHTMLPagePtr          *lpDisplayHTMLPage;
DisplayHTMLStrPtr           *lpDisplayHTMLStr;






/****************************** WindowProc() ***************************
 * Our message handler for our window to host the browser.
 */

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    if (uMsg == WM_CREATE)
    {
        // Embed the browser object into our host window. We need do this only
        // once. Note that the browser object will start calling some of our
        // IOleInPlaceFrame and IOleClientSite functions as soon as we start
        // calling browser object functions in EmbedBrowserObject().
        if ((*lpEmbedBrowserObject)(hwnd)) return(-1);

        // Another window created with an embedded browser object
        ++WindowCount;

        // Success
        return(0);
    }

    if (uMsg == WM_DESTROY)
    {
        // Detach the browser object from this window, and free resources.
        (*lpUnEmbedBrowserObject)(hwnd);

        // One less window
        --WindowCount;

        // If all the windows are now closed, quit this app
        if (!WindowCount) PostQuitMessage(0);

        return(TRUE);
    }

    // NOTE: If you want to resize the area that the browser object occupies when you
    // resize the window, then handle WM_SIZE and use the IWebBrowser2's put_Width()
    // and put_Height() to give it the new dimensions.

    return(DefWindowProc(hwnd, uMsg, wParam, lParam));
}





/****************************** WinMain() ***************************
 * C program entry point.
 *
 * This creates a window to host the web browser, and displays a web
 * page.
 */

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hInstNULL, LPSTR lpszCmdLine, int nCmdShow)
{
    HINSTANCE       cwebdll;
    MSG             msg;
    WNDCLASSEX      wc;

    // Load our DLL containing the OLE/COM code. We do this once-only. It's named "cwebpage.dll"
    if ((cwebdll = LoadLibrary("cwebpage.dll")))
    {
        // Get pointers to the EmbedBrowserObject, DisplayHTMLPage, DisplayHTMLStr, and UnEmbedBrowserObject
        // functions, and store them in some globals.

        // Get the address of the EmbedBrowserObject() function. NOTE: Only Reginald has this one
        lpEmbedBrowserObject = (EmbedBrowserObjectPtr *)GetProcAddress((HINSTANCE)cwebdll, "EmbedBrowserObject");

        // Get the address of the UnEmbedBrowserObject() function. NOTE: Only Reginald has this one
        lpUnEmbedBrowserObject = (UnEmbedBrowserObjectPtr *)GetProcAddress((HINSTANCE)cwebdll, "UnEmbedBrowserObject");

        // Get the address of the DisplayHTMLPagePtr() function
        lpDisplayHTMLPage = (DisplayHTMLPagePtr *)GetProcAddress((HINSTANCE)cwebdll, "DisplayHTMLPage");

        // Get the address of the DisplayHTMLStr() function
        lpDisplayHTMLStr = (DisplayHTMLStrPtr *)GetProcAddress((HINSTANCE)cwebdll, "DisplayHTMLStr");

        // Register the class of our window to host the browser. 'WindowProc' is our message handler
        // and 'ClassName' is the class name. You can choose any class name you want.
        ZeroMemory(&wc, sizeof(WNDCLASSEX));
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.hInstance = hInstance;
        wc.lpfnWndProc = WindowProc;
        wc.lpszClassName = &ClassName[0];
        RegisterClassEx(&wc);

        // Create another window with another browser object embedded in it.
        if ((msg.hwnd = CreateWindowEx(0, &ClassName[0], "Emergency Alert System", WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
                        HWND_DESKTOP, NULL, hInstance, 0)))
        {
            // For this window, display a URL. This could also be a HTML file on disk such as "c:\\myfile.htm".
            (*lpDisplayHTMLPage)(msg.hwnd, "http://www.google.com");

            // Show the window.
            ShowWindow(msg.hwnd, nCmdShow);
            UpdateWindow(msg.hwnd);
        }

        // Do a message loop until WM_QUIT.
        while (GetMessage(&msg, 0, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        // Free the DLL.
        FreeLibrary(cwebdll);

        return(0);
    }

    MessageBox(0, "Can't open cwebpage.dll! You are not protected by Emergency Alerting System. Click OK to terminate this application. Contact the developer, Scott Plunkett.", "ERROR", MB_OK);
    return(-1);
}

它来自我发现的一个示例教程,我以前从未做过任何 Windows 编程,所以我必须想出一个快速的解决方案。

我很感激这方面的任何帮助。

4

2 回答 2

1

如果为WM_SYSCOMMAND消息创建处理程序并检查SC_SYSCLOSE参数,则可以阻止它执行关闭窗口的默认操作。

于 2013-09-18T02:48:07.160 回答
0

我注意到它不是 MFC 应用程序,因此您必须调用 Win32 库才能启用该功能。试试这个:http ://www.davekb.com/browse_programming_tips:win32_disable_close_button:txt

- -编辑 - -

抱歉,代码没有成功。我没有资源来调试它。

要禁用窗口的 X,您可以设置 WNDCLASSEX 的 CS_NOCLOSE 属性:

wc.style = CS_NOCLOSE;//in your code

或重写 WM_CLOSE 消息处理函数。谢谢。

于 2013-09-18T02:14:13.220 回答