Buttons Pop up [Part-2]
 
Hello,
If you are not familiar with the question of this post, you can get a quick 
glimps at its description at the first part of this post called "Buttons Pop 
up!"
The reason I started a new post on the same question is so I don't clutter 
up the previous post! So here is a clean start!
I have taken the advice of a news groups fellow to strip down my program so 
I can isolate the problem, and I did, however the situation still persists. I 
call this a "situation" because at this point, I don't know if the problem I 
am facing is normal when creating a windows with CreateWindow();
In short, I now have two (2) windows, and therefore it means I have 2 
WndProc's,
WndProc.cpp and WndProc_CW2.cpp which we will call Window#1 and Window #2 
respectively. I also have a Main.cpp for the good old Windows message pump!
The first window is based on WndProc.cpp with one(1) button which opens 
a child window based on WndProc_CW2.pp. I also have an exit button on the 
first window which is of no relevance to this issue.
So when I click on a button on window#1, it opens window#2, and do you agree 
that some space on the second  window is right above some buttons of the 
first window right underneath.... right! (lets call this space "space X"). So 
space 
X is the space that is on my second window where it aligns directly with the 
space containing a button on the opened window #1 which is right behind it.
If I click on some of its space X, well, the button from the underneath 
window, pops up in the top window(window #2) currently open. ??? I can even 
move window#2 around and this newly poped up button stays in the client area!
Does anyone have any I deas of what could be going on !
Here is a watered down skeleton of the app, it contains 6 very small files!
Here's the code:
-Excuse me if its a long post....You would not believe how much code I 
removed... however if you feel its still too long, its no problem, let me 
know and I will repost a shorter version. Although, it only looks long 
however its all basic routine  code that is very common in every Windows 
code.    ============================================Main.h
//DECLARE CALLBACKS!
LRESULT CALLBACK WndProc		(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc_CW2	(HWND, UINT, WPARAM, LPARAM);
==================================================
============================================Main.cpp
#include <windows.h>	
#include "MAIN.h"	
static TCHAR *szMW_Name = TEXT ("MAIN APPLICATION 1");		
                //Name of window
static TCHAR szMW_ClassName[] = TEXT ("MW");
                //Class name of window
//Declaration of Class name for Window based on WndProc_CW2
static TCHAR szCW2_ClassName[] = TEXT("CW2");	
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInnstance,
        PSTR szCmdLine, int iCmdShow)
{
HWND	hwnd;
MSG	msg;
WNDCLASS  wndclass;
//-MAIN WINDOW CONFIGURATION based on WndProc
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 = NULL;
wndclass.lpszClassName  = szMW_ClassName;
//-REGISTRATION 
RegisterClass (&wndclass);
//-CONFIGURATION  -CHILD WINDOW #2 
wndclass.lpfnWndProc  = WndProc_CW2;
wndclass.hIcon     = LoadIcon (NULL, IDI_EXCLAMATION);
wndclass.hIcon     = NULL;
wndclass.lpszClassName  = szCW2_ClassName;
//-REGISTRATION 
RegisterClass(&wndclass);  
//-CREATE MAIN APPLICATION WINDOW
hwnd = CreateWindow (szMW_ClassName,szMW_Name,
                                   WS_OVERLAPPEDWINDOW ,
                                  20, 20, 750, 550,NULL,NULL, hInstance, 
NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow (hwnd);
//-WINDOWS MESSAGE LOOP
while (GetMessage (&msg, NULL, 0, 0))		
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
===================================================
==========================================WndPro.h
struct hdMW_WindowButtonsTAG
{
int     iCTL_idx;
TCHAR	*szMW_btC_Name;
int     MW_btC_RectLeft;		
int     MW_btC_RectTop;
int    MW_btC_RectRight;
int    MW_btC_RectBottom;
int    MW_btC_ID;
};
===================================================
==========================================WndProc.cpp
#include <windows.h>
#include "WndProc.h"		
#define CW2_ID	2					
static TCHAR *szCW2_Name = TEXT("Programming GUI");	
//Child window title bar name
extern TCHAR szCW2_ClassName[] = TEXT("CW2");		
//Child window class name . This is declared as extern because I need the 
class name as a parameter for registration of the window in Main.cpp also.
               
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                                            WPARAM wParam, LPARAM lParam)
{
//MAIN WINDOW CONTROL PROPERTIES
hdMW_WindowButtonsTAG WindowButtons[] =
{
   1,TEXT("< EXIT >"),650,450,80,40,1,
   2,TEXT("< GUI >"),200,30,180,30,2, 	
};
static  HWND	hdCWdws[1];
static  HWND	hdMW_WindowButtons[2];	//Main window buttons
int      i;
HDC                 hdc;
PAINTSTRUCT  ps;
RECT   	       rect;
switch(message)
{
case WM_CREATE:
   hdc = GetDC(hwnd);
  //MAIN WINDOW BUTTON CONTROLS
  for(i=0;i<2;i++)
    {
    hdMW_WindowButtons[i] = CreateWindow(				TEXT 
("button"),WindowButtons[i].szMW_btC_Name,
    WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON ,
    WindowButtons[i].MW_btC_RectLeft,
    WindowButtons[i].MW_btC_RectTop,
    WindowButtons[i].MW_btC_RectRight,
    WindowButtons[i].MW_btC_RectBottom,
    hwnd,(HMENU)WindowButtons[i].MW_btC_ID,
    (HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
    }
ReleaseDC(hwnd,hdc); 
return 0;
case WM_COMMAND:
//IF EXIT BUTTON CLICKED THEN EXIT APPLICATION
if (LOWORD(wParam) == WindowButtons[0].MW_btC_ID)	
   {
    DestroyWindow(hwnd);	//End application
   }
//CREATE CHILD WINDOW #2 WHEN BUTTON #2 PRESSED
else if (LOWORD(wParam) == WindowButtons[1].MW_btC_ID)		
            hdCWdws[1] = CreateWindow(					          
szCW2_ClassName,szCW2_Name, 
              WS_CHILD | WS_CAPTION | WS_SYSMENU,
                          10, 10, 700, 450,hwnd,(HMENU)CW2_ID,
                          (HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
        //SHOW CHILD WINDOW #1
        ShowWindow(hdCWdws[1],SW_SHOW);	
return 0;
case WM_DESTROY:
//CLEAR ALL OBJECTS
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
==================================================
===========================================WndPro_CW2.h
struct hdCW2_WindowButtonsTAG
{
int     iCTL_idx;
TCHAR	*szMW_btC_Name;
int    MW_btC_RectLeft;		
int   MW_btC_RectTop;
int   MW_btC_RectRight;
int   MW_btC_RectBottom;
int    MW_btC_ID;
};
===================================================
========================================WndProc_CW2.cpp
#include <windows.h>		
#include "WndProc_CW2.h"				
LRESULT CALLBACK WndProc_CW2(HWND hwnd, UINT message, WPARAM wParam, LPARAM 
lParam)
{
//MAIN WINDOW CONTROL PROPERTIES
hdCW2_WindowButtonsTAG WindowButtonsCW2[] =
{
   1,TEXT("< EXIT >"),580,350,80,40,1,
};
static	HWND	hdCW2_WindowButtons[1];	
int            i;
HDC	hdc;
switch(message)
{
case WM_SIZE:
SetFocus(hwnd);
return 0;
case WM_CREATE:
   hdc = GetDC(hwnd);
   //MAIN WINDOW BUTTON CONTROLS
    for(i=0;i<1;i++)
     {
    hdCW2_WindowButtons[i] = CreateWindow(				TEXT 
("button"),WindowButtonsCW2[i].szMW_btC_Name,
    WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON ,
    WindowButtonsCW2[i].MW_btC_RectLeft,
    WindowButtonsCW2[i].MW_btC_RectTop,
    WindowButtonsCW2[i].MW_btC_RectRight,
    WindowButtonsCW2[i].MW_btC_RectBottom,
    hwnd,(HMENU)WindowButtonsCW2[i].MW_btC_ID,
    (HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
    }
ReleaseDC(hwnd,hdc); 
return 0;
case WM_COMMAND:
//IF EXIT BUTTON CLICKED THEN EXIT APPLICATION
if (LOWORD(wParam) == WindowButtonsCW2[0].MW_btC_ID)	
{
    DestroyWindow(hwnd);	//End application
}
return 0;
case WM_CLOSE:		//Handler to do code on close
break;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
====================================================
Agian, excuse the lenghty post.....
So, basically, I always get the button to pop up from the bottom window on 
to the top window when clicked on space X!
I am as we speak, trying to troubleshoot this, I surely appreciate any input 
from the news groups!
Thankyou all!
-- 
Best regards
Robert