为什么我在使用WS_EX_CONTEXTHELP时看不到问号?

时间:2015-11-19 08:50:02

标签: c++ c winapi createwindowex

我正在学习WinAPI。 MSDN

  

WS_EX_CONTEXTHELP

     

窗口的标题栏包含一个问题   标记。当用户单击问号时,光标变为a   带指针的问号。如果用户然后单击子窗口,   孩子收到WM_HELP消息。子窗口应该通过   消息到父窗口过程,应该调用WinHelp   函数使用HELP_WM_HELP命令。帮助应用程序显示   一个弹出窗口,通常包含子窗口的帮助。

     

WS_EX_CONTEXTHELP不能与WS_MAXIMIZEBOX一起使用   WS_MINIMIZEBOX样式。

当我尝试在代码中使用WS_EX_CONTEXTHELP时,我看不到问号。我没有在代码中指出WS_MAXIMIZEBOXWS_MINIMIZEBOX值:

enter image description here

enter image description here

为什么会这样?我的“Hello World”代码:

#include <Windows.h>
#include <tchar.h>
#include <iostream>
#include <exception>

using namespace std;

#define APP_RC_SUCCEEDED 0
#define APP_RC_UNHANDLED_EXCEPTION 1
#define APP_RC_UNKNOWN_ERROR 2
#define APP_RC_WINDOW_CLASS_WAS_NOT_REGISTERED 3

#ifdef UNICODE
#define TCOUT std::wcout
#define TCIN std::wcin
#define TCERR std::wcerr
#else
#define TCOUT std::cout
#define TCIN std::cin
#define TCERR std::cerr
#endif

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(
    HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, INT iShow)
    try {
    LPCTSTR className = _T("{AAAEB8BF-04C5-4DEA-96C1-FC14F7E66A35}");

    WNDCLASSEX wndclassex;
    ZeroMemory(&wndclassex, sizeof(wndclassex));

    wndclassex.cbSize = sizeof(wndclassex);
    wndclassex.lpszClassName = className;
    wndclassex.cbClsExtra = 0;
    wndclassex.cbWndExtra = 0;
    wndclassex.hInstance = hInstance;
    wndclassex.lpfnWndProc = WndProc;
    wndclassex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wndclassex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wndclassex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndclassex.lpszMenuName = NULL;
    wndclassex.style = CS_HREDRAW | CS_VREDRAW;
    wndclassex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);

    ATOM wAtom = RegisterClassEx(&wndclassex);

    if (!wAtom) {
        DWORD errCode = GetLastError();
        TCERR << _T("Function: RegisterClassEx. System Error Code: ")
            << errCode << endl;
        return APP_RC_WINDOW_CLASS_WAS_NOT_REGISTERED;
    }

    HWND hwnd = CreateWindowEx(
        WS_EX_CONTEXTHELP,
        className,
        _T("This is the title text..."),
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL);

    ShowWindow(hwnd, iShow);
    UpdateWindow(hwnd);

    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return APP_RC_SUCCEEDED;
}
catch (exception ex)
{
    TCERR << ex.what() << endl;
    return APP_RC_UNHANDLED_EXCEPTION;
}
catch (...) {
    TCERR << _T("Unknown error.") << endl;
    return APP_RC_UNKNOWN_ERROR;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    HDC hdc;
    PAINTSTRUCT ps;
    RECT rect;
    switch (uMsg) {
    case WM_CREATE:
        return 0;
    case WM_PAINT:
        hdc = BeginPaint(hwnd, &ps);
        GetClientRect(hwnd, &rect);
        DrawText(hdc, _T("Hello!"), -1, &rect, DT_SINGLELINE |
            DT_CENTER | DT_VCENTER);
        EndPaint(hwnd, &ps);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(APP_RC_SUCCEEDED);
        return 0;
    default:
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
}

1 个答案:

答案 0 :(得分:3)

答案可以在您的问题中包含的文档引用中找到:

  

WS_EX_CONTEXTHELP不能与WS_MAXIMIZEBOX或WS_MINIMIZEBOX样式一起使用。

您指定了包含WS_OVERLAPPEDWINDOWWS_MAXIMIZEBOX的窗口样式WS_MINIMIZEBOX