#include<windows.h>
#include "resource.h"
#define ID_ABC 21
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK ChildProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS w;
if(!hPrevInstance)
{
w.cbClsExtra=0;
w.cbWndExtra=0;
w.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
w.hIcon=LoadIcon(NULL,IDC_ARROW);
w.hCursor=LoadCursor(NULL,IDI_APPLICATION);
w.hInstance=hInstance;
w.lpfnWndProc=WndProc;
w.lpszClassName=TEXT("MYCLASS");
w.lpszMenuName=MAKEINTRESOURCE(IDR_MENU1);
w.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&w))
{
return 0;
}
}
w.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
w.lpfnWndProc=ChildProc;
w.lpszClassName=TEXT("ChildClass");
w.lpszMenuName=NULL;
if(!RegisterClass(&w))
{
return 0;
}
hwnd=CreateWindow(TEXT("MyClass"),TEXT("WINDOW"),WS_OVERLAPPEDWINDOW,10,20,500,500,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message, WPARAM wParam,LPARAM lParam)
{
static BOOL hcreate=TRUE;
static HWND hchild;
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch(message)
{
case WM_CREATE:
return 0;
case WM_COMMAND:
switch(wParam)
{
case ID_CREATE:
if(hcreate==TRUE)
{
hcreate=FALSE;
hchild=CreateWindow(TEXT("ChildClass"),TEXT("CHILD"),WS_CHILD|WS_BORDER|WS_THICKFRAME|WS_SIZEBOX|WS_VISIBLE|WS_CAPTION,20,50,100,100,hwnd,NULL,(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
}
break;
case ID_SEND:
SendMessage(hchild,WM_USER,0,0L);
break;
}
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
TextOut(hdc,10,20,TEXT("Hello Sir Jiiiiiiii"),2);
EndPaint(hwnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
LRESULT CALLBACK ChildProc(HWND h,UINT m,WPARAM w,LPARAM l)
{
static BOOL p=FALSE;
//static HANDLE hpr;
//static HWND hpush;
//HINSTANCE his;
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch(m)
{
if(!p)
{
p=TRUE;
case WM_CREATE:
//hpr=GetParent(h);
CreateWindow(TEXT("BUTTON"),TEXT("PUSH IT"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|WS_BORDER,10,50,70,20,h,(HMENU) ID_ABC,(HINSTANCE)GetWindowLong(h,GWL_HINSTANCE),NULL);
}
break;
case WM_USER:
SetWindowText(h,TEXT("THIS IS A CHILD WINDOW DUDE"));
break;
case WM_COMMAND:
switch(w)
{
case ID_ABC:
MessageBox(h,TEXT("i m tired "),TEXT("WINDOW"),MB_OK);
break;
}
break;
case WM_PAINT:
hdc=BeginPaint(h,&ps);
GetClientRect(h,&rect);
TextOut(hdc,20,30,TEXT("Hello Sir Jiiiiiiii u re in child window now"),29);
EndPaint(h,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(h,m,w,l);
}
Gurpreet Singh
No comments:
Post a Comment