我的程序中没有对话框 [英] Not getting Dialogbox in my program

查看:58
本文介绍了我的程序中没有对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#pragma comment(lib,"IPHlpApi.Lib") 
#pragma comment(lib, "ws2_32.lib")

#include "windows.h"
#include <iphlpapi.h>		//IP Helper api
#include "resource.h"

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
BOOL    CALLBACK IpDlgProc (HWND, UINT, WPARAM, LPARAM) ;

TCHAR szAppName[] = TEXT ("Fire") ;
//HWND hwnd;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     HWND     hwnd ;
     MSG      msg ;
     WNDCLASS wndclass ;
     
     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
     wndclass.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1); ;
     wndclass.lpszClassName = szAppName ;
     
     if (!RegisterClass (&wndclass))
     {
          MessageBox (NULL, TEXT ("This program requires Windows NT!"),
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }
     
     hwnd = CreateWindow (szAppName, TEXT ("Fire"),
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          NULL, NULL, hInstance, NULL) ;

     
     ShowWindow (hwnd, iCmdShow) ;
     UpdateWindow (hwnd) ;
  
     while (GetMessage (&msg, NULL, 0, 0))
     {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
     }
     return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	 static HINSTANCE hInstance ;    
     HMENU      hMenu ;
     
     switch (message)
     {

	 case WM_CREATE :
          hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
          return 0 ;

     case WM_COMMAND:
          hMenu = GetMenu (hwnd) ;
          
          switch (LOWORD (wParam))
          {
                       
          case ID_FILE_EXIT:
               SendMessage (hwnd, WM_CLOSE, 0, 0) ;
               return 0 ;
               
        
		  case ID_TOOL_GETIPINFO:
			  DialogBox (hInstance, TEXT ("AboutBox"), hwnd, IpDlgProc) ;              
			  break;

          case ID_HELP_HELP:
               MessageBox (hwnd, TEXT ("Help not yet implemented!"),
                           szAppName, MB_ICONEXCLAMATION | MB_OK) ;
               return 0 ;
               
          case ID_HELP_ABOUT:
               MessageBox (hwnd, TEXT ("Project By\n\n"),
                           szAppName, MB_ICONINFORMATION | MB_OK) ;
               return 0 ;
          }
          break ;
          
         case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}

BOOL CALLBACK IpDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
     switch (message)
     {
     case WM_INITDIALOG :
          return TRUE ;
          
     case WM_COMMAND :
          switch (LOWORD (wParam))
          {
          case IDOK :
          case IDCANCEL :
               EndDialog (hDlg, 0) ;
               return TRUE ;
          }
          break ;
     }
     return FALSE ;
}

推荐答案

好像对DialogBox的调用对我来说很麻烦.我还没有听说过一个名为"AboutBox"的DialogTemplate.这是您在其他地方实现的吗?

我更习惯使用resource_id来调用它,以将对话框从exe的资源部分中拉出.


DialogBox(hInstance,MAKEINTRESOURCE(IDD_ABOUT_BOX),hwnd,lpDlgProc);

其中IDD_ABOUT_BOX是在某处#define定义的,并用作资源编辑器中对话框的资源标识符.
Looks like the call to DialogBox is screwy to me. I''ve not heard of a DialogTemplate called "AboutBox". Is this something you have implemented elsewhere?

I''m more used to calling this using a resource_id to pull a dialog box out of the exe''s resource section.

I.e
DialogBox(hInstance, MAKEINTRESOURCE(IDD_ABOUT_BOX), hwnd, lpDlgProc);

Where IDD_ABOUT_BOX is #defined somewhere and is used as the resource identifier for the dialog in the resource editor.


DialogBox(hInstance,TEXT("AboutBox"),hwnd,IpDlgProc)

第三个参数应为MAKEINTRESOURCE(IDD_DIALOG1)
其中IDD_DIALOG1是dilogbox的ID

对话框(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,IpDlgProc)
DialogBox (hInstance, TEXT ("AboutBox"), hwnd, IpDlgProc)

3rd parameter should be MAKEINTRESOURCE(IDD_DIALOG1)
where IDD_DIALOG1 is the id of dilogbox

DialogBox (hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, IpDlgProc)


这篇关于我的程序中没有对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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