Search code examples
c++winapiinputbox

Using Win32InputBox in C++


I'm using this InputBox code (using dialog templates) -> http://www.codeproject.com/Articles/13330/Using-Dialog-Templates-to-create-an-InputBox-in-C

and if I first call MessageBox(..) function everything works fine, but without them the application hangs! (there must be some initializing code in it)!

In fact I don't need the MessageBox(), only want to use this InputBox -> how can I realize it?

My steps:

  • included Win32InputBox.h/.cpp
  • included header to my file
  • added CWin32InputBox::InputBox(_T("Input Dialog"), _T("Please enter password"), buf, 100, false, NULL); (wchar_t buf[100] = {0};)

My code:

void ClassA::SomeFunction()
{
    // ...
    MessageBoxA(NULL, "TEST!", "TEST", MB_ICONINFORMATION); // with this ALL OK
    wchar_t buf[100] = {0};
    CWin32InputBox::InputBox(_T("Input Dialog"), _T("Please enter password"), buf, 100, false, NULL);
    // ...
}

if the application hangs it's this line in CWin32InputBox::InputBoxEx(...)

INT_PTR r = ::DialogBoxIndirectParam(param->hInstance, dlgTemplate, param->hwndOwner, (DLGPROC)DlgProc, (LPARAM)&inputbox);

Thx


Solution

  • I solved it by creating a dummy window just right before calling InputBox!

    void ClassA::SomeFunction()
    {
        // ...
        // create a dummy window
        HWND dummyHWND = ::CreateWindowA("STATIC","dummy",WS_VISIBLE,0,0,100,100,NULL,NULL,NULL,NULL);
    
        wchar_t buf[100] = {0};
        CWin32InputBox::InputBox(_T("Input Dialog"), _T("Please enter KeyCard password"), buf, 100, false, dummyHWND);
        // ...
    }