Hi,
I'm beginning to approach Windows programming in C++. I've written
a short
application which is to do nothing more than demonstrate the Window
style being used. The child windows are not appearing within the
parent window. Could someone point out the cause?
Thank you in advance,
Anthony
#include <windows.h>
#include <string.h>
long WINAPI MainWndProc(HWN D,UINT,WPARAM,L PARAM);
HWND hWnd;
HWND hwndEdit;
HWND hwndButton;
HWND hwndClearButton ;
char szMessage[50] = "";
int WINAPI WinMain(HINSTAN CE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wc;
wc.lpszClassNam e = "Style1";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,I DI_APPLICATION) ;
wc.hCursor = LoadCursor(NULL ,IDC_ARROW);
wc.hbrBackgroun d = (HBRUSH)( COLOR_WINDOW+1 );
wc.lpszMenuName = "";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass(& wc);
hWnd = CreateWindow("S tyle1","Border Demonstration",
WS_OVERLAPPEDWI NDOW,CW_USEDEFA ULT,CW_USEDEFAU LT,
185,265,NULL,NU LL,hInstance,NU LL);
hwndEdit = CreateWindow("E DIT",NULL,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
10,10,155,20,hW nd,NULL,hInstan ce,NULL);
hwndButton = CreateWindow("B UTTON","Message ",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTO N,
10,40,35,35,hWn d,NULL,hInstanc e,NULL);
hwndClearButton = CreateWindow("B UTTON","Clear",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTO N,
50,40,35,35,hWn d,NULL,hInstanc e,NULL);
ShowWindow(hWnd ,nCmdShow);
MSG msg;
while(GetMessag e(&msg,NULL,0,0 ))
{
TranslateMessag e(&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}//end WinMain()
long WINAPI MainWndProc(HWN D hWnd,UINT msg,WPARAM wParam,LPARAM
lParam)
{
HWND hwndCtl = (HWND)lParam;
switch(msg)
{
case WM_COMMAND:
switch(wParam)
{
case BN_CLICKED:
if(hwndCtl == hwndButton)
{
strcpy(szMessag e,"This program is an overlapped style Window.");
SetWindowText(h wndEdit,szMessa ge);
}
else if(hwndCtl == hwndClearButton )
{
strcpy(szMessag e,"");
SetWindowText(h wndEdit,szMessa ge);
}
}
break;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
default:
return DefWindowProc(h Wnd,msg,wParam, lParam);
}
return 0;
}//end MainWndProc()
I'm beginning to approach Windows programming in C++. I've written
a short
application which is to do nothing more than demonstrate the Window
style being used. The child windows are not appearing within the
parent window. Could someone point out the cause?
Thank you in advance,
Anthony
#include <windows.h>
#include <string.h>
long WINAPI MainWndProc(HWN D,UINT,WPARAM,L PARAM);
HWND hWnd;
HWND hwndEdit;
HWND hwndButton;
HWND hwndClearButton ;
char szMessage[50] = "";
int WINAPI WinMain(HINSTAN CE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wc;
wc.lpszClassNam e = "Style1";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,I DI_APPLICATION) ;
wc.hCursor = LoadCursor(NULL ,IDC_ARROW);
wc.hbrBackgroun d = (HBRUSH)( COLOR_WINDOW+1 );
wc.lpszMenuName = "";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass(& wc);
hWnd = CreateWindow("S tyle1","Border Demonstration",
WS_OVERLAPPEDWI NDOW,CW_USEDEFA ULT,CW_USEDEFAU LT,
185,265,NULL,NU LL,hInstance,NU LL);
hwndEdit = CreateWindow("E DIT",NULL,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
10,10,155,20,hW nd,NULL,hInstan ce,NULL);
hwndButton = CreateWindow("B UTTON","Message ",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTO N,
10,40,35,35,hWn d,NULL,hInstanc e,NULL);
hwndClearButton = CreateWindow("B UTTON","Clear",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTO N,
50,40,35,35,hWn d,NULL,hInstanc e,NULL);
ShowWindow(hWnd ,nCmdShow);
MSG msg;
while(GetMessag e(&msg,NULL,0,0 ))
{
TranslateMessag e(&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}//end WinMain()
long WINAPI MainWndProc(HWN D hWnd,UINT msg,WPARAM wParam,LPARAM
lParam)
{
HWND hwndCtl = (HWND)lParam;
switch(msg)
{
case WM_COMMAND:
switch(wParam)
{
case BN_CLICKED:
if(hwndCtl == hwndButton)
{
strcpy(szMessag e,"This program is an overlapped style Window.");
SetWindowText(h wndEdit,szMessa ge);
}
else if(hwndCtl == hwndClearButton )
{
strcpy(szMessag e,"");
SetWindowText(h wndEdit,szMessa ge);
}
}
break;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
default:
return DefWindowProc(h Wnd,msg,wParam, lParam);
}
return 0;
}//end MainWndProc()
Comment