Skip to main content
gamedev.net
🔒 Locked

Winapi again

Started by DMINATOR 9 replies 1.1k views
Original Post
DMINATOR
DMINATOR
Well here is another one of my problems i recently encountered. I create many child windows, and one of the window has child edit boxes. Now when i try to use this edit box, it doesn't responde. I don't know if it has something to do with focus, or i just messed something. Anyone got a clue ? main:

#include <windows.h>

//number of form items
#define TOTALNUM 4 

//window and object defenitions

#define WINDOW1  0

#define WINDOW2  1

#define WINDOW3  2

#define WINDOW4  3

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


int idFocus;


TCHAR szChildClass[] = TEXT ("Checker4_Child") ;

//array of MDL child windows
static      HWND  hwndarray[TOTALNUM];
static      HWND  hwndmbuttons[2];    //two buttons that select actions
static      HWND  hwndwin3[12];    //Storing all the elements of window 3


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
	static TCHAR szAppName[] = TEXT ("Checker4") ;
	HWND         hwnd ;
	MSG          msg ;
	WNDCLASS     wndclass ;
	
	wndclass.style         = 0 ;//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 (LTGRAY_BRUSH) ;
	wndclass.lpszMenuName  = NULL ;
	wndclass.lpszClassName = szAppName ;
	
	if (!RegisterClass (&wndclass))
	{
		MessageBox (NULL, TEXT ("This program requires Windows NT!"), 
			szAppName, MB_ICONERROR) ;
		return 0 ;
	}
	
	wndclass.lpfnWndProc   = ChildWndProc ;
	wndclass.cbWndExtra    = sizeof (long) ;
	wndclass.hIcon         = NULL;
	wndclass.lpszClassName = szChildClass ;
	wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
    wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH) ;

	
	RegisterClass (&wndclass) ;
	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 ;
}


creating / using child windows :

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC         hdc ;
	PAINTSTRUCT ps ;
	RECT        rect ;
	//this is our array of elements on the window

	int i;
	
	switch (message)
	{
	case WM_CREATE:
		for(i = 0; i < TOTALNUM ; i++)
		{
			//putting individual paramters for each window
			switch(i)
			{
			
			case 0:
			hwndarray = CreateWindow (szChildClass ,
				TEXT("Results"),WS_CHILDWINDOW | WS_VISIBLE |
				WS_CAPTION | WS_THICKFRAME | WS_CLIPSIBLINGS | WS_VSCROLL,
				i * 100,i * 100, 200, 200, hwnd, (HMENU) i,
				((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
			    break;

			case 1:
			hwndarray = CreateWindow (szChildClass ,
				TEXT("Actions"),WS_CHILDWINDOW | WS_VISIBLE |
				WS_CAPTION  | WS_CLIPSIBLINGS,
				i * 100,i * 100, 200, 200, hwnd, (HMENU) i,
				((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
			    break;

			case 2:
			hwndarray = CreateWindow (szChildClass ,
				TEXT("window 3"),WS_CHILDWINDOW |
				WS_CAPTION | WS_CLIPSIBLINGS,
				i * 100,i * 100, 200, 200, hwnd, (HMENU) i,
				((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
			    break;

			case 3:
			hwndarray = CreateWindow (szChildClass ,
				TEXT("window 4"),WS_CHILDWINDOW |
				WS_CAPTION  | WS_CLIPSIBLINGS,
				i * 100,i * 100, 200, 200, hwnd, (HMENU) i,
				((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
			    break;
			}
			
			
		}



		return 0 ;
		
		  case WM_DESTROY:
			  PostQuitMessage (0) ;
			  return 0 ;
	}
	return DefWindowProc (hwnd, message, wParam, lParam) ;
}

//child windows messages

LRESULT CALLBACK ChildWndProc (HWND hwnd, UINT message, 
                               WPARAM wParam, LPARAM lParam)
{
	HDC         hdc ;
	PAINTSTRUCT ps ;
	RECT        rect ;
	static int iVscrollPos;
	static int iHscrollPos;
	int i;
	int j;


	//size of window
	static int sizeX;
	static int sizeY;

	//window id
	int id = GetWindowLong (hwnd, GWL_ID) ;
	char* temp;
	
	
	switch (message)
	{
	case WM_CREATE:

	
		//drawing the second window
		if(id == WINDOW2)
		{

			//this button would show window3
		  hwndmbuttons[0] = CreateWindow ( TEXT("button"), 
                                   TEXT("Show Window 3"),
                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                   5, 5,
                                   135 , 20 ,
                                   hwnd, (HMENU) 0,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;

		  //this button would show window 4
		  hwndmbuttons[1] = CreateWindow ( TEXT("button"), 
                                   TEXT("Show Window 4"),
                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                   5, 29,
                                   135 , 20 ,
                                   hwnd, (HMENU) 1,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;

    	 	MoveWindow(hwnd,0,220,150,80,TRUE);
		}
		
		if(id == WINDOW3)
		{
           MoveWindow(hwnd,300,220,300,300,TRUE);
		
           //creating items :

		   //big TOP GROUP BOX
           hwndwin3[0] = CreateWindow ( TEXT("button"), 
                                   TEXT("Results:"),
                                   WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
                                   2, 0,
                                   sizeX - 5 , sizeY - 50 ,
                                   hwnd, (HMENU) 0,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
		   //little DOWN GROUP BOX
           hwndwin3[1] = CreateWindow ( TEXT("button"), 
                                   TEXT(""),
                                   WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
                                   2, sizeY - 50 ,
                                   sizeX - 5 ,sizeY - (sizeY - 50) - 3 ,
                                   hwnd, (HMENU) 0,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;

		   //CANCEL BUTTON - ID = 1
           hwndwin3[2] = CreateWindow ( TEXT("button"), 
                                   TEXT("CANCEL"),
                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                   sizeX - 100, sizeY - 30 ,
                                   85 ,20 ,
                                   hwnd, (HMENU) 1,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
		    //OK BUTTON - ID = 2
           hwndwin3[3] = CreateWindow ( TEXT("button"), 
                                   TEXT("OK"),
                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                   sizeX - 190, sizeY - 30 ,
                                   85 ,20 ,
                                   hwnd, (HMENU) 2,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
		    //LABEL 1
           hwndwin3[4] = CreateWindow ( TEXT("STATIC"), 
                                   TEXT("Please enter first parmaters :"),
                                   WS_CHILD | WS_VISIBLE | SS_CENTER ,
                                   10, 14 ,
                                   200 ,20 ,
                                   hwnd, (HMENU) -1,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;

		   //EDIT1 - ID = 3 (Winning numbers)
           hwndwin3[5] = CreateWindow ( TEXT("edit"), 
                                   NULL,
                                   WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |ES_AUTOHSCROLL,
                                   10, 35 ,
                                   sizeX - 20 ,20 ,
                                   hwnd, (HMENU) 3,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
		    //LABEL 2
           hwndwin3[6] = CreateWindow ( TEXT("STATIC"), 
                                   TEXT("Tour N :"),
                                   WS_CHILD | WS_VISIBLE | SS_CENTER ,
								   10, 60 ,
                                   55 ,20 ,
                                   hwnd, (HMENU) -1,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;

		    //EDIT2 - ID = 4 (Number of tour)
           hwndwin3[7] = CreateWindow ( TEXT("edit"), 
                                   NULL,
                                   WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT|ES_NUMBER ,
                                   10, 75 ,
                                   55 ,20 ,
                                   hwnd, (HMENU) 4,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
		    //LABEL 3
           hwndwin3[8] = CreateWindow ( TEXT("STATIC"), 
                                   TEXT("Date :"),
                                   WS_CHILD | WS_VISIBLE | SS_CENTER ,
                                   80, 60 ,
                                   55 ,20 ,
                                   hwnd, (HMENU) -1,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
		   //EDIT3 - ID = 5 (Date of tour)
           hwndwin3[9] = CreateWindow ( TEXT("edit"), 
                                   NULL,
                                   WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT ,
                                   80, 75 ,
                                   80 ,20 ,
                                   hwnd, (HMENU) 5,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
		     //LABEL 4
           hwndwin3[10] = CreateWindow ( TEXT("STATIC"), 
                                   TEXT("Time :"),
                                   WS_CHILD | WS_VISIBLE | SS_CENTER ,
                                   170, 60 ,
                                   55 ,20 ,
                                   hwnd, (HMENU) -1,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;

		   //EDIT4 - ID = 6 (Date of tour)
           hwndwin3[11] = CreateWindow ( TEXT("edit"), 
                                   NULL,
                                   WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT ,
                                   170, 75 ,
                                   80 ,20 ,
                                   hwnd, (HMENU) 6,
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
		}

		if(id == WINDOW4)
		{
           MoveWindow(hwnd,300,220,300,300,TRUE);
	

		}

		SetFocus (hwndmbuttons[0]) ;


		return 0 ;
  
    case WM_COMMAND:
		
		//working with individual window
        switch(id)
		{
        case WINDOW1: break;

        case WINDOW2: // Showing 3 window
				      if(LOWORD(wParam) == 0)
					  {
		
					  ShowWindow(hwndarray[2],TRUE);
					  SetFocus (hwndarray[2]);
					  ShowWindow(hwndarray[3],FALSE);
		
				
					  }
					  else //showing forth window
					  {
						 
						  ShowWindow(hwndarray[3],TRUE);
						  SetFocus (hwndarray[3]);
					      ShowWindow(hwndarray[2],FALSE);
						  
					  }
			
			          break;
  
			       
	


		}
	

        return 0;

      case WM_SIZE:
		sizeX = LOWORD (lParam) ;
		sizeY = HIWORD (lParam) ;
		
		return 0;
    
		
	}
	
	
	return DefWindowProc (hwnd, message, wParam, lParam) ;
}



Nytegard
Nytegard
OK, the problem you have is actually expected behavior.

WS_CHILDWINDOW & WS_CAPTION don't exactly work well together. You have several solutions.

A) Just don't include WS_CAPTION.

B) Use WS_POPUP if the sub windows don't have to be within the main window frame (don't make them child windows then). If they do, look at using an MDI solution instead of an SDI solution.

C) Forward the focus messages, mouse messages, and keyboard messages to the windows that actually need them.

This is a very common problem, but unfortunately, there isn't exactly an easy solution to this. Even the MDI solution is a hacked version so to speak of the SDI solution by Microsoft.
DMINATOR
DMINATOR
Thank's for reply. I understand now that i have to pass focus and other messages to childs, and i actually know how to do that :

 case WM_COMMAND:				//working with individual window        switch(id)		{        case WINDOW1: break;        case WINDOW2: // Showing 3 window				      if(LOWORD(wParam) == 0)					  {							  ShowWindow(hwndarray[2],TRUE);					  SetFocus (hwndarray[2]);					  ShowWindow(hwndarray[3],FALSE);											  }					  else //showing forth window					  {						 						  ShowWindow(hwndarray[3],TRUE);						  SetFocus (hwndarray[3]);					      ShowWindow(hwndarray[2],FALSE);						  					  }						          break;		case WINDOW3: 			          switch(LOWORD(wParam))					  {	                  case 1:   	   MessageBox(NULL,"CANCEL BUTTON","LALLA",0);break;					  case 2:   	   MessageBox(NULL,"OK BUTTON","LALLA",0);break;						  case 3:          MessageBox(NULL,"EDIT1","LALLA",0); break;					  }				}


but i actually can operate only with buttons and form area. If i try to click on any edit box, messages WM_LBUTTONDOWN and WM_COMMAND are not even processed, i think there is some other default message that takes this processing. Am I right or wrong ?
Skizz
Skizz
You need to add an 'IsDialogMessage' call to your message pump:
get messagemessage processed = falsefor each window    if IsDialogMessage (window, &msg)        message processed = true        exit loop    end ifend forif !message processed    TranslateMessage ()    DispatchMessage ()end if

Then your edit control will work as expected.

Also, don't create all those controls by hand (the 'hwndwin3[n] = CreateWindow (...)' calls), create a dialog box using a resource editor. It's much cleaner and easier to understand and maintain.

Skizz
DMINATOR
DMINATOR
I got it this way,but it is still the same . Am i missing something ?

     BOOL processedm = 0 ;          .     .     .	while (GetMessage (&msg, NULL, 0, 0))	{	    processedm = FALSE;		for(i = 0; i < 12; i++)		{			if (IsDialogMessage(hwndwin3, &msg))			{								processedm = TRUE;					break;			}		}		if(!processedm)		{		TranslateMessage (&msg) ;		DispatchMessage (&msg) ;		}	}	return msg.wParam ;


Here is complete code i have right now
#include <windows.h>//number of form items#define TOTALNUM 4 //window and object defenitions#define WINDOW1  0#define WINDOW2  1#define WINDOW3  2#define WINDOW4  3LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;LRESULT CALLBACK ChildWndProc (HWND, UINT, WPARAM, LPARAM) ;int idFocus;TCHAR szChildClass[] = TEXT ("Checker4_Child") ;//array of MDL child windowsstatic      HWND  hwndarray[TOTALNUM];static      HWND  hwndmbuttons[2];    //two buttons that select actionsstatic      HWND  hwndwin3[12];    //Storing all the elements of window 3BOOL processedm = 0 ;        //indicates that have we processed message or notint i;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,                    PSTR szCmdLine, int iCmdShow){	static TCHAR szAppName[] = TEXT ("Checker4") ;	HWND         hwnd ;	MSG          msg ;	WNDCLASS     wndclass ;		wndclass.style         = 0 ;//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 (LTGRAY_BRUSH) ;	wndclass.lpszMenuName  = NULL ;	wndclass.lpszClassName = szAppName ;		if (!RegisterClass (&wndclass))	{		MessageBox (NULL, TEXT ("This program requires Windows NT!"), 			szAppName, MB_ICONERROR) ;		return 0 ;	}		wndclass.lpfnWndProc   = ChildWndProc ;	wndclass.cbWndExtra    = sizeof (long) ;	wndclass.hIcon         = NULL;	wndclass.lpszClassName = szChildClass ;	wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;    wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH) ;		RegisterClass (&wndclass) ;	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))	{	    processedm = FALSE;		for(i = 0; i < 12; i++)		{			if (IsDialogMessage(hwndwin3, &msg))			{								processedm = TRUE;					break;			}		}		if(!processedm)		{		TranslateMessage (&msg) ;		DispatchMessage (&msg) ;		}	}	return msg.wParam ;}LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){	HDC         hdc ;	PAINTSTRUCT ps ;	RECT        rect ;	//this is our array of elements on the window	int i;		switch (message)	{	case WM_CREATE:		for(i = 0; i < TOTALNUM ; i++)		{			//putting individual paramters for each window			switch(i)			{						case 0:			hwndarray = CreateWindow (szChildClass ,				TEXT("Results"),WS_CHILDWINDOW | WS_VISIBLE |				 WS_CAPTION  |WS_THICKFRAME | WS_CLIPSIBLINGS | WS_VSCROLL,				i * 100,i * 100, 200, 200, hwnd, (HMENU) i,				((LPCREATESTRUCT) lParam)->hInstance, NULL) ;			    break;			case 1:			hwndarray = CreateWindow (szChildClass ,				TEXT("Actions"),WS_CHILDWINDOW | WS_VISIBLE |				WS_CAPTION  | WS_CLIPSIBLINGS,				i * 100,i * 100, 200, 200, hwnd, (HMENU) i,				((LPCREATESTRUCT) lParam)->hInstance, NULL) ;			    break;			case 2:			hwndarray = CreateWindow (szChildClass ,				TEXT("window 3"),WS_CHILDWINDOW| 				 WS_CAPTION  | WS_CLIPSIBLINGS ,				i * 100,i * 100, 200, 200, hwnd, (HMENU) i,				((LPCREATESTRUCT) lParam)->hInstance, NULL) ;			    break;			case 3:			hwndarray = CreateWindow (szChildClass ,				TEXT("window 4"),WS_CHILDWINDOW |				WS_CAPTION  | WS_CLIPSIBLINGS,				i * 100,i * 100, 200, 200, hwnd, (HMENU) i,				((LPCREATESTRUCT) lParam)->hInstance, NULL) ;			    break;			}								}		return 0 ;				  case WM_DESTROY:			  PostQuitMessage (0) ;			  return 0 ;	}	return DefWindowProc (hwnd, message, wParam, lParam) ;}//child windows messagesLRESULT CALLBACK ChildWndProc (HWND hwnd, UINT message,                                WPARAM wParam, LPARAM lParam){	HDC         hdc ;	PAINTSTRUCT ps ;	RECT        rect ;	static int iVscrollPos;	static int iHscrollPos;	//size of window	static int sizeX;	static int sizeY;	//window id	int id = GetWindowLong (hwnd, GWL_ID) ;	char* temp;			switch (message)	{	case WM_CREATE:			//drawing the second window		if(id == WINDOW2)		{			//this button would show window3		  hwndmbuttons[0] = CreateWindow ( TEXT("button"),                                    TEXT("Show Window 3"),                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,                                   5, 5,                                   135 , 20 ,                                   hwnd, (HMENU) 0,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		  //this button would show window 4		  hwndmbuttons[1] = CreateWindow ( TEXT("button"),                                    TEXT("Show Window 4"),                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,                                   5, 29,                                   135 , 20 ,                                   hwnd, (HMENU) 1,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;    	 	MoveWindow(hwnd,0,220,150,80,TRUE);		}				if(id == WINDOW3)		{           MoveWindow(hwnd,300,220,300,300,TRUE);		           //creating items :		   //big TOP GROUP BOX           hwndwin3[0] = CreateWindow ( TEXT("button"),                                    TEXT("Results:"),                                   WS_CHILD | WS_VISIBLE | BS_GROUPBOX,                                   2, 0,                                   sizeX - 5 , sizeY - 50 ,                                   hwnd, (HMENU) 0,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		   //little DOWN GROUP BOX           hwndwin3[1] = CreateWindow ( TEXT("button"),                                    TEXT(""),                                   WS_CHILD | WS_VISIBLE | BS_GROUPBOX,                                   2, sizeY - 50 ,                                   sizeX - 5 ,sizeY - (sizeY - 50) - 3 ,                                   hwnd, (HMENU) 0,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		   //CANCEL BUTTON - ID = 1           hwndwin3[2] = CreateWindow ( TEXT("button"),                                    TEXT("CANCEL"),                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,                                   sizeX - 100, sizeY - 30 ,                                   85 ,20 ,                                   hwnd, (HMENU) 1,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		    //OK BUTTON - ID = 2           hwndwin3[3] = CreateWindow ( TEXT("button"),                                    TEXT("OK"),                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,                                   sizeX - 190, sizeY - 30 ,                                   85 ,20 ,                                   hwnd, (HMENU) 2,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		    //LABEL 1           hwndwin3[4] = CreateWindow ( TEXT("STATIC"),                                    TEXT("Please enter first parmaters :"),                                   WS_CHILD | WS_VISIBLE | SS_CENTER ,                                   10, 14 ,                                   200 ,20 ,                                   hwnd, (HMENU) -1,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		   //EDIT1 - ID = 3 (Winning numbers)           hwndwin3[5] = CreateWindow ( TEXT("edit"),                                    NULL,                                   WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |ES_AUTOHSCROLL,                                   10, 35 ,                                   sizeX - 20 ,20 ,                                   hwnd, (HMENU) 3,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		    //LABEL 2           hwndwin3[6] = CreateWindow ( TEXT("STATIC"),                                    TEXT("Tour N :"),                                   WS_CHILD | WS_VISIBLE | SS_CENTER ,								   10, 60 ,                                   55 ,20 ,                                   hwnd, (HMENU) -1,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		    //EDIT2 - ID = 4 (Number of tour)           hwndwin3[7] = CreateWindow ( TEXT("edit"),                                    NULL,                                   WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT|ES_NUMBER ,                                   10, 75 ,                                   55 ,20 ,                                   hwnd, (HMENU) 4,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		    //LABEL 3           hwndwin3[8] = CreateWindow ( TEXT("STATIC"),                                    TEXT("Date :"),                                   WS_CHILD | WS_VISIBLE | SS_CENTER ,                                   80, 60 ,                                   55 ,20 ,                                   hwnd, (HMENU) -1,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		   //EDIT3 - ID = 5 (Date of tour)           hwndwin3[9] = CreateWindow ( TEXT("edit"),                                    NULL,                                   WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT ,                                   80, 75 ,                                   80 ,20 ,                                   hwnd, (HMENU) 5,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		     //LABEL 4           hwndwin3[10] = CreateWindow ( TEXT("STATIC"),                                    TEXT("Time :"),                                   WS_CHILD | WS_VISIBLE | SS_CENTER ,                                   170, 60 ,                                   55 ,20 ,                                   hwnd, (HMENU) -1,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		   //EDIT4 - ID = 6 (Date of tour)           hwndwin3[11] = CreateWindow ( TEXT("edit"),                                    NULL,                                   WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT ,                                   170, 75 ,                                   80 ,20 ,                                   hwnd, (HMENU) 6,                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;		}		if(id == WINDOW4)		{           MoveWindow(hwnd,300,220,300,300,TRUE);			}		SetFocus (hwndmbuttons[0]) ;		return 0 ;      case WM_COMMAND:				//working with individual window        switch(id)		{        case WINDOW1: break;        case WINDOW2: // Showing 3 window				      if(LOWORD(wParam) == 0)					  {							  ShowWindow(hwndarray[2],TRUE);					  SetFocus (hwndarray[2]);					  ShowWindow(hwndarray[3],FALSE);											  }					  else //showing forth window					  {						 						  ShowWindow(hwndarray[3],TRUE);						  SetFocus (hwndarray[3]);					      ShowWindow(hwndarray[2],FALSE);						  					  }						          break;		case WINDOW3: 			          switch(LOWORD(wParam))					  {	                  case 1:   	   MessageBox(NULL,"CANCEL BUTTON","LALLA",0);break;					  case 2:   	   MessageBox(NULL,"OK BUTTON","LALLA",0);break;						  case 3:          MessageBox(NULL,"EDIT1","LALLA",0); break;					  }		     return 0;		}        case WM_LBUTTONDOWN:			{               MessageBox(NULL,"MOUSE","LALLA",0);				return 0;			}      case WM_SIZE:		sizeX = LOWORD (lParam) ;		sizeY = HIWORD (lParam) ;				return 0;    			}			return DefWindowProc (hwnd, message, wParam, lParam) ;}
Skizz
Skizz
No, the IsDialogMessage requires the parent window handle of the control, not the control itself, so you only need to do it for the four hwndarray windows and the root window.

Skizz
DMINATOR
DMINATOR
I changed to that :) Still the same . But WM_LBUTTONDOWN: gets message twice.

	while (GetMessage (&msg, NULL, 0, 0))	{	    processedm = FALSE;		for(i = 0; i < TOTALNUM; i++)		{			if (IsDialogMessage(hwndarray, &msg))			{								processedm = TRUE;					break;			}		}		if (IsDialogMessage(hwnd, &msg))			{								processedm = TRUE;			}		if(!processedm)		{		TranslateMessage (&msg) ;		DispatchMessage (&msg) ;		}	}
Skizz
Skizz
There's some more to change:
1) change WS_CAPTION to WS_DLGFRAME (you won't be able to drag the windows around).
2) change 'if (IsDialogMessage(hwnd, &msg))' to 'if (!processedm && IsDialogMessage(hwnd, &msg))'
3) remove 'MessageBox (NULL,"EDIT1","LALLA",0);' (this was causing the input box to lose its focus).

However, your overall structure is flawed. Firstly, it really is better to use a dialog resource to define your windows and use CreateDialog instead of doing it all manually. Secondly, like C++ and other OO systems, a window class should only have one function. Create a separate class for each type of window you have rather than getting the one class to do everything. Use subclassing to modify behaviour of another class. It'll just work out easier in the long run.

Skizz
DMINATOR
DMINATOR
Hmm i still want to move windows around. Ok it seems there is no clear solution, but maybe someone can post a code or link, where it's easyly shown how to make applications of this type. I couldn't find it myself, and had to make something up.
DMINATOR
DMINATOR
I looked a bit on MDI window code, and got them working without a problem,but there is one thing I am missing. The MDI child window style, I don't know how to change it. Can anyone help ?

Il post a code where i create child windows in FrameWindow WM_CREATE

 case WM_CREATE:           // Create the client window                    clientcreate.hWindowMenu  = hMenuInit ;          clientcreate.idFirstChild = IDM_FIRSTCHILD ;                    hwndClient = CreateWindow (TEXT ("MDICLIENT"), NULL,                                     WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,                                        0, 0, 0, 0, hwnd, (HMENU) 1, hInst,                                     (PSTR) &clientcreate) ;		  //let's try to create simple results window:               mdicreate.szClass = szResultsClass ;               mdicreate.szTitle = TEXT ("Results") ;               mdicreate.hOwner  = hInst ;               mdicreate.x       = CW_USEDEFAULT ;               mdicreate.y       = CW_USEDEFAULT ;               mdicreate.cx      = 100 ;               mdicreate.cy      = 100 ;               mdicreate.style   = 0;               mdicreate.lParam  = 0 ;                              hwndChild = (HWND) SendMessage (hwndClient,                                   WM_MDICREATE,0,                                   (LPARAM) (LPMDICREATESTRUCT) &mdicreate) ;			//let's try to create simple results window:               mdicreate.szClass = szSelectClass ;               mdicreate.szTitle = TEXT ("Selecting") ;               mdicreate.hOwner  = hInst ;               mdicreate.x       = 120 ;               mdicreate.y       = 0 ;               mdicreate.cx      = 100 ;               mdicreate.cy      = 100 ;               mdicreate.style   = 0 ;               mdicreate.lParam  = 0 ;                              hwndChild = (HWND) SendMessage (hwndClient,                                   WM_MDICREATE, 0,                                   (LPARAM) (LPMDICREATESTRUCT) &mdicreate) ;          return 0 ;
DMINATOR
DMINATOR
Ok moving further and I found a way to change style of MDI child, but it doesn't work correctly

//changing style of window ALL OK
SetWindowLong(hwndChild, GWL_style,WS_CHILDWINDOW | WS_CAPTION | WS_VISIBLE | WS_CLIPSIBLINGS | WS_THICKFRAME);


But if i want' not resizable child and i use this ->

//changing style of window PROBLEM
SetWindowLong(hwndChild, GWL_style,WS_CHILDWINDOW | WS_CAPTION | WS_VISIBLE | WS_CLIPSIBLINGS);

This makes a problem client area near window border is not redrawn correctly. I must be doing something wrong ...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.