/ Make the class name into a global variable /
char szClassName[ ] = "WindowsApp";
HWND hwndButton3; //Window handle to button
void Horses(HWND);//Horse text function
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; / This is the handle for our window /
MSG messages; / Here messages to the application are saved /
WNDCLASSEX wincl; / Data structure for the windowclass /
/* The Window structure */
wincl.hInstance=hThisInstance;
wincl.lpszClassName=szClassName;
wincl.lpfnWndProc=WindowProcedure;/* This function is called by windows */
wincl.style=CS_DBLCLKS;/* Catch double-clicks */
wincl.cbSize=sizeof(WNDCLASSEX);/* Use default icon and mouse-pointer */
wincl.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wincl.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
wincl.hCursor=LoadCursor(NULL,IDC_ARROW);
wincl.lpszMenuName=NULL;/* No menu */
wincl.cbClsExtra=0;/* No extra bytes after the window class */
wincl.cbWndExtra=0;/* structure or the window instance *//* Use Windows's default color as the background of the window */
wincl.hbrBackground=(HBRUSH)COLOR_BACKGROUND;/* Register the window class, and if it fails quit the program */if(!RegisterClassEx(&wincl))return0;/* The class is registered, let's create the program*/
hwnd=CreateWindowEx(0,/* Extended possibilites for variation */szClassName,/* Classname */"WindowsApp",/* Title Text */WS_OVERLAPPEDWINDOW,/* default window */CW_USEDEFAULT,/* Windows decides the position */CW_USEDEFAULT,/* where the window ends up on the screen */544,/* The programs width */375,/* and height in pixels */HWND_DESKTOP,/* The window is a child-window to desktop */NULL,/* No menu */hThisInstance,/* Program Instance handler */NULL/* No Window Creation data */);/* Make the window visible on the screen */
ShowWindow(hwnd,nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */while(GetMessage(&messages,NULL,0,0)){/* Translate virtual-key messages into character messages */TranslateMessage(&messages);/* Send message to WindowProcedure */DispatchMessage(&messages);}/* The program return-value is 0 - The value that PostQuitMessage() gave */returnmessages.wParam;
}
/ This function is called by the Windows function DispatchMessage() /
HWND aChildWindow;
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) / handle the messages /
{
case WM_CREATE:
/////////////////////Create a child window//////////////////////
int test;
if(test == 0)
{
aChildWindow = CreateWindowEx (
WS_EX_CLIENTEDGE, /* Extended possibilites for variation */
szClassName, /* Classname */
NULL, /* Title Text */
WS_VISIBLE | WS_CHILD, /* default window */
10, /* Windows decides the position */
100, /* where the window ends up on the screen */
200, /* The window width */
200, /* and height in pixels */
hwnd, /* The window is a child-window to main window */
NULL, /* No menu */
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), /* Program Instance handler */
NULL /* No Window Creation data */
);
test = 1;
}
break;
case WM_COMMAND:
if ((HWND)lParam == hwndButton3 && HIWORD(wParam) == BN_CLICKED)
{
Horses(aChildWindow);
return 0;
}
break;
//case WM_ERASEBKGND:
//break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
RECT ClientArea;
int x, y;
int count;
void Horses(HWND htowind)
{
HDC Hndltodc;
char str[] = "horses";
if( count==0)
{
x = 10;
y = 10;
}
Hndltodc = GetDC(htowind);
TextOut(
Hndltodc, // handle to DC
x, // x-coordinate of starting position
y, // y-coordinate of starting position
str, // character string
6 // number of characters
);
x=x+50;
//y=y+50;
count = count + 1;
GetClientRect(
htowind,
&ClientArea
);
if(x > (int)ClientArea.right - 50)
{
y=y+20;
x=10;
}
ReleaseDC(
htowind, // handle to window
Hndltodc // handle to DC
);
return;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have it! I had to move a few things to get it to work.... Having my child window under WM_CREATE was producing some very strange results when I tried to paint to it.
/ Make the class name into a global variable /
char szClassName[ ] = "WindowsApp";
HWND aChildWindow;
HWND hwndButton3; //Window handle to button
void Horses(HWND);//Horse text function
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; / This is the handle for our window /
MSG messages; / Here messages to the application are saved /
WNDCLASSEX wincl; / Data structure for the windowclass /
/* The Window structure */
wincl.hInstance=hThisInstance;
wincl.lpszClassName=szClassName;
wincl.lpfnWndProc=WindowProcedure;/* This function is called by windows */
wincl.style=CS_DBLCLKS;/* Catch double-clicks */
wincl.cbSize=sizeof(WNDCLASSEX);/* Use default icon and mouse-pointer */
wincl.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wincl.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
wincl.hCursor=LoadCursor(NULL,IDC_ARROW);
wincl.lpszMenuName=NULL;/* No menu */
wincl.cbClsExtra=0;/* No extra bytes after the window class */
wincl.cbWndExtra=0;/* structure or the window instance *//* Use Windows's default color as the background of the window */
wincl.hbrBackground=(HBRUSH)COLOR_BACKGROUND;/* Register the window class, and if it fails quit the program */if(!RegisterClassEx(&wincl))return0;/* The class is registered, let's create the program*/
hwnd=CreateWindowEx(0,/* Extended possibilites for variation */szClassName,/* Classname */"WindowsApp",/* Title Text */WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,/* default window */CW_USEDEFAULT,/* Windows decides the position */CW_USEDEFAULT,/* where the window ends up on the screen */544,/* The programs width */375,/* and height in pixels */HWND_DESKTOP,/* The window is a child-window to desktop */NULL,/* No menu */hThisInstance,/* Program Instance handler */NULL/* No Window Creation data */);/* Make the window visible on the screen */
ShowWindow(hwnd,nFunsterStil);
//////////Having my child window under WM_CREATE caused a lot of /////////problems
aChildWindow = CreateWindowEx (
WS_EX_CLIENTEDGE, /* Extended possibilites for variation */
szClassName, /* Classname */
NULL, /* Title Text */
WS_VISIBLE | WS_CHILD, /* default window */
10, /* Place window on */
100, /* parent*/
200, /* The window width */
200, /* and height in pixels */
hwnd, /* The window is a child-window to main window */
NULL, /* No menu */
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Run the message loop. It will run until GetMessage() returns 0 */while(GetMessage(&messages,NULL,0,0)){/* Translate virtual-key messages into character messages */TranslateMessage(&messages);/* Send message to WindowProcedure */DispatchMessage(&messages);}/* The program return-value is 0 - The value that PostQuitMessage() gave */returnmessages.wParam;
}
/ This function is called by the Windows function DispatchMessage() /
break;
case WM_COMMAND:
if ((HWND)lParam == hwndButton3 && HIWORD(wParam) == BN_CLICKED)
{
Horses(aChildWindow);
return 0;
}
break;
case WM_PAINT:
HBRUSH hBrush ;
HDC hdc ;
PAINTSTRUCT ps ;
RECT rc ;
hdc = BeginPaint (aChildWindow, &ps) ;
GetClientRect (aChildWindow, &rc) ;
hBrush = CreateSolidBrush (RGB(255,255,255));
FillRect (hdc, &rc, hBrush) ;
EndPaint (aChildWindow, &ps) ;
DeleteObject (hBrush) ;
UpdateWindow(
hwndButton3 // handle to window
);
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
RECT ClientArea;
int x, y;
int count;
void Horses(HWND htowind)
{
HDC Hndltodc;
char str[] = "horses";
if( count==0)
{
x = 10;
y = 10;
}
Hndltodc = GetDC(htowind);
TextOut(
Hndltodc, // handle to DC
x, // x-coordinate of starting position
y, // y-coordinate of starting position
str, // character string
6 // number of characters
);
x=x+50;
//y=y+50;
count = count + 1;
GetClientRect(
htowind,
&ClientArea
);
if(x > (int)ClientArea.right - 50)
{
y=y+20;
x=10;
}
ReleaseDC(
htowind, // handle to window
Hndltodc // handle to DC
);
return;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I want to paint the smaller child window in which the text appears. I am trying to make it white. I am learning the API and trying understand how it works.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to paint the background ofa child window but haven't been able to manage it. Does anybody know how this is accomplished?
include <windows.h>
/ Declare Windows procedure /
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/ Make the class name into a global variable /
char szClassName[ ] = "WindowsApp";
HWND hwndButton3; //Window handle to button
void Horses(HWND);//Horse text function
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; / This is the handle for our window /
MSG messages; / Here messages to the application are saved /
WNDCLASSEX wincl; / Data structure for the windowclass /
///////////////Create a button//////////////////////////
hwndButton3 = CreateWindow(
"BUTTON", // Predefined class; Unicode assumed.
"Test", // Button text.
WS_VISIBLE | WS_CHILD, // Styles.
10, // x position.
10, // y position.
95, // Button width.
85, // Button height.
hwnd, // Parent window.
NULL, // No menu.
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL); // Pointer not needed.
////////////////////////////////////////////////////////
}
/ This function is called by the Windows function DispatchMessage() /
HWND aChildWindow;
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) / handle the messages /
{
case WM_CREATE:
/////////////////////Create a child window//////////////////////
int test;
if(test == 0)
{
///////////////////////////////////////////////////////////////////
}
RECT ClientArea;
int x, y;
int count;
void Horses(HWND htowind)
{
HDC Hndltodc;
char str[] = "horses";
if( count==0)
{
x = 10;
y = 10;
}
Hndltodc = GetDC(htowind);
}
I have it! I had to move a few things to get it to work.... Having my child window under WM_CREATE was producing some very strange results when I tried to paint to it.
//////////////////////////////////////////////////////////////////////
include <windows.h>
/ Declare Windows procedure /
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/ Make the class name into a global variable /
char szClassName[ ] = "WindowsApp";
HWND aChildWindow;
HWND hwndButton3; //Window handle to button
void Horses(HWND);//Horse text function
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; / This is the handle for our window /
MSG messages; / Here messages to the application are saved /
WNDCLASSEX wincl; / Data structure for the windowclass /
///////////////Create a button//////////////////////////
hwndButton3 = CreateWindow(
"BUTTON", // Predefined class; Unicode assumed.
"Test", // Button text.
WS_VISIBLE | WS_CHILD, // Styles.
10, // x position.
10, // y position.
95, // Button width.
85, // Button height.
hwnd, // Parent window.
NULL, // No menu.
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL); // Pointer not needed.
////////////////////////////////////////////////////////
//////////Having my child window under WM_CREATE caused a lot of /////////problems
////////////////////////////////////////////////////////////////////////////////////////
}
/ This function is called by the Windows function DispatchMessage() /
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) / handle the messages /
{
case WM_CREATE:
}
RECT ClientArea;
int x, y;
int count;
void Horses(HWND htowind)
{
HDC Hndltodc;
char str[] = "horses";
if( count==0)
{
x = 10;
y = 10;
}
Hndltodc = GetDC(htowind);
}
Now I can sleep tonight. Cool...
////////////////////////////////////////////////////////////////////////
Whats wrong with it, except it doesn't compile? After a simple fix it compiles and works.
what exactly do you want to achieve.
see
http://i150.photobucket.com/albums/s106/toatingbucket/untitled.jpg
I want to paint the smaller child window in which the text appears. I am trying to make it white. I am learning the API and trying understand how it works.
BTW: It compiles just fine on my machine. I'm using Dev.
Where are you trying to paint it white? I don't see it.
use fillrect http://msdn.microsoft.com/en-us/library/ms533283(VS.85).aspx
checkout http://msdn.microsoft.com/en-us/library/ms533223(VS.85).aspx for brush info
Hmm... It gets even better. I've built a function that makes it even easier.
//////////////////////////////////////////////////////////
void PaintWindBckgnd(HWND hwnd, int r, int g, int b)
{
HBRUSH hBrush ;
HDC hdc ;
PAINTSTRUCT ps ;
RECT rc ;