在Win32中使用CreateDialogParamA [英] Using CreateDialogParamA In Win32

查看:319
本文介绍了在Win32中使用CreateDialogParamA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有win32 dll,它使用CreateDialogParamA函数使父"窗口的小对话框前面.父窗口包括不同的窗口,每个窗口都有特定的HWND.
问题是当我可以使用具有唯一HWND的CreateDialogParamA时,这将显示具有不同HWND的所有窗口的对话框.
是否有任何C ++函数将此对话框限制为调用该对话框的HWND?

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?

// 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;
}



例如,在上面的代码中,我用唯一的hWnd调用了MetaTest函数.我希望它为此hWnd显示此对话框,但也要在父"窗口中为其他活动的hWnd显示此对话框.
我想修复仅显示此hwnd对话框的问题.
问候,



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,

推荐答案

首先,为了适当处理各种事情,您可能希望完成案例条件:

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

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;



然后,也许在您的MetaTest中,您已经通过父窗口传递了HWND,因为您知道父窗口可以有多个子窗口.然后,在对CreateDialogParamA的调用中,您使用了CALLBACK函数DialogFunc,而没有使用(,, ...)对其进行初始化.



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.

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



因此,每次打开一个新模块(对话框)时,您并没有显示旧的ShowWindow(SW_HIDE).
然后,您将获得一个While循环,该循环正在运行"msg"泵,并且该循环还将显示所有打开的先前处于非活动状态的子窗口.



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.


这篇关于在Win32中使用CreateDialogParamA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆