A
August1
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(HWND,UINT,WPARAM,LPARAM);
HWND hWnd;
HWND hwndEdit;
HWND hwndButton;
HWND hwndClearButton;
char szMessage[50] = "";
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wc;
wc.lpszClassName = "Style1";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
wc.lpszMenuName = "";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass(&wc);
hWnd = CreateWindow("Style1","Border Demonstration",
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
185,265,NULL,NULL,hInstance,NULL);
hwndEdit = CreateWindow("EDIT",NULL,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
10,10,155,20,hWnd,NULL,hInstance,NULL);
hwndButton = CreateWindow("BUTTON","Message",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10,40,35,35,hWnd,NULL,hInstance,NULL);
hwndClearButton = CreateWindow("BUTTON","Clear",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
50,40,35,35,hWnd,NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}//end WinMain()
long WINAPI MainWndProc(HWND 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(szMessage,"This program is an overlapped style Window.");
SetWindowText(hwndEdit,szMessage);
}
else if(hwndCtl == hwndClearButton)
{
strcpy(szMessage,"");
SetWindowText(hwndEdit,szMessage);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,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(HWND,UINT,WPARAM,LPARAM);
HWND hWnd;
HWND hwndEdit;
HWND hwndButton;
HWND hwndClearButton;
char szMessage[50] = "";
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wc;
wc.lpszClassName = "Style1";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
wc.lpszMenuName = "";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass(&wc);
hWnd = CreateWindow("Style1","Border Demonstration",
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
185,265,NULL,NULL,hInstance,NULL);
hwndEdit = CreateWindow("EDIT",NULL,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
10,10,155,20,hWnd,NULL,hInstance,NULL);
hwndButton = CreateWindow("BUTTON","Message",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10,40,35,35,hWnd,NULL,hInstance,NULL);
hwndClearButton = CreateWindow("BUTTON","Clear",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
50,40,35,35,hWnd,NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}//end WinMain()
long WINAPI MainWndProc(HWND 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(szMessage,"This program is an overlapped style Window.");
SetWindowText(hwndEdit,szMessage);
}
else if(hwndCtl == hwndClearButton)
{
strcpy(szMessage,"");
SetWindowText(hwndEdit,szMessage);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,msg,wParam,lParam);
}
return 0;
}//end MainWndProc()