locked
Why is the Default Beep Triggered by CreateWindowEx? RRS feed

  • Question

  • Hi,

    When creating a rich edit control via "Create" on Windows 7 64-bit, the default beep is triggered.  This happens in the "CreateEx" method in wincore.cpp, specifically after the call to "CreateWindowEx". A proper handle is returned and there is no error, just a beep.  The window is properly created as far as we can tell.

    Our application is a native c++, mfc, unicode.  Here is the code for creating the edit control:

    HINSTANCE hRichEditLib = LoadLibrary(_T("Riched20.dll"));

    CRect rectDummy(0, 0, lpCreateStruct->cx, lpCreateStruct->cy);

    const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_AUTOSCROLL | ES_AUTOVSCROLL | ES_MULTILINE;

    if (!myCtrl.Create(dwStyle, rectDummy, this, 2))  //this line triggers the beep

    {

      return -1;

    }

    else

    {

      myCtrl.Initalize();

    }

    Any ideas as to why the beep is triggered would be greatly appreciated! Thanks.

    Thursday, November 26, 2015 4:50 PM

Answers

  • It turns out the '2' for the ID was incorrect. This removed the 'BEEP' from CreateWindowEx.  However, as part of the initialization, our overridden version of OnKeyDown gets called.  The key stroke gets processed by CRichEditCtrl::OnKeyDown which also throws a 'BEEP' but that's a separate issue.
    • Marked as answer by KarimNogas Thursday, November 26, 2015 8:20 PM
    Thursday, November 26, 2015 8:20 PM

All replies

  • Consider calling  AfxInitRichEdit2 in InitInstance.

    LBS_NOINTEGRALHEIGHT is a listbox style that has nothing to do with a richedit control. More information about the code you haven't shown would be helpful.  For example, what is myCtrl?  Is it a CWnd? Something else? When is this code being executed?


    • Edited by RLWA32 Thursday, November 26, 2015 6:04 PM
    Thursday, November 26, 2015 6:02 PM
  • I discovered that I don't need to call LoadLibrary as the call to CRichEditCtrl::Create will automatically call AfxInitRichEdit5().

    myCtrl is simply a class derived from CRichEditCtrl whose purpose is simply to log messages from the rest of the application.  It lives in a CDialog derived class.

    On startup, the app's InitInstance calls ProcessShellCommand which eventually leads to the OnCreate method of CMainFrame where the CDialog derived class's Create method is called. That method has the code shown, where the control gets created.

    Thursday, November 26, 2015 7:55 PM
  • It turns out the '2' for the ID was incorrect. This removed the 'BEEP' from CreateWindowEx.  However, as part of the initialization, our overridden version of OnKeyDown gets called.  The key stroke gets processed by CRichEditCtrl::OnKeyDown which also throws a 'BEEP' but that's a separate issue.
    • Marked as answer by KarimNogas Thursday, November 26, 2015 8:20 PM
    Thursday, November 26, 2015 8:20 PM