🔒 Locked
help with first window program
Advertisement
Original Post
hello. I need help with my first windows
program. I dont know what''s wrong
with the codes cause the compiler
said "unexpected end of file while searching for precompiled
header files. I really dont know what went wrong as I
double-checked it.
Please, anyone pls help me find
out the problem. Here''s the source:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <iostream.h>
#include <stdio.h>
#include <math.h>
#define WINDOW_CLASS_NAME "WINCLASS1"
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
PAINSTRUCT ps;
HDC hdc;
switch(msg)
{
case WM_CREATE:
{
return (0);
} break;
case WM_PAINT:
{
hdc= BeginPaint(hwnd,&ps);
EndPaint(hwnd, &ps);
return (0);
} break;
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
} break;
default:break;
}
return (DefWindowProc(hwnd, msg, wparam, lparam));
}
////WINMAIN////////
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
WNDCLASSEX winclass;//hold winclass
HWND hwnd;
MSG msg;
winclass.cbSize= sizeof(WNDCLASSEX);
winclass.nostyle= CS_DBLCLKS | 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);
if (!RegisterClassEx(&winclass))
return (0);
if (!(hwnd=CreateWindowEx(NULL, WINDOW_CLASS_NAME, "Gib Records", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0, 400,400, NULL, NULL, hinstance, NULL)))
return(0);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}//End of source file
Thank you, and sorry if this bothered you.
You can reply to my email:
jokerarnold@loveletter.org
Thanks.
Hi,
First you don''t need to declare so much header files (atleast in this case). Just
#include <windows.h>
will do the trick for you.
I am not sure about your problem, but there is something to do with the return functions. (That''s what end of file indicates) I think.
Try ...
return DefWindowProc(hwnd, msg, wparam, lparam);
instead of
return (DefWindowProc(hwnd, msg, wparam, lparam));
and
return msg.wParam
instead of
return(msg.wParam);
Its PAINTSTRUCT not PAINSTRUCT.
and
winclass.hbrBackground= (HBRUSH)GetStockObject(BLACK_BRUSH);
not
winclass.hbrBackground= GetStockObject(BLACK_BRUSH);
and its
winclass.nostyle= CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
not
winclass.nonostyle= CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
OK! Now, try these and it shall work.
Now it works on my compiler which is Microsoft Visual C++ 6
I can survive anything ... even NUKES!!!
The Lion King
First you don''t need to declare so much header files (atleast in this case). Just
#include <windows.h>
will do the trick for you.
I am not sure about your problem, but there is something to do with the return functions. (That''s what end of file indicates) I think.
Try ...
return DefWindowProc(hwnd, msg, wparam, lparam);
instead of
return (DefWindowProc(hwnd, msg, wparam, lparam));
and
return msg.wParam
instead of
return(msg.wParam);
Its PAINTSTRUCT not PAINSTRUCT.
and
winclass.hbrBackground= (HBRUSH)GetStockObject(BLACK_BRUSH);
not
winclass.hbrBackground= GetStockObject(BLACK_BRUSH);
and its
winclass.nostyle= CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
not
winclass.nonostyle= CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
OK! Now, try these and it shall work.
Now it works on my compiler which is Microsoft Visual C++ 6
I can survive anything ... even NUKES!!!
Thank you very much!! But...it still said
"fatal error C1010: unexpected end of file while looking for precompiled header directive."
I''d followed your instruction but...help?
Here''s the modified codes:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <iostream.h>
#include <stdio.h>
#include <math.h>
#define WINDOW_CLASS_NAME "WINCLASS1"
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(msg)
{
case WM_CREATE:
{
return (0);
} break;
case WM_PAINT:
{
hdc= BeginPaint(hwnd,&ps);
EndPaint(hwnd, &ps);
return (0);
} break;
case WM_DESTROY:
{
PostQuitMessage(0);
return (0);
} break;
default:break;
}
return DefWindowProc(hwnd, msg, wparam, lparam);
}
////WINMAIN////////
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
WNDCLASSEX winclass;//hold winclass
HWND hwnd;
MSG msg;
winclass.cbSize= sizeof(WNDCLASSEX);
winclass.nostyle= CS_DBLCLKS | 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(BLACK_BRUSH);
winclass.lpszMenuName= NULL;
winclass.lpszClassName= WINDOW_CLASS_NAME;
winclass.hIconSm= LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&winclass))
return (0);
if (!(hwnd=CreateWindowEx(NULL, WINDOW_CLASS_NAME, "Gib Records", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0, 400,400, NULL, NULL, hinstance, NULL)))
return (0);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Thank you. Where you from ?(just curious)
"fatal error C1010: unexpected end of file while looking for precompiled header directive."
I''d followed your instruction but...help?
Here''s the modified codes:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <iostream.h>
#include <stdio.h>
#include <math.h>
#define WINDOW_CLASS_NAME "WINCLASS1"
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(msg)
{
case WM_CREATE:
{
return (0);
} break;
case WM_PAINT:
{
hdc= BeginPaint(hwnd,&ps);
EndPaint(hwnd, &ps);
return (0);
} break;
case WM_DESTROY:
{
PostQuitMessage(0);
return (0);
} break;
default:break;
}
return DefWindowProc(hwnd, msg, wparam, lparam);
}
////WINMAIN////////
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
WNDCLASSEX winclass;//hold winclass
HWND hwnd;
MSG msg;
winclass.cbSize= sizeof(WNDCLASSEX);
winclass.nostyle= CS_DBLCLKS | 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(BLACK_BRUSH);
winclass.lpszMenuName= NULL;
winclass.lpszClassName= WINDOW_CLASS_NAME;
winclass.hIconSm= LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&winclass))
return (0);
if (!(hwnd=CreateWindowEx(NULL, WINDOW_CLASS_NAME, "Gib Records", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0, 400,400, NULL, NULL, hinstance, NULL)))
return (0);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Thank you. Where you from ?(just curious)
I pasted the modified code and the only part the compiler complained about was the ".nostyle" bit. I changed it to ".style" and it compiled fine.
Try starting a new win32 app and pasting in the code from your post here, then make that change. The error you''re getting might be a result of some other problem.
Try starting a new win32 app and pasting in the code from your post here, then make that change. The error you''re getting might be a result of some other problem.
if that only how a window.. i think it''s to much code.
[edited by - Metal Typhoon on May 24, 2002 2:05:07 PM]
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,LPARAM lparam,WPARAM wparam)
{
switch(msg)
{
case WS_CLOSE:
DestroyWindow(hwnd);
break;
case WS_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,msg,lparam,wparam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
WINCLASS wnd;
HWND hwnd;
MSG msg;
wnd.style = 0;
wnd.lpfnWndProc = WndProc;
wnd.cbClsExtra = 0;
wnd.cbWndExtra = 0;
wnd.hInstance = hInstance;
wnd.hIcon = LoadIcon(NULL,0);
wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd.hbrBackground = (HBRUSH)GetStockObject(COLOR_BLACK);
wnd.lpszMenuName = NULL;
wnd.lpszClassName = "WHATEVER";
if(!RegisterWindow(&wnd))
{
MessageBox(NULL,"Could not REGISTER CLASS","ERROR",MB_OK);
return 0;
}
hwnd = CreateWindowEx(
NULL,
"WHATEVER",
"My first window",
WS_OVERLAPPEDWINDOW,
100,100,300,300,
NULL,
NULL,
hInstance,
NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return Msg.wParam;
}
[edited by - Metal Typhoon on May 24, 2002 2:05:07 PM]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement