Click here to Skip to main content
15,905,414 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C++
#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.
Posted
Updated 9-Mar-12 7:09am
v3

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900