CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2007
    Posts
    9

    Creating a dialog from a dll

    Hello,

    I have a dll I built to be loaded as a pluging. As part of the dll I have a dialog I'm trying to create and display.
    The dialog is created and displayed using CreateDialog, however once the dialog is shown it doesn't respond, as soon as I pass the mouse over the dialog the mouse pointer changes to busy, and the dialog isn't responding while the rest of the module keeps running.

    bool CDialogs:isplaySafetyDialog(HWND wnd)
    {
    HWND retValue = CreateDialog(m_instance, MAKEINTRESOURCE(IDD_SAFETY), NULL, dialogProc);


    return true;
    }

    INT_PTR CALLBACK CDialogs:ialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    static int num;
    BOOL translated = false;

    switch (uMsg)
    {
    case WM_INITDIALOG:
    return TRUE;
    case WM_COMMAND:
    switch (LOWORD(wParam))
    {
    case IDOK:
    if (num == GetDlgItemInt(hwnd, IDC_INPUT, &translated, false))
    {
    DestroyWindow(hwnd);
    }
    return TRUE;
    case IDCANCEL:
    DestroyWindow(hwnd);
    return TRUE;
    default:
    break;
    }
    break;
    default:
    break;
    }

    return FALSE;

    }

    Any help will be appreciated,
    Best regards,
    Alex

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Creating a dialog from a dll

    Please format your code properly before posting and use code tags. Your code as shown is not easy to understand. Go Advanced, select the code and click '#'.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Aug 2007
    Posts
    9

    Re: Creating a dialog from a dll

    Quote Originally Posted by khalameizer View Post
    Hello,

    I have a dll I built to be loaded as a pluging. As part of the dll I have a dialog I'm trying to create and display.
    The dialog is created and displayed using CreateDialog, however once the dialog is shown it doesn't respond, as soon as I pass the mouse over the dialog the mouse pointer changes to busy, and the dialog isn't responding while the rest of the module keeps running.
    Code:
    bool CDialogs::displaySafetyDialog(HWND wnd)
    {
    	HWND retValue = CreateDialog(m_instance, MAKEINTRESOURCE(IDD_SAFETY), NULL, dialogProc);
    	
    
    	return true;
    }
    
    INT_PTR CALLBACK CDialogs::dialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	static int num;
    	BOOL translated = false;
    
    	switch (uMsg)
    	{
    		case WM_INITDIALOG:
    			return TRUE;
    		case WM_COMMAND:
    			switch (LOWORD(wParam))
    			{
    			case IDOK:
    				if (num == GetDlgItemInt(hwnd, IDC_INPUT, &translated, false))
    				{
    					DestroyWindow(hwnd);
    				}
    				return TRUE;
    			case IDCANCEL:
    				DestroyWindow(hwnd);
    				return TRUE;
    			default:
    				break;
    			}
    			break;
    		default:
    			break;
    	}
    
    	return FALSE;
    		
    }
    Any help will be appreciated,
    Best regards,
    Alex
    Attached above the formatted code.
    Thank you,
    Alex

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Creating a dialog from a dll

    maybe a silly question, but in that kind of setup... Who'll be doing the "pumping" of the messages of your dialog ?

    also. The thread that creates the window, needs to be the SAME thread that processes the messages. Does your plugin guarantee this is always going to be the case ?

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Creating a dialog from a dll

    Quote Originally Posted by khalameizer View Post
    as soon as I pass the mouse over the dialog the mouse pointer changes to busy, and the dialog isn't responding while the rest of the module keeps running.
    You need to learn about modal and modeless dialogs. CreateDialog just creates modeless dialog which requires a proper message pump be present in the thread. DialogBox function creates a modal dialog and internally takes care about dialog messages proper pumping.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured