C++ 无法更改任何使用窗口的应用程序?@GavinWilliams在调试器中的WinMain的第一行代码上设置一个断点,并在调试器中运行它,查看断点是否命中否未命中,VS显示应用程序已终止,而任务管理器说它仍在运行。抱歉,是的,它已命中(我以前在发行版中运行过)

C++ 无法更改任何使用窗口的应用程序?@GavinWilliams在调试器中的WinMain的第一行代码上设置一个断点,并在调试器中运行它,查看断点是否命中否未命中,VS显示应用程序已终止,而任务管理器说它仍在运行。抱歉,是的,它已命中(我以前在发行版中运行过),c++,C++,无法更改任何使用窗口的应用程序?@GavinWilliams在调试器中的WinMain的第一行代码上设置一个断点,并在调试器中运行它,查看断点是否命中否未命中,VS显示应用程序已终止,而任务管理器说它仍在运行。抱歉,是的,它已命中(我以前在发行版中运行过)。单步执行代码时,ShowWindow(hwnd,windowStyle)不会弹出任何窗口,并且单步标记在((status=GetMessage(&msg,(hwnd)NULL,0,0))!=0&&status!=-1)时丢失这种情况可能是由错


无法更改任何使用窗口的应用程序?@GavinWilliams在调试器中的
WinMain
的第一行代码上设置一个断点,并在调试器中运行它,查看断点是否命中否未命中,VS显示应用程序已终止,而任务管理器说它仍在运行。抱歉,是的,它已命中(我以前在发行版中运行过)。单步执行代码时,ShowWindow(hwnd,windowStyle)不会弹出任何窗口,并且单步标记在((status=GetMessage(&msg,(hwnd)NULL,0,0))!=0&&status!=-1)时丢失这种情况可能是由错误的
hInstance
值引起的。当您将WinMain设置为入口点时,无法再从此参数获取应用程序实例句柄。请尝试从
GetModuleHandle(NULL)获取
hInstance
然后看看会发生什么。你在哪里准确设置入口点?属性>配置属性>链接器>高级>入口点=WinMain你似乎触及了这里讨论的问题www.benshoof.org/blog/small-programs/显然,我需要更深入地理解这个主题,然后才能期待entr带来奇迹y点改变。也许需要使用minicrt之类的东西来正确改变入口点。我想说风险并不重要,因为这是一个了解演示如何工作的短暂实验过程。但是,我尝试查看的演示中有一半以上都无法在我的计算机上工作,所以这就是风险所在。@GavinWilliams:我错过了你在输入答案时的编辑。现在我看到了你方法的实验性质。哦,好吧……考虑到你给出的链接,我想你现在已经自己回答了你的问题:)Gavin,如果你更改了程序的入口点,你需要确保你的新函数与你要替换的函数具有相同的签名。程序的真正入口点是一个零参数C函数。的图3显示了它是如何为
WinMain
准备参数的。
#include <Windows.h>

// forward declarations
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 

// The entry point into a windows program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int windowStyle )
{
....
#include <Windows.h>

// forward declarations
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); // WindowProcedure function

// The entry point into a windows program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int  windowStyle )
{
// create and register a local window class > exit on failure
WNDCLASSEX wcx;
HINSTANCE zhInstance = GetModuleHandle(NULL);
wcx.cbSize = sizeof(WNDCLASSEX);                // size of structure
wcx.style = CS_HREDRAW | CS_VREDRAW;            // redraw if size changes
wcx.lpfnWndProc = WndProc;                      // window procedure
wcx.cbClsExtra = 0;                             // no extra class memory
wcx.cbWndExtra = 0;                             // no extra windows memory
wcx.hInstance = zhInstance;                     // handle to instance (owner)
wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);    // predefined icon 
wcx.hCursor = LoadCursor (NULL, IDC_ARROW);     // predefined arrow
wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);//(HBRUSH) (COLOR_WINDOW + 1);// white background brush
wcx.lpszMenuName = NULL;                        // name of menu resource
wcx.lpszClassName = TEXT("BasicWindow");        // name of window class
wcx.hIconSm = (HICON)LoadImage(zhInstance,              // small class icon 
    MAKEINTRESOURCE(5),
    IMAGE_ICON, 
    GetSystemMetrics(SM_CXSMICON), 
    GetSystemMetrics(SM_CYSMICON), 
    LR_DEFAULTCOLOR); 

if (!RegisterClassEx(&wcx))
{
    MessageBoxA(0, "Error registering window class!","Error",MB_ICONSTOP | MB_OK);
    DWORD result = GetLastError();
    return 0;
}

// create window > exit on failure
HWND hwnd; // the window handle
hwnd = CreateWindowEx(
    WS_EX_STATICEDGE, 
    wcx.lpszClassName, 
    TEXT("Basic Window"), 
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    320,
    240,
    NULL,
    NULL,
    zhInstance,
    NULL);

if (hwnd == NULL)
{
    MessageBoxA(0,"Error creating window!","Error",MB_ICONSTOP | MB_OK);
    return 0;
}

// show window
ShowWindow(hwnd, SW_MAXIMIZE);
// send a WM_PAINT message to the window
UpdateWindow(hwnd);

// enter message loop, break out of loop if there is an error (result = -1)
MSG msg;    // for storing the windows messages
int status; // for storing the status of the windows message service where -1 = error, 0 = WM_QUIT, n = any other message)
while ((status = GetMessage(&msg,(HWND) NULL,0,0)) != 0 && status != -1)
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}

return msg.wParam;
    UNREFERENCED_PARAMETER(lpCmdLine);
}

LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CLOSE:
    DestroyWindow(hWnd);
    break;
case WM_DESTROY:
    PostQuitMessage(0);
default:
    return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}