/ 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 /
/*TheWindowstructure*/wincl.hInstance=hThisInstance;wincl.lpszClassName=szClassName;wincl.lpfnWndProc=WindowProcedure;/*Thisfunctioniscalledbywindows*/wincl.style=CS_DBLCLKS;/*Catchdouble-clicks*/wincl.cbSize=sizeof(WNDCLASSEX);/*Usedefaulticonandmouse-pointer*/wincl.hIcon=LoadIcon(NULL,IDI_APPLICATION);wincl.hIconSm=LoadIcon(NULL,IDI_APPLICATION);wincl.hCursor=LoadCursor(NULL,IDC_ARROW);wincl.lpszMenuName=NULL;/*Nomenu*/wincl.cbClsExtra=0;/*Noextrabytesafterthewindowclass*/wincl.cbWndExtra=0;/*structureorthewindowinstance*//*UseWindows's default color as the background of the window */wincl.hbrBackground=(HBRUSH)COLOR_BACKGROUND;/*Registerthewindowclass,andifitfailsquittheprogram*/if(!RegisterClassEx(&wincl))return0;/*Theclassisregistered,let's create the program*/hwnd=CreateWindowEx(0,/*Extendedpossibilitesforvariation*/szClassName,/*Classname*/"WindowsApp",/*TitleText*/WS_OVERLAPPEDWINDOW,/*defaultwindow*/CW_USEDEFAULT,/*Windowsdecidestheposition*/CW_USEDEFAULT,/*wherethewindowendsuponthescreen*/544,/*Theprogramswidth*/375,/*andheightinpixels*/HWND_DESKTOP,/*Thewindowisachild-windowtodesktop*/NULL,/*Nomenu*/hThisInstance,/*ProgramInstancehandler*/NULL/*NoWindowCreationdata*/);/*Makethewindowvisibleonthescreen*/ShowWindow(hwnd,nFunsterStil);
caseWM_COMMAND:if((HWND)lParam==hwndButton3&&HIWORD(wParam)==BN_CLICKED){Horses(aChildWindow);return0;}break;//caseWM_ERASEBKGND://break;caseWM_DESTROY:PostQuitMessage(0);/* send a WM_QUIT to the message queue */break;default:/* for messages that we don't deal with */returnDefWindowProc(hwnd,message,wParam,lParam);}return0;
}
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.
/ 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 /
/*TheWindowstructure*/wincl.hInstance=hThisInstance;wincl.lpszClassName=szClassName;wincl.lpfnWndProc=WindowProcedure;/*Thisfunctioniscalledbywindows*/wincl.style=CS_DBLCLKS;/*Catchdouble-clicks*/wincl.cbSize=sizeof(WNDCLASSEX);/*Usedefaulticonandmouse-pointer*/wincl.hIcon=LoadIcon(NULL,IDI_APPLICATION);wincl.hIconSm=LoadIcon(NULL,IDI_APPLICATION);wincl.hCursor=LoadCursor(NULL,IDC_ARROW);wincl.lpszMenuName=NULL;/*Nomenu*/wincl.cbClsExtra=0;/*Noextrabytesafterthewindowclass*/wincl.cbWndExtra=0;/*structureorthewindowinstance*//*UseWindows's default color as the background of the window */wincl.hbrBackground=(HBRUSH)COLOR_BACKGROUND;/*Registerthewindowclass,andifitfailsquittheprogram*/if(!RegisterClassEx(&wincl))return0;/*Theclassisregistered,let's create the program*/hwnd=CreateWindowEx(0,/*Extendedpossibilitesforvariation*/szClassName,/*Classname*/"WindowsApp",/*TitleText*/WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,/*defaultwindow*/CW_USEDEFAULT,/*Windowsdecidestheposition*/CW_USEDEFAULT,/*wherethewindowendsuponthescreen*/544,/*Theprogramswidth*/375,/*andheightinpixels*/HWND_DESKTOP,/*Thewindowisachild-windowtodesktop*/NULL,/*Nomenu*/hThisInstance,/*ProgramInstancehandler*/NULL/*NoWindowCreationdata*/);/*Makethewindowvisibleonthescreen*/ShowWindow(hwnd,nFunsterStil);
break;caseWM_COMMAND:if((HWND)lParam==hwndButton3&&HIWORD(wParam)==BN_CLICKED){Horses(aChildWindow);return0;}break;caseWM_PAINT:HBRUSHhBrush;HDChdc;PAINTSTRUCTps;RECTrc;hdc=BeginPaint(aChildWindow,&ps);GetClientRect(aChildWindow,&rc);hBrush=CreateSolidBrush(RGB(255,255,255));FillRect(hdc,&rc,hBrush);EndPaint(aChildWindow,&ps);DeleteObject(hBrush);UpdateWindow(hwndButton3//handletowindow);break;caseWM_DESTROY:PostQuitMessage(0);/* send a WM_QUIT to the message queue */break;default:/* for messages that we don't deal with */returnDefWindowProc(hwnd,message,wParam,lParam);}return0;
}
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 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 ;