API 编程 对话框问题 求大牛解答
API编程时调用对话框和消息盒时有时显示出来,有时就显示不出来,显示不出来后,我就来回切换其他应用程序和我编出来的程序,切换几次就好了,以前编的东西都没有这种问题,求大牛...
API编程时 调用对话框和消息盒时 有时显示出来,有时就显示不出来,显示不出来后,我就来回切换其他应用程序和我编出来的程序,切换几次就好了,以前编的东西都没有这种问题,求大牛。
展开
展开全部
这是我抄书上的一个程序,但是不能够正确允许,点击菜单的时候,对话框不能显示出来。程序如下,请大家给看看,谢谢!
资源文件:
//Microsoft Developer Studio generated resource script.
//
#include "resource.h "
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h "
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Chinese (P.R.C.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
ABOUT1 MENU DISCARDABLE
BEGIN
POPUP "帮助 "
BEGIN
MENUITEM "帮助主题 ", IDM_HELP
MENUITEM "关于 ", IDM_ABOUT
END
END
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0 "
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include " "afxres.h " "\r\n "
"\0 "
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n "
"\0 "
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
ABOUTBOX DIALOG DISCARDABLE 0, 0, 187, 94
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog "
FONT 10, "System "
BEGIN
DEFPUSHBUTTON "OK ",IDOK,130,7,50,14
PUSHBUTTON "Cancel ",IDCANCEL,130,24,50,14
LTEXT "关于 ",IDC_STATIC,38,29,63,26
COMBOBOX IDC_COMBO1,94,47,48,30,CBS_DROPDOWN | CBS_SORT |
WS_VSCROLL | WS_TABSTOP
END
HELP DIALOG DISCARDABLE 0, 0, 187, 94
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog "
FONT 10, "System "
BEGIN
DEFPUSHBUTTON "OK ",IDOK,130,7,50,14
PUSHBUTTON "Cancel ",IDCANCEL,130,24,50,14
LTEXT "帮助 ",IDC_STATIC,49,29,39,36
END
IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 187, 94
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog "
FONT 10, "System "
BEGIN
DEFPUSHBUTTON "OK ",IDOK,130,7,50,14
PUSHBUTTON "Cancel ",IDCANCEL,130,24,50,14
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 180
TOPMARGIN, 7
BOTTOMMARGIN, 87
END
HELP, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 180
TOPMARGIN, 7
BOTTOMMARGIN, 87
END
IDD_DIALOG1, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 180
TOPMARGIN, 7
BOTTOMMARGIN, 87
END
END
#endif // APSTUDIO_INVOKED
#endif // Chinese (P.R.C.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
自动生成的头文件resource.h:
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Script1.rc
//
#define ABOUT1 101
#define ABOUTBOX 102
#define HELP 103
#define IDD_DIALOG1 104
#define IDC_COMBO1 1000
#define IDM_HELP 40001
#define IDM_ABOUT 40002
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40003
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
程序文件:
#include <windows.h>
#include "resource.h "
HWND hWndModeless=NULL;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//对话框窗口处理函数
BOOL CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK HelpDlgProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static char szAppName[] = "About1 " ;
MSG msg ;
HWND hwnd ;
WNDCLASSEX wndclass ;
HMENU hMenu;
hMenu=LoadMenu(hInstance,MAKEINTRESOURCE(ABOUT1));
wndclass.cbSize = sizeof (wndclass) ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (hInstance, szAppName) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = szAppName ;
wndclass.lpszClassName = szAppName ;
wndclass.hIconSm = LoadIcon (hInstance, szAppName) ;
RegisterClassEx (&wndclass) ;
hwnd = CreateWindow (szAppName, "对话框示例 ",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL,hMenu, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{//截获非模态对话框消息并发往处理函数
if(!IsDialogMessage(hWndModeless,&msg))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static WNDPROC lpfnAboutDlgProc ;
static HINSTANCE hInstance ;
switch (iMsg)
{
case WM_CREATE :
hInstance = ((LPCREATESTRUCT) lParam)-> hInstance ;
return 0 ;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDM_ABOUT :
//调用DialogBox函数显示模态对话框
DialogBox (hInstance, "ABOUTBOX ", hwnd, AboutDlgProc) ;
return 0 ;
case IDM_HELP:
//调用CreateDialog函数显示非模态对话框
hWndModeless=CreateDialog(hInstance, "HELP ", hwnd, HelpDlgProc);
ShowWindow(hWndModeless,SW_SHOW);
}
break ;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_INITDIALOG :
return TRUE ;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDOK :
case IDCANCEL :
EndDialog (hDlg, 0) ; //关闭模态对话框
return TRUE ;
}
break ;
}
return FALSE ;
}
BOOL CALLBACK HelpDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_INITDIALOG :
return TRUE ;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDOK :
case IDCANCEL :
DestroyWindow(hDlg) ; //关闭非模态对话框
return TRUE ;
}
break ;
}
return FALSE ;
资源文件:
//Microsoft Developer Studio generated resource script.
//
#include "resource.h "
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h "
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Chinese (P.R.C.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
ABOUT1 MENU DISCARDABLE
BEGIN
POPUP "帮助 "
BEGIN
MENUITEM "帮助主题 ", IDM_HELP
MENUITEM "关于 ", IDM_ABOUT
END
END
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0 "
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include " "afxres.h " "\r\n "
"\0 "
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n "
"\0 "
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
ABOUTBOX DIALOG DISCARDABLE 0, 0, 187, 94
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog "
FONT 10, "System "
BEGIN
DEFPUSHBUTTON "OK ",IDOK,130,7,50,14
PUSHBUTTON "Cancel ",IDCANCEL,130,24,50,14
LTEXT "关于 ",IDC_STATIC,38,29,63,26
COMBOBOX IDC_COMBO1,94,47,48,30,CBS_DROPDOWN | CBS_SORT |
WS_VSCROLL | WS_TABSTOP
END
HELP DIALOG DISCARDABLE 0, 0, 187, 94
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog "
FONT 10, "System "
BEGIN
DEFPUSHBUTTON "OK ",IDOK,130,7,50,14
PUSHBUTTON "Cancel ",IDCANCEL,130,24,50,14
LTEXT "帮助 ",IDC_STATIC,49,29,39,36
END
IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 187, 94
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog "
FONT 10, "System "
BEGIN
DEFPUSHBUTTON "OK ",IDOK,130,7,50,14
PUSHBUTTON "Cancel ",IDCANCEL,130,24,50,14
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 180
TOPMARGIN, 7
BOTTOMMARGIN, 87
END
HELP, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 180
TOPMARGIN, 7
BOTTOMMARGIN, 87
END
IDD_DIALOG1, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 180
TOPMARGIN, 7
BOTTOMMARGIN, 87
END
END
#endif // APSTUDIO_INVOKED
#endif // Chinese (P.R.C.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
自动生成的头文件resource.h:
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Script1.rc
//
#define ABOUT1 101
#define ABOUTBOX 102
#define HELP 103
#define IDD_DIALOG1 104
#define IDC_COMBO1 1000
#define IDM_HELP 40001
#define IDM_ABOUT 40002
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40003
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
程序文件:
#include <windows.h>
#include "resource.h "
HWND hWndModeless=NULL;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//对话框窗口处理函数
BOOL CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK HelpDlgProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static char szAppName[] = "About1 " ;
MSG msg ;
HWND hwnd ;
WNDCLASSEX wndclass ;
HMENU hMenu;
hMenu=LoadMenu(hInstance,MAKEINTRESOURCE(ABOUT1));
wndclass.cbSize = sizeof (wndclass) ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (hInstance, szAppName) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = szAppName ;
wndclass.lpszClassName = szAppName ;
wndclass.hIconSm = LoadIcon (hInstance, szAppName) ;
RegisterClassEx (&wndclass) ;
hwnd = CreateWindow (szAppName, "对话框示例 ",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL,hMenu, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{//截获非模态对话框消息并发往处理函数
if(!IsDialogMessage(hWndModeless,&msg))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static WNDPROC lpfnAboutDlgProc ;
static HINSTANCE hInstance ;
switch (iMsg)
{
case WM_CREATE :
hInstance = ((LPCREATESTRUCT) lParam)-> hInstance ;
return 0 ;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDM_ABOUT :
//调用DialogBox函数显示模态对话框
DialogBox (hInstance, "ABOUTBOX ", hwnd, AboutDlgProc) ;
return 0 ;
case IDM_HELP:
//调用CreateDialog函数显示非模态对话框
hWndModeless=CreateDialog(hInstance, "HELP ", hwnd, HelpDlgProc);
ShowWindow(hWndModeless,SW_SHOW);
}
break ;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_INITDIALOG :
return TRUE ;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDOK :
case IDCANCEL :
EndDialog (hDlg, 0) ; //关闭模态对话框
return TRUE ;
}
break ;
}
return FALSE ;
}
BOOL CALLBACK HelpDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_INITDIALOG :
return TRUE ;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDOK :
case IDCANCEL :
DestroyWindow(hDlg) ; //关闭非模态对话框
return TRUE ;
}
break ;
}
return FALSE ;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询