I just want to create a basic Window!
Hi Folks!
I''ve got a problem. Is this code correct to create a basic window like it is said in the book "Tricks of Windows Game Programming Gurus":
#define
#include
#include
#include
//Defínes
#define WINDOW_CLASS_NAME "WINCLASS1"
//Functions
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
PAINSTRUCT ps;
HDC hdc;
//what is the maessage
switch(msg)
{
case WM_CREATE;
{
//do initialization stuff here
//return success
return(0);
} break;
case WM_PAINT:
{
//simply validate the window
hdc = BeginPaint(hwnd,&ps);
//you would do all your painting here
EndPaint(hwnd,&ps);
//return success
return(0);
}break;
case WM_DESTROY:
{
//kill the application, this sends a WM_QUIT message
PostQuitMessage(0);
//return success
return(0);
}break;
default:break;
} // end switch
//process any messages that we didn''t take care of
return (DefWindowProc(hwnd, msg, wparam, lparam));
} // end WinProc
//Winmain
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
WNDCLASSEX winclass;
HWND hwnd;
MSG msg;
//first fill in the window class structure
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLICKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
//register the window class
if (!RegisterClassEx(&winclass))
return(0);
//create the window
if (!(hwnd = CreateWindowEx(NULL, WINDOW_CLASS_NAME, "Grundfenster", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 400, 400,
NULL, NULL, hinstance, NULL)))
return(0);
//enter main event loop
while (GetMessage(&msg,NULL,0,0))
{
//translate any accelerator keys
TranslateMessage(&msg);
//send the message to the window proc
DispatchMessage(&msg);
} // end while
//return to Windows like this
return(msg.wParam);
}
If i want to run it, there is always fatal error C1010!
Please help me!
Thanks!!
Most of it looks ok, but what is:
#define
#include
#include
#include
#include
at the top? Did you tell it what to define and what files to include in your actual code? If this is your actual code, then this is what is causing your error!
#define
#include
#include
#include
#include
at the top? Did you tell it what to define and what files to include in your actual code? If this is your actual code, then this is what is causing your error!
September 06, 2000 04:30 PM
quote: Original post by carlinke
If i want to run it, there is always fatal error C1010!
Please help me!
Thanks!!
I had several compile errors when I tried to compile your code. PAINTSTRUCT spelled funny, a semicolon following a case (in a switch), and the brush type needed to be type-cast into an HBRUSH. Once I changed these, (and included windows.h), it ran perfectly.
September 06, 2000 04:37 PM
I modified the code a bit, and fixed those errors I had.. this works for me in Visual C++ 6.0 Professional.
#include#define WINDOW_CLASS_NAME "WINCLASS1"//FunctionsLRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);//Winmainint WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow){ WNDCLASSEX winclass; HWND hwnd; MSG msg; winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //register the window class if (!RegisterClassEx(&winclass)) return(0); //create the window if (!(hwnd = CreateWindowEx(NULL, WINDOW_CLASS_NAME, "Grundfenster", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 400, 400, NULL, NULL, hinstance, NULL))) return(0); //enter main event loop while(1) { if(GetMessage(&msg, NULL, 0, 0)) { //translate any accelerator keys TranslateMessage(&msg); //send the message to the window proc DispatchMessage(&msg); } else { break; } } // end while //return to Windows like this return(msg.wParam);} LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){ HDC hdc; PAINTSTRUCT ps; switch(msg) { case WM_PAINT: hdc = BeginPaint(hwnd, &ps); TextOut(hdc, 50, 50, "This is a test", 14); EndPaint(hwnd, &ps); break; default: break; } return DefWindowProc(hwnd, msg, wparam, lparam);}
Sorry, I forgot the one #define and the 4 #includes.
#define WIN32_LEAN_AND_MEAN
#include
#include
#include
#include
Thanks for your help ;-}
#define WIN32_LEAN_AND_MEAN
#include
#include
#include
#include
Thanks for your help ;-}
Why can''t i write the includes?
perhaps like this:
#include windows.h
#include windowsx.h
#include stdio.h
#include math.h
perhaps like this:
#include windows.h
#include windowsx.h
#include stdio.h
#include math.h
use [ source ]
and [ /source ]
like this:
see?
and [ /source ]
like this:
this is inside a source block
see?
The reason why you can''t use includes properly on many boards is because most of them use HTML and HTML treats anything between < and > as an HTML tag. Put it in a source block or a ''pre'' tag, ''code'' tag or you could leave a space between the < and the library like #include < iostream.h >.
As to your problem, I think you are using an incorrect compiler directive and specifying an include as ''/Yu'' which is "Use Precompiled Header". Have you checked that you have included ''StdAfx.h'', because I think it is a pre-compiled header.
Lucas
As to your problem, I think you are using an incorrect compiler directive and specifying an include as ''/Yu'' which is "Use Precompiled Header". Have you checked that you have included ''StdAfx.h'', because I think it is a pre-compiled header.
Lucas
-=[ Lucas ]=-
It still doesn''t work *gr*!
I also tried your code(Anonymous Poster) but that doesn''t work too.
Is it a folder if i use all this stuff in a Win 32 application?
I also tried your code(Anonymous Poster) but that doesn''t work too.
Is it a folder if i use all this stuff in a Win 32 application?
What someone mentioned about the conversion to HBRUSH is right, so in the line where you set the background color, it should look something like this:
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
also, I said earlier you can''t leave the include and define the way you had them. You said in one post what it was you were including so, Here is the way those first few lines should look:
#define WIN32_LEAN_AND_MEAN
#include
#include
#include
#include
This should work!
Also, if you are just making a window, then you don''t need to include stdio.h or math.h. It won''t hurt your program in any way by leaving these two lines in there, but right now I don''t think you need them so it would only slow down compile times.
Hope this helps!
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
also, I said earlier you can''t leave the include and define the way you had them. You said in one post what it was you were including so, Here is the way those first few lines should look:
#define WIN32_LEAN_AND_MEAN
#include
#include
#include
#include
This should work!
Also, if you are just making a window, then you don''t need to include stdio.h or math.h. It won''t hurt your program in any way by leaving these two lines in there, but right now I don''t think you need them so it would only slow down compile times.
Hope this helps!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement