Archived

This topic is now archived and is closed to further replies.

TheNerd Tk421

error with putting a bmp inside a window

Recommended Posts

My program wont compile!! Help me plz... my source code: #include <windows.h> #include <stdlib.h> #define NULL //what do i put here? LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprev, PSTR cmdline, int ishow) { HWND hwnd; MSG msg; WNDCLASSEX wndclassex = {0}; char class_name[] = "My Game"; wndclassex.cbSize = sizeof(WNDCLASSEX); wndclassex.style = CS_HREDRAW | CS_VREDRAW; wndclassex.lpfnWndProc = WinProc; wndclassex.hInstance = hinstance; wndclassex.hIcon = LoadIcon(hinstance,IDI_APPLICATION); wndclassex.hbrBackground = (HBRUSH)(BLACK_BRUSH); wndclassex.lpszClassName = class_name; RegisterClassEx(&wndclassex); hwnd = CreateWindowEx(NULL, class_name, "My Game", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hinstance, NULL); if(!hwnd) { UnregisterClass(class_name,hinstance); return EXIT_FAILURE; } ShowWindow(hwnd, ishow); UpdateWindow(hwnd); HBITMAP hbitmap = (HBITMAP)LoadImage(hinstance,"ent.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE); HDC hdc = GetDC(hwnd); HDC image_dc = CreateCompatibleDC(hdc); HBITMAP old_hbitmap = (HBITMAP)(image_dc,hbitmap); BitBlt(hdc,50,50,320,192,image_dc,0,0,SRCCOPY); while(1) { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if(msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else { } } SelectObject(image_dc,old_hbitmap); DeleteObject(hbitmap); ReleaseDC(hwnd, hdc); DeleteDC(image_dc); UnregisterClass(class_name,hinstance); return msg.wParam; } LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; switch(message) { case WM_PAINT: BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); return 0; case WM_CLOSE: case WM_DESTROY: PostQuitMessage(0); return 0; } return(DefWindowProc(hwnd, message, wparam, lparam)); } when i try to compile it i get errors... 40 c:\windows\desktop\aotnsite\win_main.cpp warning: converting NULL to non-pointer type ....... 45 c:\windows\desktop\aotnsite\win_main.cpp `EXIT_FAILURE' undeclared (first use this function) ....... 45 c:\windows\desktop\aotnsite\win_main.cpp (Each undeclared identifier is reported only once ....... 45 c:\windows\desktop\aotnsite\win_main.cpp for each function it appears in.) those lines have: 40: NULL); 45:return EXIT_FAILURE; ........................... why wont it compile? ............................... There is no spoon [edited by - TheNerd Tk421 on August 8, 2003 11:12:39 AM] [edited by - TheNerd Tk421 on August 8, 2003 11:22:32 AM]

Share this post


Link to post
Share on other sites
The EXIT_FAILURE macro is defined in stdlib.h (or cstdlib, if you''re using C++). For some reason a lot of older C code--especially Windows programs--uses NULL for an integer 0, when NULL is supposed to represent an invalid pointer.

Share this post


Link to post
Share on other sites
and if you do not need any headers that define NULL for you just do #include <stddef.h>, it contains NULL (defined there as 0), and a bit of some other stuff, but nothing big.

Share this post


Link to post
Share on other sites