0

如果我在主窗口中创建一个子窗口(在本例中为“关于”窗口),则由于某种原因不会调用该对话框。如果您不这样做,则子窗口是一个称为正常的对话框并且可以正常工作。GetLastError 返回错误号 1812(指定的图像文件不包含资源部分。)。但是从资源文件来看,一切都很好。正如我所说,如果您不创建子窗口,那么一切正常。有什么问题?

#include <windows.h>
#include "resource.h"

LONG WINAPI WndProc(HWND, UINT, WPARAM,LPARAM);
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK PointsProc(HWND hPoints, UINT message, WPARAM wParam,LPARAM lParam);

HINSTANCE hInst;
HWND hPoints;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    hInst = hInstance;
    HWND hwnd;
    MSG msg;
    WNDCLASS w;
    memset(&w,0,sizeof(WNDCLASS));
    w.style = CS_HREDRAW | CS_VREDRAW;
    w.lpfnWndProc = WndProc;
    w.hInstance = hInstance;
    w.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    w.lpszClassName = L"My Class";
    RegisterClass(&w);
    hwnd = CreateWindow(L"My Class", L"My title", WS_OVERLAPPEDWINDOW,
    300, 200, 200, 180, NULL, NULL, hInstance, NULL);

    HMENU main_menu = CreateMenu();
    AppendMenu(main_menu, MF_STRING, 1111, L"Box");

    WNDCLASS w2;
    memset(&w2, 0, sizeof(WNDCLASS));
    w2.lpfnWndProc = (WNDPROC)PointsProc;
    w2.hInstance = hInst;
    w2.lpszClassName = L"About";
    w2.hCursor = LoadCursor(NULL, IDC_ARROW); 
    w2.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(111, 111, 111));
    RegisterClass(&w2);

    hPoints = CreateWindowEx(0, L"About", (LPCTSTR) NULL,
    WS_CHILD | WS_BORDER | WS_VISIBLE | WS_DISABLED, 10, 10,
    100, 100, hwnd, (HMENU)1112, hInst, NULL);

    ShowWindow(hPoints,SW_NORMAL);
    UpdateWindow(hPoints);

    SetMenu(hwnd, main_menu);

    ShowWindow(hwnd,nCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

LONG WINAPI WndProc(HWND hwnd, UINT Message, WPARAM wparam, LPARAM lparam)
{
    switch (Message)
    {
        case WM_COMMAND:
            switch(LOWORD(wparam)) 
            {
                case 1111:
                    DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, About);
                    return 0;
            }
            break;
        case WM_DESTROY: 
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, Message, wparam, lparam);
    }
    return 0;
}

LRESULT CALLBACK PointsProc(HWND hPoints, UINT message, WPARAM wParam,LPARAM lParam)
{   
    switch(message)
    {   
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        case WM_PAINT:
            break;
        default:
            return DefWindowProc(hPoints, message, wParam, lParam);
    }
    return 0;
}

INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
        case WM_INITDIALOG:
            return (INT_PTR)TRUE;

        case WM_COMMAND:
            if (LOWORD(wParam) == IDCANCEL)
            {
                EndDialog(hDlg, LOWORD(wParam));
                return (INT_PTR)TRUE;
            }
        break;
    }
    return (INT_PTR)FALSE;
}
4

1 回答 1

0

对话框调用,只是它需要很长时间,因为PointsProc()正在循环......

问题是break;while 处理WM_PAINT-PointsProc()然后它跳过调用DefWindowProc(),因此窗口不断收到 WM_PAINT 消息,因为窗口仍然无效。

//        case WM_PAINT:
//            break;
于 2013-06-21T11:14:47.550 回答