【问题标题】:windows programing setting up window [closed]windows编程设置窗口[关闭]
【发布时间】:2014-06-29 19:57:29
【问题描述】:

我有这些拖车错误,我尝试过的都无法修复它们。我正在运行 Windows 8.1

错误 1 ​​错误 C3861: 'InitMainWindow': 未找到标识符

错误 2 错误 C2440: '=' : 无法从 'LRESULT (__stdcall *)(HWND,WPARAM,LPARAM)' 转换为 'WNDPROC'

代码:

#include <windows.h>    // include the basic windows header file

bool InitMainWindow(HINSTANCE, int);

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

const int width = 800;
const int height = 600;

HWND hwnd = NULL;

// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int     nCmdShow)
{
    if (!InitMainWindow(hInstance, nCmdShow))
        return 1;

     MSG msg = { 0 };
     while (WM_QUIT != msg.message)
     {
         if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
         {
             TranslateMessage(&msg);
             DispatchMessage(&msg);
         }
         return static_cast<int>(msg.wParam);
     }
}

bool InitMainWindow(HINSTANCE hInstance, int nCmdShow)
{
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(wcex);
    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.lpfnWndProc = MsgProc;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
    wcex.lpszClassName = NULL;
    wcex.lpszMenuName = NULL;
    wcex.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

    if (!RegisterClassEx(&wcex))
        return false;

    hwnd = CreateWindow (
        NULL,
        NULL,
        WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION,
        GetSystemMetrics(SM_CXSCREEN) / 2 - width / 2,
        GetSystemMetrics(SM_CYSCREEN) / 2 - height / 2,
        width,
        height,
        (HWND)NULL,
        (HMENU)NULL,
        hInstance,
        (LPVOID*)NULL);

    if (!hwnd)
        return false;
    ShowWindow(hwnd, nCmdShow);
    return true;

}

LRESULT CALLBACK MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    case WM_CHAR:
        switch (wParam)
        {

         case VK_ESCAPE:
             PostQuitMessage(0);
             return 0;
        }
        return 0;
    }
    return DefWindowProc(hwnd, msg, wParam, lParam);
}

【问题讨论】:

    标签: winapi visual-c++ directx win32gui


    【解决方案1】:

    您的 MsgProc 声明中缺少逗号。

    你有

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

    它声明了一个接受名为 UINT 的 HWND 的函数。

    你需要

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

    在此之后,它编译正常。

    【讨论】:

      猜你喜欢
      • 2015-01-27
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多