Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi,
I have win32 dll that using CreateDialogParamA function for making small dialog front of Parent window. Parent window is include different windows that each has specific HWND.
Problem is when i can this CreateDialogParamA with unique HWND, this shows dialog for all windows with different HWND.
Is there any C++ function that restrict this dialog to HWND that call that?
C++
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "resource.h"

HINSTANCE g_hInstance;

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		g_hInstance = hModule;
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

INT_PTR CALLBACK DialogFunc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	HMENU hMenu;
	switch(uMsg)
	{
	case WM_INITDIALOG:
		hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MENU1));
		SetMenu(hDlg, hMenu);
		break;
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case IDC_BUTTON1:
		case ID_FILE_MESSAGEBOX:
			MessageBox(hDlg, "This is sample for Reza", "Test", MB_OK);
			break;
		case IDC_BUTTON2:
		case ID_FILE_EXIT:
			SendMessage(hDlg, WM_CLOSE, 0, 0);
			break;
		

		}
		break;
	case WM_CLOSE:
		DestroyWindow(hDlg);
		return TRUE;
		break;
	case WM_DESTROY: 
		PostQuitMessage (0); 
		return TRUE;
		break; 
	}
	return FALSE;
}

MT4_EXPFUNC int MetaTest(HWND hWnd)
{
	MSG msg; 
	BOOL msgstatus; 

	HWND hDlg = CreateDialogParamA(g_hInstance, MAKEINTRESOURCE(IDD_METATEST), hWnd, DialogFunc, 0);
	ShowWindow(hDlg, SW_SHOW);

	while ((msgstatus=GetMessage (&msg, NULL, 0, 0)) && msgstatus!=-1)
	{ 
		if (! IsDialogMessage (hDlg, &msg)) 
		{ 
			TranslateMessage (&msg);  
			DispatchMessage (&msg); 
		}
	}
	return 0;
}


For example in above code, I call function MetaTest with unique hWnd. I want it shows this dialog for this hWnd, but it shows for other active hWnd in Parent window too.
I want fix that it shows dialog for this hwnd only.
Regards,
Posted
Updated 24-Sep-13 13:27pm
v2
Comments
CPallini 24-Sep-13 16:49pm    
Could you please elaborate?
Sergey Alexandrovich Kryukov 24-Sep-13 17:15pm    
It looks like OP managed to make something very exotic. I wouldn't not mind to see such code... :-)
—SA
Richard MacCutchan 25-Sep-13 4:05am    
I am not really sure what your question is but it may be that you should be using a modal dialog as described in this page.

1 solution

To start with, just for proper HANDLE'ing of various things you might want to finish your case conditions:

C++
switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		g_hInstance = hModule;
	case DLL_THREAD_ATTACH://attaches a thread to a process
	case DLL_THREAD_DETACH:// detaches a thread from process 
	case DLL_PROCESS_DETACH:// detaches module from g_hInstance 
		g_hInstance = null;
		break;
	}
	return TRUE;


Then perhaps in your MetaTest you have passed in a HWND, as is from a Parent window, as you know a parent window can have several children. Then Within the call to CreateDialogParamA, you have used your CALLBACK function DialogFunc without the (,,,..) to initialize it.

C++
MT4_EXPFUNC int MetaTest(HWND hWnd)
{
	MSG msg; 
	BOOL msgstatus; 
 
	HWND hDlg = CreateDialogParamA(g_hInstance, MAKEINTRESOURCE(IDD_METATEST), hWnd, DialogFunc, 0);


So every time you opened a new module (dialog), you didn't ShowWindow(SW_HIDE) the old one.
Then you have a While loop, that is running the 'msg' pump, and that too will show all open previously inactive child windows.
 
Share this answer
 
v4
Comments
Rezame 28-Sep-13 11:30am    
Hi,
I call this function only one time when start application no every time.
The_Inventor 29-Sep-13 21:18pm    
To be clear, you really have not made yourself clear, as to which dialog you want to see, and have not told us about the other open child windows / dialogs that you don't want to see, that maybe you want to close if you don't want to see them. Or maybe maximize the dialog, it will block the view of the others, or make a top-level window.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900