Moving A Picture..slight prob

This is a discussion on Moving A Picture..slight prob within the Windows Programming forums, part of the Platform Specific Boards category; Hey, I'm having a weird problem( I havn't done windows programming in several months so don't get mad at me). ...

  1. #1
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035

    Moving A Picture..slight prob

    Hey, I'm having a weird problem( I havn't done windows programming in several months so don't get mad at me). I am trying to make it so when the user presses right, the picture goes right one space. Here is my code for WM_PAINT:
    Code:
    case WM_PAINT:
    		{
    			
    			if(moveright == TRUE)
    			{
    	
    			
    		hDC = BeginPaint(hWnd, &ps);
    		hBitmap = (HBITMAP)LoadImage(NULL, "C:\\Visual C++\\Game\\none.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    	                 DrawState(hDC, NULL, NULL, (LPARAM)hBitmap, 0, picx, picy, picsizex, picsizey, DST_BITMAP | DSS_NORMAL);
    		picx+=4;
    		hBitmap = (HBITMAP)LoadImage(NULL, "C:\\Visual C++\\Game\\guy.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    		DrawState(hDC, NULL, NULL, (LPARAM)hBitmap, 0, picx, picy, picsizex, picsizey, DST_BITMAP | DSS_NORMAL);
    	
    		
    		
    			}
    //WM_PAINT goes on...
    anyway, when I press right it goes right through WM_PAINT and goes through moveright==true. I know this because when I press right, it only shows my guy once. When I press it again, he doesn't move at all. He just stays in the same place. Help? Thanks in advance.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    How have you declared

    picx

    Is it a static?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Talking Just use a "static" window...

    Like this:


    int px=0;

    HWND hStatic;

    hStatic=CreateWindow(
    "static", NULL,
    WS_CHILD | WS_VISIBLE | SS_BITMAP,
    0, 0, 300, 300, // Change 300, 300 to the image width/height
    hwnd,
    0,
    0,
    0
    );

    // Code


    case WM_KEYDOWN:
    switch(LOWORD(wParam))
    {
    case VK_RIGHT:
    px+=1;

    SetWindowPos(hStatic, 0, 0, 0, px, 0, FALSE);
    }
    break;


    or something like that...
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  4. #4
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    making a static window like that doesn't work. Anyway, here's my code(sorry to dump it all on you )
    Code:
    #include <windows.h>
    #include <tchar.h>
    #include "resource.h"
    #include <conio.h>
    #include <windowsx.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <math.h>
    #include <iostream.h>
    //GLOBALS//////////////////////////////////////
    int picx=0;
    int picy=0;
    int picsizex=100;
    int picsizey=100;
    ///////////////////////////////////////////////
    TCHAR	szBitmapFilename[MAX_PATH];
    HBITMAP	hBitmap;
    
    LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	PAINTSTRUCT	ps;
    	HDC			hDC;
    
    
    		if(GetAsyncKeyState(VK_RIGHT))
    	{
    		
    		
    		
    	
    			
    		hDC = BeginPaint(hWnd, &ps);
    		hBitmap = (HBITMAP)LoadImage(NULL, "C:\\Visual C++\\Game\\none.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    	    DrawState(hDC, NULL, NULL, (LPARAM)hBitmap, 0, picx, picy, picsizex, picsizey, DST_BITMAP | DSS_NORMAL);
    		hBitmap = (HBITMAP)LoadImage(NULL, "C:\\Visual C++\\Game\\guy.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    		picx++;
    		DrawState(hDC, NULL, NULL, (LPARAM)hBitmap, 0, picx, picy, picsizex, picsizey, DST_BITMAP | DSS_NORMAL);
    		EndPaint(hWnd, &ps);
    		
    		
    			
    
    		
    	
    	}
    	switch (uMsg)
    	{
    
    
    
    	case WM_PAINT:
    		{
    		
    		return 0;
    		}break;
    	case WM_CLOSE:
    		PostQuitMessage(0);
    		DestroyWindow(hWnd);
    		return 0;break;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    	
    
    	
    	}
    
    	return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    
    
    void RegisterWindowClass()
    {
    	WNDCLASSEX	wcx;
    
    	ZeroMemory(&wcx, sizeof(WNDCLASSEX));
    	wcx.cbSize = sizeof(WNDCLASSEX);
    	wcx.lpfnWndProc = MainWindowProc;
    	wcx.hInstance = GetModuleHandle(NULL);
    	wcx.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
    	wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    	wcx.lpszMenuName = NULL;
    	wcx.lpszClassName = "WinClass";
    	RegisterClassEx(&wcx);
    }
    
    HWND hWndMain;
    
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) 
    {
    	MSG	msg;
    	RegisterWindowClass();
    	HDC hDC;
    	HWND hWnd;
    	hWndMain = CreateWindowEx(WS_EX_APPWINDOW,
    		"WinClass", "Some Game", WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
    		NULL, NULL, hInstance, NULL);
    	
    	ShowWindow(hWndMain, SW_SHOW);
    	
    	
    PlaySound("C:\\chrono.wav",NULL,SND_FILENAME | SND_ASYNC);		
    
    
    		while (GetMessage(&msg, NULL, 0, 0))
    		DispatchMessage(&msg);
    
    	
    
    
    	return 0;
    }
    guy.bmp just isn't going right another space! Someone help me solve this simple problem!

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Actually I meant to ensure that the variable was a static, as it may have lost scope in the callback, but you have it as a global.

    Why are you not using a framebuffer?

    When is the screen cleared of the last drawing?

    If you call BeginPaint() it will, as I understand it, return the HDC of the update region. What will it return if there is NO update region? (because you are calling it without a WM_PAINT msg being generated) In other words is the HDC returned from the BeginPaint() call the right one or NULL?

    Do some error checking on the DrawState() function. eg use GetLastError() if the return is a fail.

    Why are you not processing WM_KEYDOWN msg's to find user input?

    Better msg loop
    Code:
    while(GetMessage(&msg, NULL , 0, 0))	//get all messages associated with the current thread
    {
          TranslateMessage(&msg) ;
          DispatchMessage(&msg) ;
    }
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [C] change picture width and height in Static control (no MFC)
    By pc2-brazil in forum Windows Programming
    Replies: 1
    Last Post: 05-05-2008, 02:17 AM
  2. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-24-2007, 12:05 AM
  3. 3D moving
    By bluehead in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2005, 05:46 AM
  4. Embedding Objects into Picture Controls
    By Capsher Codah in forum Windows Programming
    Replies: 1
    Last Post: 03-05-2005, 09:38 PM
  5. Moving a picture
    By Death_Wraith in forum C++ Programming
    Replies: 2
    Last Post: 03-13-2004, 08:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21