please help with my program

Started by
2 comments, last by Madmonky1 21 years, 7 months ago
The code I used is: #include <windows.h> #include <windowsx.h> #include <conio.h> #include <stdio.h> int xSize; int ySize; int xPos; int yPos; int focus; /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM); /* Make the class name into a global variable */ char szClassName[ ] = "RPG TEST!!!"; int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof(WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor(NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use light-gray as the background of the window */ wincl.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); /* Register the window class, if fail quit the program */ if(!RegisterClassEx(&wincl)) return 0; /* The class is registered, let''s create the program*/ hwnd = CreateWindowEx( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ "Windows App", /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 544, /* The programs width */ 375, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Make the window visible on the screen */ ShowWindow(hwnd, nFunsterStil); /* Run the message loop. It will run until GetMessage( ) returns 0 */ while(GetMessage(&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage( ) gave */ return messages.wParam; } /* This function is called by the Windows function DispatchMessage( ) */ LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) /* handle the messages */ { case WM_DESTROY: PostQuitMessage(0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don''t deal with */ return DefWindowProc(hwnd, message, wParam, lParam); } if (message == WM_SIZE) { xSize = LOWORD(lParam); ySize = HIWORD(lParam); } if (message == WM_MOVE) { xPos = LOWORD(lParam); yPos = HIWORD(lParam); } if (message == WM_ACTIVATE) { if (LOWORD(wParam) == WA_INACTIVE) focus = FALSE; else focus = TRUE; // tell Windows we handled it return(0); } if (message == WM_PAINT) { PAINTSTRUCT ps; // declare a PAINTSTRUCT for use with this message HDC hdc; // display device context for graphics calls hdc = BeginPaint(HWND, &ps); // validate the window //PAINT SOME STUFF!!! EndPaint(HWND, &ps); // release the DC // tell Windows we took care of it return(0); } return(0); } It worked fine until I added the paint message. heres the errors dev c++ returned: compiler: 110 parse erorr before '','' 115 parse erorr before '','' Linker: g++ c/dev-c++\rpging\rpgtest.o no such file or directory. g++ file path prefix C:/dev_C`1/'' bin never used by the way, could someone tell me the irc server and channel? the page wont work.(thats the server and channel, not help with how the page wont work peoples
the monky has no place in the circle of confusion. Now the mosspit of chaos...
Advertisement
Why do you have all those if(message==WM_?) after the switch statement? They way you do, windows is handling all but the WM_DESTROY message, as you send all others to DefWindowProc(). You should put them in the switch:
/* This function is called by the Windows function DispatchMessage( ) */LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){    switch (message) {    case WM_DESTROY:        PostQuitMessage(0);        break;    case WM_MOVE:        xPos = LOWORD(lParam);        yPos = HIWORD(lParam);        break;    case WM_SIZE:        xSize = LOWORD(lParam);        ySize = HIWORD(lParam);        break;    case WM_ACTIVATE:        if(LOWORD(wParam) == WA_INACTIVE)            focus = FALSE;        else            focus = TRUE;        return 0;     case WM_PAINT:        PAINTSTRUCT ps;        HDC hdc;        hdc = BeginPaint(HWND, &ps);        //PAINT SOME STUFF!!!        EndPaint(HWND, &ps);        return(0);    default:        return DefWindowProc(hwnd, message, wParam, lParam);    }    return(0);}    
if (message == WM_PAINT) {PAINTSTRUCT ps; // declare a PAINTSTRUCT for use with this messageHDC hdc; // display device context for graphics callshdc = BeginPaint(HWND, &ps); // validate the window//PAINT SOME STUFF!!!EndPaint(HWND, &ps); // release the DC// tell Windows we took care of itreturn(0);} 


should have the HWND in BeginPaint in lower case (hwnd), that should fix this line.

Take a look at the WindowProcedure function, the first argument is a HWND with the name hwnd.
madmonky1 thanks you very much for teaching him this. now he will be off to making some cool games.

I game therfore I am.
the monky has no place in the circle of confusion. Now the mosspit of chaos...

This topic is closed to new replies.

Advertisement