|
From: Robby on 10 Sep 2005 15:01 Hi, Trying the first windows program in Charles Petzold's book and getting many errors. Boy, this windows programming, not an easy world ! Here is the code in its simplist nature: #include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("HelloWin"); HWND hwnd; MSG msg; WNDCLASS wndclass; wndclass.style = CS_HREDRAW CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor (NULL,IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; if (!RegisterClass (&wndclass)) { MessageBox(NULL,TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow (szAppName, TEXT ("The Hello program"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow (hwnd, iCmdShow); UpdateWindow(hwnd); while (GetMessage (&msg, NULL,0,0)) { TranslateMessage (&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; switch(message) { case WM_CREATE: PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME SND_ASYNC); return 0; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); GetClientRect (hwnd,&rect); DrawText (hdc, TEXT ("Hello, Windows 98!"), -1,&rect, DT_SINGLELINE DT_CENTER DT_VCENTER); EndPaint (hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); } I don't know why I am getting all sorts of errors, can someone please take a look at this! Thanks -- Best regards Robert
From: Joe Butler on 10 Sep 2005 15:21 you need to post the first few error messages that are generated. "Robby" <Robby(a)discussions.microsoft.com> wrote in message news:22E6CA3E-748E-4D2C-B0F3-612BAD16F5C5(a)microsoft.com... > Hi, > > Trying the first windows program in Charles Petzold's book and getting many > errors. Boy, this windows programming, not an easy world ! > > Here is the code in its simplist nature: > > #include <windows.h> > > LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); > > int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, > PSTR szCmdLine, int iCmdShow) > { > static TCHAR szAppName[] = TEXT ("HelloWin"); > HWND hwnd; > MSG msg; > WNDCLASS wndclass; > > wndclass.style = CS_HREDRAW ?CS_VREDRAW; > wndclass.lpfnWndProc = WndProc; > wndclass.cbClsExtra = 0; > wndclass.cbWndExtra = 0; > wndclass.hInstance = hInstance; > wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); > wndclass.hCursor = LoadCursor (NULL,IDC_ARROW); > wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); > wndclass.lpszMenuName = NULL; > wndclass.lpszClassName = szAppName; > > if (!RegisterClass (&wndclass)) > { > MessageBox(NULL,TEXT ("This program requires Windows NT!"), > szAppName, MB_ICONERROR); > return 0; > } > > hwnd = CreateWindow (szAppName, > TEXT ("The Hello program"), > WS_OVERLAPPEDWINDOW, > CW_USEDEFAULT, > CW_USEDEFAULT, > CW_USEDEFAULT, > CW_USEDEFAULT, > NULL, > NULL, > hInstance, > NULL); > > ShowWindow (hwnd, iCmdShow); > UpdateWindow(hwnd); > > while (GetMessage (&msg, NULL,0,0)) > { > TranslateMessage (&msg); > DispatchMessage(&msg); > } > > return msg.wParam; > } > > LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM > lParam) > { > HDC hdc; > PAINTSTRUCT ps; > RECT rect; > > switch(message) > { > case WM_CREATE: > PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME ? SND_ASYNC); > return 0; > > case WM_PAINT: > hdc = BeginPaint(hwnd, &ps); > GetClientRect (hwnd,&rect); > DrawText (hdc, TEXT ("Hello, Windows 98!"), -1,&rect, > DT_SINGLELINE ? DT_CENTER ? DT_VCENTER); > EndPaint (hwnd, &ps); > return 0; > case WM_DESTROY: > PostQuitMessage (0); > return 0; > } > return DefWindowProc(hwnd, message, wParam, lParam); > } > > I don't know why I am getting all sorts of errors, can someone please take a > look at this! > > Thanks > > -- > Best regards > Robert
From: William DePalo [MVP VC++] on 10 Sep 2005 15:25 "Robby" <Robby(a)discussions.microsoft.com> wrote in message news:22E6CA3E-748E-4D2C-B0F3-612BAD16F5C5(a)microsoft.com... > I don't know why I am getting all sorts of errors, can someone please take > a > look at this! You should post again with the exact text of the error message you get as well as the offending lines. Someone here may cut and paste those lines into a project but that effort may mask environmental issues are your side. Just by the way, chances are that Petzold's example is in C. Most modern development environments default to C++. Given the C++ compiler's insistence on type saftey and the way Windows plays fast and loose, it's possible that his example is fine in C and problematic in C++. Regards, Will
From: Robby on 10 Sep 2005 15:34 OKAY here are the couple of first errors! c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp(64): error C2059: syntax error : ')' c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp(13): error C2065: 'CS_VREDRAW' : undeclared identifier c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp(70): error C2146: syntax error : missing ')' before identifier ' DT_CENTER' c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp(64): error C2146: syntax error : missing ')' before identifier ' SND_ASYNC' c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp(13): error C2146: syntax error : missing ';' before identifier 'CS_VREDRAW' c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp(70): error C3209: ' DT_CENTER' : Unicode identifiers are not yet supported c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp(52): warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data I'm discouraged! -- Best regards Robert "Joe Butler" wrote: > you need to post the first few error messages that are generated. > > > > "Robby" <Robby(a)discussions.microsoft.com> wrote in message > news:22E6CA3E-748E-4D2C-B0F3-612BAD16F5C5(a)microsoft.com... > > Hi, > > > > Trying the first windows program in Charles Petzold's book and getting > many > > errors. Boy, this windows programming, not an easy world ! > > > > Here is the code in its simplist nature: > > > > #include <windows.h> > > > > LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); > > > > int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, > > PSTR szCmdLine, int iCmdShow) > > { > > static TCHAR szAppName[] = TEXT ("HelloWin"); > > HWND hwnd; > > MSG msg; > > WNDCLASS wndclass; > > > > wndclass.style = CS_HREDRAW ?CS_VREDRAW; > > wndclass.lpfnWndProc = WndProc; > > wndclass.cbClsExtra = 0; > > wndclass.cbWndExtra = 0; > > wndclass.hInstance = hInstance; > > wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); > > wndclass.hCursor = LoadCursor (NULL,IDC_ARROW); > > wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); > > wndclass.lpszMenuName = NULL; > > wndclass.lpszClassName = szAppName; > > > > if (!RegisterClass (&wndclass)) > > { > > MessageBox(NULL,TEXT ("This program requires Windows NT!"), > > szAppName, MB_ICONERROR); > > return 0; > > } > > > > hwnd = CreateWindow (szAppName, > > TEXT ("The Hello program"), > > WS_OVERLAPPEDWINDOW, > > CW_USEDEFAULT, > > CW_USEDEFAULT, > > CW_USEDEFAULT, > > CW_USEDEFAULT, > > NULL, > > NULL, > > hInstance, > > NULL); > > > > ShowWindow (hwnd, iCmdShow); > > UpdateWindow(hwnd); > > > > while (GetMessage (&msg, NULL,0,0)) > > { > > TranslateMessage (&msg); > > DispatchMessage(&msg); > > } > > > > return msg.wParam; > > } > > > > LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM > > lParam) > > { > > HDC hdc; > > PAINTSTRUCT ps; > > RECT rect; > > > > switch(message) > > { > > case WM_CREATE: > > PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME ? SND_ASYNC); > > return 0; > > > > case WM_PAINT: > > hdc = BeginPaint(hwnd, &ps); > > GetClientRect (hwnd,&rect); > > DrawText (hdc, TEXT ("Hello, Windows 98!"), -1,&rect, > > DT_SINGLELINE ? DT_CENTER ? DT_VCENTER); > > EndPaint (hwnd, &ps); > > return 0; > > case WM_DESTROY: > > PostQuitMessage (0); > > return 0; > > } > > return DefWindowProc(hwnd, message, wParam, lParam); > > } > > > > I don't know why I am getting all sorts of errors, can someone please take > a > > look at this! > > > > Thanks > > > > -- > > Best regards > > Robert > > >
From: Joe Butler on 10 Sep 2005 15:50 "Robby" <Robby(a)discussions.microsoft.com> wrote in message news:99564CDB-037F-467F-83AB-5F70DA5008EC(a)microsoft.com... > OKAY here are the couple of first errors! > > c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp (64): error C2059: syntax error : ')' > > c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp (13): error C2065: 'CS_VREDRAW' : undeclared identifier There's a mistake on line 13. Correct that and this error will go away. Exact same problem with all the other errors you've given, except the end one. Unless this is some sort of character substitution that the newsreader has made. > > c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp (70): error C2146: syntax error : missing ')' before identifier ' DT_CENTER' > > c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp (64): error C2146: syntax error : missing ')' before identifier ' SND_ASYNC' > > c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp (13): error C2146: syntax error : missing ';' before identifier 'CS_VREDRAW' > > c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp (70): error C3209: ' DT_CENTER' : Unicode identifiers are not yet supported > > c:\DATASOURCE_EXTRA\Programming\VC++CodeTesting_WINDOWS\CPZ_P44\HELLOWIN.cpp (52): > warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of > data This is a warning. The code will still work. But to get rid of it, use this instead: return (LRESULT)msg.wParam; So, even though there were lots of errors, things were pretty much sorted just by looking at the first 1 or 2 in detail. > > I'm discouraged! > > -- > Best regards > Robert > > > "Joe Butler" wrote: > > > you need to post the first few error messages that are generated. > > > > > > > > "Robby" <Robby(a)discussions.microsoft.com> wrote in message > > news:22E6CA3E-748E-4D2C-B0F3-612BAD16F5C5(a)microsoft.com... > > > Hi, > > > > > > Trying the first windows program in Charles Petzold's book and getting > > many > > > errors. Boy, this windows programming, not an easy world ! > > > > > > Here is the code in its simplist nature: > > > > > > #include <windows.h> > > > > > > LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); > > > > > > int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, > > > PSTR szCmdLine, int iCmdShow) > > > { > > > static TCHAR szAppName[] = TEXT ("HelloWin"); > > > HWND hwnd; > > > MSG msg; > > > WNDCLASS wndclass; > > > > > > wndclass.style = CS_HREDRAW ?CS_VREDRAW; > > > wndclass.lpfnWndProc = WndProc; > > > wndclass.cbClsExtra = 0; > > > wndclass.cbWndExtra = 0; > > > wndclass.hInstance = hInstance; > > > wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); > > > wndclass.hCursor = LoadCursor (NULL,IDC_ARROW); > > > wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); > > > wndclass.lpszMenuName = NULL; > > > wndclass.lpszClassName = szAppName; > > > > > > if (!RegisterClass (&wndclass)) > > > { > > > MessageBox(NULL,TEXT ("This program requires Windows NT!"), > > > szAppName, MB_ICONERROR); > > > return 0; > > > } > > > > > > hwnd = CreateWindow (szAppName, > > > TEXT ("The Hello program"), > > > WS_OVERLAPPEDWINDOW, > > > CW_USEDEFAULT, > > > CW_USEDEFAULT, > > > CW_USEDEFAULT, > > > CW_USEDEFAULT, > > > NULL, > > > NULL, > > > hInstance, > > > NULL); > > > > > > ShowWindow (hwnd, iCmdShow); > > > UpdateWindow(hwnd); > > > > > > while (GetMessage (&msg, NULL,0,0)) > > > { > > > TranslateMessage (&msg); > > > DispatchMessage(&msg); > > > } > > > > > > return msg.wParam; > > > } > > > > > > LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM > > > lParam) > > > { > > > HDC hdc; > > > PAINTSTRUCT ps; > > > RECT rect; > > > > > > switch(message) > > > { > > > case WM_CREATE: > > > PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME ? SND_ASYNC); > > > return 0; > > > > > > case WM_PAINT: > > > hdc = BeginPaint(hwnd, &ps); > > > GetClientRect (hwnd,&rect); > > > DrawText (hdc, TEXT ("Hello, Windows 98!"), -1,&rect, > > > DT_SINGLELINE ? DT_CENTER ? DT_VCENTER); > > > EndPaint (hwnd, &ps); > > > return 0; > > > case WM_DESTROY: > > > PostQuitMessage (0); > > > return 0; > > > } > > > return DefWindowProc(hwnd, message, wParam, lParam); > > > } > > > > > > I don't know why I am getting all sorts of errors, can someone please take > > a > > > look at this! > > > > > > Thanks > > > > > > -- > > > Best regards > > > Robert > > > > > >
|
Next
|
Last
Pages: 1 2 Prev: Which one?(for experienced ones) Next: NT service and simulated Keystroke |