Let me see if I can get this explained clearly...
I have had VB6 for a while, and recently gotten VC++6. I installed it and everything went just fine... or so it seemed.
I have written a program and tried to compile it...
//header files to include
#include <windows.h>
#include <stdlib.h>
#include <time.h>
//App title
#define APPTITLE "Hello World"
//function prototypes
BOOL InitInstance(HINSTANCE,int);
ATOM MyRegisterClass(HINSTANCE);
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);
//The window even callback function
LRESULT CALLBACK WinProcHWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
char *szHello = "Hello World";
RECT rt;
int x, y, n;
COLORREF c;
switch (message)
{
case WM_PAINT:
//get the diminsions of the window
GetCLientRect(hWnd, &rt);
//Start drawing on the device context
hdc=BeginPoint(hWnd, &ps);
//draw some text
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
//draw 1000 random pixels
for (n=0; n<3000; n++)
{
x=rand() % (rt.right - rt.left);
y=rand() % (rt.botton - rt.top);
c=RGB(rand()%256, rand()%256, rand()%256);
SetPixel(hdc, x, y, c);
}
//stop drawing
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
//helper function to set up the window properties
ATOM MyRegisterClass(HINSTANCE hInstance)
{
//create the window class structure
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
//fill the structure with info
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPTITLE;
wc.hIcon = NULL;
//set the window with class info
return RegisterClassEx(&wc0);
}
//Helper function to create the window and refresg it
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
//Create a new window
hWnd = CreateWindow(
APPTITLE, //Window Class
APPTITLE, //Title Bar
WS_OVERLAPPEDWINDOW, //Window Style
CW_USEDEFAULT, // x Position of the window
CW_USEDEFAULT, // y Position of the window
500, //Width
400, //Height
NULL, //Parrent Window
NULL, //Menue
hInstance, //Application instance
NULL); //Window Parameters
//was there an error in creating the window?
if (!hWnd)
return FALSE;
//Display the window
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//Entry point for a windows program
int WINAPI WinMain(HUNSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
//Declare variables
MSG msg;
//Register the class
MyRegisterClass(hInstance);
//Initialize the application
if (!InitInstance (hInstance, nCmdShow))
return FALSE;
//Set the random number seed
srand(time(NULL));
//Main message loop
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
The program is out of a tutorial book I have....
When I compile it I get this...
--------------------Configuration: Main - Win32 Debug--------------------
Compiling...
Main.cpp
e:\program files\vb6\msdev98\myprojects\windowtest\main.cpp(16) : error C2146: syntax error : missing ';' before identifier 'hWnd'
e:\program files\vb6\msdev98\myprojects\windowtest\main.cpp(16) : warning C4229: anachronism used : modifiers on data are ignored
e:\program files\vb6\msdev98\myprojects\windowtest\main.cpp(16) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Main.obj - 2 error(s), 1 warning(s)
Further digging has led me to believe that the program is not finding the include files. the program installed to /program files/vc98. but it is saving the projects in /program files/vb6/dev98/projects. the header files are located under the vc98 directory, and they are all there. I have gone under properties and made sure the directories tab points at the right folders.
I am not sure how sacred the directories are and so i am not sure if I can or should simply move my projects folder. I am also not sure if it's a code issue or not, though I doubt it is because I get the same error when i load the source code from from the cd that came with the book,
i would be greatfull for any help.
Thanks.
Bob