-1

まず第一に、これに対する私のポイントを理解させてください:

これは緊急警報システムで、バック オフィスで操作する Web サイトから取得します。プログラムは最小化できますが、閉じることはできません (簡単に言えば、少なくともそれを使用する人は誰もその方法を知りません)。ご覧のとおり、プログラムが閉じられた場合、緊急アラートは見られず、聞こえません....それは問題です. このアプリケーションを 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 に答える