Click here to Skip to main content
15,889,877 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Howto: creating a dynamic menu? Pin
cromag9-Jan-06 5:19
cromag9-Jan-06 5:19 
GeneralRe: Howto: creating a dynamic menu? Pin
#realJSOP9-Jan-06 12:32
mve#realJSOP9-Jan-06 12:32 
QuestionVector of Strings simple problem PLEASE HELP Pin
Cursed Feanor6-Jan-06 7:05
Cursed Feanor6-Jan-06 7:05 
AnswerRe: Vector of Strings simple problem PLEASE HELP Pin
Roland Pibinger6-Jan-06 7:33
Roland Pibinger6-Jan-06 7:33 
JokeRe: Vector of Strings simple problem PLEASE HELP Pin
Cursed Feanor6-Jan-06 8:11
Cursed Feanor6-Jan-06 8:11 
AnswerRe: Vector of Strings simple problem PLEASE HELP Pin
David Crow6-Jan-06 9:43
David Crow6-Jan-06 9:43 
AnswerRe: Vector of Strings simple problem PLEASE HELP Pin
John R. Shaw6-Jan-06 18:26
John R. Shaw6-Jan-06 18:26 
QuestionTrying to get a bmp. to move with in boundries in a windows ap.... Pin
chadsxe6-Jan-06 6:05
chadsxe6-Jan-06 6:05 
I have gotten all the way up to the point were the bitmap is drawn on the windows ap. Now I basically am trying to get the bitmap to float around never leaving the bounds of the the ap. So if it hits a side of the ap (width or height) then it is just going to bounce off and go another way. Kind of like that one game were there was a paddle at the bottom of the screen and you had to bounce a ball towards the top were you broke down bricks. Anyways, take a look at the last function...
#include <windows.h><br />
#include <winuser.h><br />
#include <stdio.h><br />
#include <stdlib.h><br />
#include <time.h><br />
<br />
#define APPTITLE "Game Loop"<br />
<br />
//function prototypes<br />
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);<br />
ATOM MyRegisterClass(HINSTANCE);<br />
BOOL InitInstance(HINSTANCE,int);<br />
void DrawBitmap(HDC,char*,int,int);<br />
void Game_Init();<br />
void Game_Run();<br />
void Game_End();<br />
<br />
//local variables<br />
HWND global_hwnd;<br />
HDC global_hdc;<br />
<br />
//the window event callback function<br />
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)<br />
{<br />
    global_hwnd = hWnd;<br />
    global_hdc = GetDC(hWnd);<br />
<br />
	switch (message) <br />
	{<br />
		case WM_DESTROY:<br />
            Game_End();<br />
			PostQuitMessage(0);<br />
			break;<br />
    }<br />
	return DefWindowProc(hWnd, message, wParam, lParam);<br />
}<br />
<br />
//helper function to set up the window properties<br />
ATOM MyRegisterClass(HINSTANCE hInstance)<br />
{<br />
    //create the window class structure<br />
    WNDCLASSEX wc;<br />
    wc.cbSize = sizeof(WNDCLASSEX); <br />
<br />
    //fill the struct with info<br />
    wc.style         = CS_HREDRAW | CS_VREDRAW;<br />
    wc.lpfnWndProc   = (WNDPROC)WinProc;<br />
    wc.cbClsExtra	 = 0;<br />
    wc.cbWndExtra	 = 0;<br />
    wc.hInstance     = hInstance;<br />
    wc.hIcon         = NULL;<br />
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);<br />
    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);<br />
    wc.lpszMenuName  = NULL;<br />
    wc.lpszClassName = APPTITLE;<br />
    wc.hIconSm       = NULL;<br />
<br />
    //set up the window with the class info<br />
    return RegisterClassEx(&wc);<br />
}<br />
<br />
//helper function to create the window and refresh it<br />
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)<br />
{<br />
    HWND hWnd;<br />
<br />
    //create a new window<br />
    hWnd = CreateWindow(<br />
       APPTITLE,              //window class<br />
       APPTITLE,              //title bar<br />
       WS_OVERLAPPEDWINDOW,   //window style<br />
       CW_USEDEFAULT,         //x position of window<br />
       CW_USEDEFAULT,         //y position of window<br />
       500,                   //width of the window<br />
       400,                   //height of the window<br />
	   NULL,                  //parent window<br />
       NULL,                  //menu<br />
       hInstance,             //application instance<br />
       NULL);                 //window parameters<br />
<br />
    //was there an error creating the window?<br />
    if (!hWnd)<br />
      return FALSE;<br />
<br />
    //display the window<br />
    ShowWindow(hWnd, nCmdShow);<br />
    UpdateWindow(hWnd);<br />
<br />
    return TRUE;<br />
}<br />
<br />
//entry point for a Windows program<br />
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)<br />
{<br />
    int done = 0;<br />
	MSG msg;<br />
<br />
	// register the class<br />
	MyRegisterClass(hInstance);<br />
<br />
    // initialize application<br />
	if (!InitInstance (hInstance, nCmdShow)) <br />
		return FALSE;<br />
<br />
    //initialize the game<br />
    Game_Init();<br />
<br />
    // main message loop<br />
	while (!done)<br />
	{<br />
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) <br />
        {<br />
            //look for quit message<br />
            if (msg.message == WM_QUIT)<br />
                done = 1;<br />
<br />
            //decode and pass messages on to WndProc<br />
            TranslateMessage(&msg);<br />
		    DispatchMessage(&msg);<br />
        }<br />
        //process game loop<br />
        Game_Run();<br />
	}<br />
<br />
	return msg.wParam;<br />
}<br />
<br />
void DrawBitmap(HDC hdcDest, char *filename, int x, int y)<br />
{<br />
    HBITMAP image;<br />
    BITMAP bm;<br />
	HDC hdcMem;<br />
<br />
    //load the bitmap image<br />
    image = LoadImage(0,"w.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);<br />
<br />
    //read the bitmap's properties<br />
    GetObject(image, sizeof(BITMAP), &bm);<br />
<br />
    //create a device context for the bitmap<br />
    hdcMem = CreateCompatibleDC(global_hdc);<br />
	SelectObject(hdcMem, image);<br />
<br />
    //draw the bitmap to the window (bit block transfer)<br />
    BitBlt( <br />
        global_hdc,              //destination device context<br />
        x, y,                    //x,y location on destination<br />
        bm.bmWidth, bm.bmHeight, //width,height of source bitmap<br />
	    hdcMem,                  //source bitmap device context<br />
        0, 0,                    //start x,y on source bitmap<br />
        SRCCOPY);                //blit method<br />
<br />
    //delete the device context and bitmap<br />
    DeleteDC(hdcMem);<br />
    DeleteObject((HBITMAP)image);<br />
}<br />
<br />
<br />
void Game_Init()<br />
{<br />
    //initialize the game...<br />
    //load bitmaps, meshes, textures, sounds, etc.<br />
<br />
    srand(time(NULL));<br />
}<br />
<br />
void Game_Run()<br />
{<br />
    //this is called once every frame<br />
    //do not include your own loop here!  <br />
    char buffer[80];<br />
    static iCount = 0;<br />
    int x = 0, y = 0;<br />
    RECT rect;<br />
    GetClientRect(global_hwnd, &rect);<br />
<br />
//    if (rect.right > 0)<br />
//    {<br />
//     x = rand() % (rect.right - rect.left);<br />
//     y = rand() % (rect.bottom - rect.top);<br />
        DrawBitmap(global_hdc, "c.bmp", x, y);<br />
//    }<br />
<br />
    iCount++;<br />
    sprintf(buffer,"%d",iCount);<br />
    TextOut(global_hdc,0,10, buffer,strlen(buffer));<br />
}<br />
<br />
<br />
If you take a look you will notice I am trying to get this accomplished in the Game_Run(). As of now the bitmap is drawn in the top left corner of the form (0,0) The stuff that is commented out is some things I was working on but failing at.

How do you create an object of the actual instance of the bitmap I a trying to get to move?

Thanks

Chad
AnswerRe: Trying to get a bmp. to move with in boundries in a windows ap.... Pin
KellyR6-Jan-06 6:34
KellyR6-Jan-06 6:34 
AnswerRe: Trying to get a bmp. to move with in boundries in a windows ap.... Pin
John R. Shaw6-Jan-06 19:05
John R. Shaw6-Jan-06 19:05 
QuestionAdding controls to a CTabCtrl Pin
Mark F.6-Jan-06 5:05
Mark F.6-Jan-06 5:05 
AnswerRe: Adding controls to a CTabCtrl Pin
#realJSOP7-Jan-06 3:12
mve#realJSOP7-Jan-06 3:12 
QuestionRe: Adding controls to a CTabCtrl Pin
Mark F.7-Jan-06 8:41
Mark F.7-Jan-06 8:41 
AnswerRe: Adding controls to a CTabCtrl Pin
#realJSOP8-Jan-06 3:14
mve#realJSOP8-Jan-06 3:14 
GeneralRe: Adding controls to a CTabCtrl Pin
Mark F.8-Jan-06 3:51
Mark F.8-Jan-06 3:51 
GeneralRe: Adding controls to a CTabCtrl Pin
#realJSOP9-Jan-06 0:17
mve#realJSOP9-Jan-06 0:17 
GeneralRe: Adding controls to a CTabCtrl Pin
Mark F.9-Jan-06 2:46
Mark F.9-Jan-06 2:46 
QuestionHelp! InternetConnect is broken! Pin
Anacreon6-Jan-06 5:01
Anacreon6-Jan-06 5:01 
QuestionLinear smooth Graph Pin
RockyJames6-Jan-06 3:40
RockyJames6-Jan-06 3:40 
AnswerRe: Linear smooth Graph Pin
Curtis Schlak.6-Jan-06 4:25
Curtis Schlak.6-Jan-06 4:25 
QuestionColumn Selection in MFC Pin
tayal1224366-Jan-06 3:22
tayal1224366-Jan-06 3:22 
AnswerRe: Column Selection in MFC Pin
BlackDice6-Jan-06 5:44
BlackDice6-Jan-06 5:44 
GeneralRe: Column Selection in MFC Pin
tayal1224366-Jan-06 17:45
tayal1224366-Jan-06 17:45 
GeneralRe: Column Selection in MFC Pin
ThatsAlok9-Jan-06 1:00
ThatsAlok9-Jan-06 1:00 
QuestionHow to indicate the buffer size before calling function recv, WSARecv in socket programming??? Pin
lvantin6-Jan-06 3:17
lvantin6-Jan-06 3:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.