4


I created in C++ a window with the Win API.
If I set the target platform to x86 in Visual Studio (2015) all works fine.
But if I set the target platform to x64 all works fine too except that I get a busy cursor for the first 4-5 seconds when the window popped up.
This isn't that bad but I am just wondering what is causing this.
I saw this behavior when using GLFW too so it seems to be not a programming error.

Maybe someone know what is causing this?

#include <windows.h>

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

    return DefWindowProc(hWnd, message, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    HWND hWnd;
    WNDCLASSEX wc;

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = NULL;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "MainWindowClass";
    wc.hIconSm = NULL;

    RegisterClassEx(&wc);

    RECT wr = { 0, 0, 800, 800 };
    AdjustWindowRectEx(&wr, WS_OVERLAPPEDWINDOW, FALSE, 0);

    hWnd = CreateWindowEx(0, "MainWindowClass", "DirectX Lab", WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, wr.right - wr.left, wr.bottom - wr.top, NULL, NULL, hInstance, NULL);

    ShowWindow(hWnd, nCmdShow);

    MSG msg;

    while (GetMessage(&msg, NULL, 0, 0) != 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}
Michael
  • 595
  • 5
  • 19
  • Could be lots and lots of things. Startup time is dominated by the need to find DLLs that are not already resident in the file system cache. Or already loaded in another process. Anti-malware always gets kudos for not allowing your start a new executable file that appeared from nowhere until it has finished scanning the file. The debugger might be trying to find a PDB file that isn't available for an x64 executable. Etcetera. You'll have to narrow it down yourself, read Mark Russinovich' blog for troubleshooting hints. – Hans Passant Oct 24 '15 at 14:34
  • But why in x32 there is not such a problem? And if I build a release version there is still the busy cursor... – Michael Oct 24 '15 at 14:41
  • I see the same thing in VS2015 64bit debug mode, but it doesn't happen in release-64bit or debug-32bit. It's probably related to Visual Studio debugger. – Barmak Shemirani Oct 24 '15 at 15:29
  • But I set it at me to release too and the busy cursor still appears. – Michael Oct 24 '15 at 15:59
  • 1
    Did you try Ctrl+F5 (run without debugger)? or try running the program from explorer. I can only see the annoying problem in 64bit-debug after source code is changed. I don't know why that happens. – Barmak Shemirani Oct 24 '15 at 16:13
  • This code sort of fixes the problem: `HCURSOR temp = LoadCursor(NULL, IDC_ARROW); HCURSOR copy = CopyCursor(temp); wndClass.hCursor = copy;` ----- or if you replace `IDC_ARROW` with `IDC_IBEAM` ----- MSDN says `LoadCursor` is suppressed by `LoadImage`, yet `LoadCursor` is used in many programs, maybe that has something to do with it? – Barmak Shemirani Oct 24 '15 at 17:22
  • Oh, if I launch using Ctr+F5 it works perfect. I didn't knew that there are different run options except setting target platform and configuration. Thanks. – Michael Oct 24 '15 at 22:08

0 Answers0