每当我单击编辑控件时,组合框区域对话框都会关闭. [英] When ever i click on edit control and combo box area dialog box get close.

查看:81
本文介绍了每当我单击编辑控件时,组合框区域对话框都会关闭.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <windows.h>
#include "resource.h"

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

BOOL    CALLBACK AddRuleDlgProc (HWND, UINT, WPARAM, LPARAM) ;

void AddRule(HWND hAddRuleDlg);


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static TCHAR szAppName[] = TEXT ("HelloWin") ;
     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,                  // window class name
                          TEXT ("The Hello Program"), // window caption
                          WS_OVERLAPPEDWINDOW,        // window style
                          CW_USEDEFAULT,              // initial x position
                          CW_USEDEFAULT,              // initial y position
                          CW_USEDEFAULT,              // initial x size
                          CW_USEDEFAULT,              // initial y size
                          NULL,                       // parent window handle
                          NULL,                       // window menu handle
                          hInstance,                  // program instance handle
                          NULL) ;                     // creation parameters
     
     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)
{
     HDC         hdc ;
     PAINTSTRUCT ps ;
     RECT        rect ;
     
	 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:
			   DialogBox (hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, AddRuleDlgProc) ;            
			   break;
          }
          break ; 
	 case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}


// Dailag Box for Adding Rules
BOOL CALLBACK AddRuleDlgProc (HWND hAddRuleDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	 static int lPort,rPort;
	 static TCHAR ipLocAddr[40],ipRemAddr[40],ipLocMask[40],ipRemMask[40];
	 
	 switch (message)
     {
     case WM_INITDIALOG :
		   //AddRule(hAddRuleDlg);
		    return TRUE ;

     case WM_COMMAND :
          switch (LOWORD (wParam))
          {
          case IDOK :
			   GetDlgItemText(hAddRuleDlg,IDC_EDIT1,ipLocAddr,40);
			   
          case IDCLOSE :
               EndDialog (hAddRuleDlg, 0);
               return TRUE ;
          }

	 case WM_CLOSE:

		 EndDialog(hAddRuleDlg,0);
		  return TRUE ;
          break ;
     }
     return FALSE ;
}


每当我单击编辑控件,组合框区域对话框就会关闭.

如何在对话框和组合框中打印初始值?


When ever I click on edit control and combo box area dialog box get close.

How to print initial value in the dialog box and combo box?
and how to get values after clicking on OK button.

推荐答案

在此之后
开关(LOWORD(wParam))
{
案例IDOK:
GetDlgItemText(hAddRuleDlg,IDC_EDIT1,ipLocAddr,40);

案例IDCLOSE:
EndDialog(hAddRuleDlg,0);
返回TRUE;
}

我插入返回TRUE;现在工作正常.
After this
switch (LOWORD (wParam))
{
case IDOK :
GetDlgItemText(hAddRuleDlg,IDC_EDIT1,ipLocAddr,40);

case IDCLOSE :
EndDialog (hAddRuleDlg, 0);
return TRUE ;
}

i inserted return TRUE; and now it is working fine.


这篇关于每当我单击编辑控件时,组合框区域对话框都会关闭.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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