lz 你怎么创建的dialog啊?sdk 我记得是用CreateDialog这个函数吧 msdn 直接输入 CreateDialog 就出来了This function creates a modeless dialog box from a dialog box template resource. HWND CreateDialog( HINSTANCE hInstance, LPCTSTR lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc //这个就是消息响应回函数 ); Parameters hInstance [in] Handle to the module whose executable file contains the dialog box template. lpTemplate [in] Long pointer to the dialog box template. This parameter is either the pointer to a null-terminated character string that specifies the name of the dialog box template or an integer value that specifies the resource identifier of the dialog box template. If the parameter specifies a resource identifier, its high-order word must be zero and its low-order word must contain the identifier. You can use the MAKEINTRESOURCE macro to create this value. hWndParent [in] Handle to the window that owns the dialog box. lpDialogFunc [in] Long pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc. Return Values The handle to the dialog box indicates success. NULL indicates failure. To get extended error information, call GetLastError.Res The CreateDialog function uses the CreateWindowEx function to create the dialog box. CreateDialog then sends a WM_INITDIALOG message to the dialog box procedure. The function displays the dialog box if the template specifies the WS_VISIBLE style. Finally, CreateDialog returns the window handle to the dialog box. After CreateDialog returns, the application displays the dialog box (if it is not already displayed) by using the ShowWindow function. The application destroys the dialog box by using the DestroyWindow function. Microsoft® Windows® CE does not support all styles in the DLGTEMPLATE structure. This structure is in the template identified by the lpTemplate parameter.Requirements OS Versions: Windows CE 1.0 and later. Header: Winuser.h.
// Main message loop: while (GetMessage(&msg, NULL, 0, 0)) {//If the function retrieves the WM_QUIT message, the return value is zero. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); //转换某些键盘消息 DispatchMessage(&msg); //发送消息至窗口过程 } } //@@ 函数命名IsDigit,c1,c2 return msg.wParam; }可以在这个里面控制的吧
在transtalemessage之前把它过滤掉就可以了
to 5l:是消息循环,不是回调函数,你比如对话框有控件处理不了wm_keydown把
to 6l:是对话框,不是窗口,对话框有自己的messageloop
是消息循环啊 while (GetMessage(&msg, NULL, 0, 0)) 这个不是消息循环吗? 难道你的SDK代码里没有这一段?
msdn 直接输入 CreateDialog 就出来了This function creates a modeless dialog box from a dialog box template resource. HWND CreateDialog(
HINSTANCE hInstance,
LPCTSTR lpTemplate,
HWND hWndParent,
DLGPROC lpDialogFunc //这个就是消息响应回函数
);
Parameters
hInstance
[in] Handle to the module whose executable file contains the dialog box template.
lpTemplate
[in] Long pointer to the dialog box template. This parameter is either the pointer to a null-terminated character string that specifies the name of the dialog box template or an integer value that specifies the resource identifier of the dialog box template. If the parameter specifies a resource identifier, its high-order word must be zero and its low-order word must contain the identifier. You can use the MAKEINTRESOURCE macro to create this value.
hWndParent
[in] Handle to the window that owns the dialog box.
lpDialogFunc
[in] Long pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc.
Return Values
The handle to the dialog box indicates success. NULL indicates failure. To get extended error information, call GetLastError.Res
The CreateDialog function uses the CreateWindowEx function to create the dialog box. CreateDialog then sends a WM_INITDIALOG message to the dialog box procedure. The function displays the dialog box if the template specifies the WS_VISIBLE style. Finally, CreateDialog returns the window handle to the dialog box. After CreateDialog returns, the application displays the dialog box (if it is not already displayed) by using the ShowWindow function. The application destroys the dialog box by using the DestroyWindow function. Microsoft® Windows® CE does not support all styles in the DLGTEMPLATE structure. This structure is in the template identified by the lpTemplate parameter.Requirements
OS Versions: Windows CE 1.0 and later.
Header: Winuser.h.
不用自己写就是了
INT_PTR DialogBox( HINSTANCE hInstance,
LPCTSTR lpTemplate,
HWND hWndParent,
DLGPROC lpDialogFunc
);第4个参数就是消息处理过程函数.在这处理即可.
while (GetMessage(&msg, NULL, 0, 0))
{//If the function retrieves the WM_QUIT message, the return value is zero.
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg); //转换某些键盘消息
DispatchMessage(&msg); //发送消息至窗口过程
}
}
//@@ 函数命名IsDigit,c1,c2
return msg.wParam;
}可以在这个里面控制的吧
while (GetMessage(&msg, NULL, 0, 0)) 这个不是消息循环吗?
难道你的SDK代码里没有这一段?
其次,PeekMessage()调用后,如果是对话框消息(IsDialogMessage()),则接着调用TranslateMessage()和DispatchMessage();如果不是,则调用WaitMessage()让出处理器给其它线程,该线程睡眠
再次,以上步骤均在User32.dll模块中完成,所以如果你想改变消息循环流程,只有hook一条路了
非模式对话框由CreateDialogParam创建,需要你的代码维持消息循环
#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#define ImageBase ((HINSTANCE)0x40000)INT_PTR __stdcall DialogFunc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndList,hwndEdit[3];
switch (message)
{
case WM_COMMAND://这里处理WM_COMMAND消息
switch(LOWORD(wParam))
{
case IDC_ADD:
{
static wchar_t Buffer[512];
static LVITEM lvitem={LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM,2147483647,0,0,0,Buffer},lvsubitem={LVIF_TEXT,0,1,0,0,Buffer},lvsubitem2={LVIF_TEXT,0,2,0,0,Buffer};
SendMessage(hwndEdit[0],WM_GETTEXT,512,(LPARAM)Buffer);
lvsubitem.iItem=lvsubitem2.iItem=ListView_InsertItem(hwndList,&lvitem);
SendMessage(hwndEdit[1],WM_GETTEXT,512,(LPARAM)Buffer);
ListView_SetItem(hwndList,&lvsubitem);
SendMessage(hwndEdit[2],WM_GETTEXT,512,(LPARAM)Buffer);
ListView_SetItem(hwndList,&lvsubitem2);
}
break;
}
return 1;
case WM_INITDIALOG:
{
static LVCOLUMN col_H1={LVCF_TEXT|LVCF_WIDTH,0,50,TEXT("H1")},col_H2={LVCF_TEXT|LVCF_WIDTH,0,50,TEXT("H2")},col_H3={LVCF_TEXT|LVCF_WIDTH,0,50,TEXT("H3")};
hwndList=GetDlgItem(hDlg,IDC_LIST1);
hwndEdit[0]=GetDlgItem(hDlg,IDC_EDIT1);
hwndEdit[1]=GetDlgItem(hDlg,IDC_EDIT2);
hwndEdit[2]=GetDlgItem(hDlg,IDC_EDIT3);
ListView_InsertColumn(hwndList,0,&col_H1);
ListView_InsertColumn(hwndList,1,&col_H2);
ListView_InsertColumn(hwndList,2,&col_H3);
}
return 1;
case WM_CLOSE:
EndDialog(hDlg,0);
}
return 0;
}void EntryPoint(void)
{
static INITCOMMONCONTROLSEX icce={sizeof(INITCOMMONCONTROLSEX),ICC_WIN95_CLASSES};
InitCommonControlsEx(&icce);
ExitProcess(DialogBoxParam(ImageBase,MAKEINTRESOURCE(IDD_FORMVIEW),0,DialogFunc,0));
}
而你用SDK的DialogBox创建后,就直接卡着了,函数内部搞消息循环,所以你截不了它的原始消息。
至你说到不能处理WM_KEYDOWN,只是表面现象,DialogBox创建一样有方法处理。
解决方法:
方法1。用CreateDialogIndirect创建对话框,外加消息循环,然后在GetMessage或PeekMessage后里截住WM_KEYDOWN,实现所谓pretranslatemessage,跟MFC处理方法类似。
方法2。用DialogBox创建,然后处理消息WM_GETDLGCODE,返回的HRESULT值为DLGC_WANTALLKEYS|DLGC_WANTCHARS,然后你WM_KEYDOWN就有反应了!!
没有管理员改日在结,谢谢所有回答的哥们