Results 1 to 6 of 6

Thread: Stupid Graphics!

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Stupid Graphics!

    Okay this is getting really annoying....I've been trying for so long to get graphics to work. and they still won't Can someone give me an example? Preferably having it redraw during WM_PAINT.....every tme I try I either get errors or just nothing happens.....All I want to do is show a bitmap!

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I hate WM_PAINT Ooh that rhymes

    Are you trying to display a bitmap from a file, or from a resource?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I've only really tried resource...

  4. #4
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Here is a quick example:

    Code:
    #include <windows.h>
    #include "resource.h"
    static char g_szClassName[] = "MyWindowClass";
    static HINSTANCE hinst = NULL;
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    HWND hwnd;
    PAINTSTRUCT ps;
    HDC hdc, memhdc;
    HBITMAP mybmp;
    BITMAP bm;
    
    //MYBMP is a bitmap in the resource file
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
       LPSTR lpCmdLine, int nCmdShow)
    {
       WNDCLASSEX WndClass;
       MSG Msg;
    
       hinst = hInstance;
    
       mybmp = LoadBitmap(hinst, MAKEINTRESOURCE(MYBMP));
    
       WndClass.cbSize        = sizeof(WNDCLASSEX);
       WndClass.style         = CS_HREDRAW | CS_VREDRAW;
       WndClass.lpfnWndProc   = WndProc;
       WndClass.cbClsExtra    = 0;
       WndClass.cbWndExtra    = 0;
       WndClass.hInstance     = hinst;
       WndClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
       WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
       WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
       WndClass.lpszMenuName  = NULL;
       WndClass.lpszClassName = g_szClassName;
       WndClass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
       if(!RegisterClassEx(&WndClass))
       {
          MessageBox(0, "Window Registration Failed! :(", "Error!",
             MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
          return 0;
       }
    
       hwnd = CreateWindowEx(
          NULL,
          g_szClassName,
          "Coloured Shapes Generator",
          WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT, CW_USEDEFAULT, 320, 240,
          NULL, NULL, hinst, NULL);
    
       if(hwnd == NULL)
       {
          MessageBox(0, "Window Creation Failed! :(", "Error!",
             MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
          return 0;
       }
    
    
       ShowWindow(hwnd, nCmdShow);
       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)
    {
    	
       switch(Message)
       {
       case WM_PAINT:
    	   hdc = BeginPaint(hwnd, &ps);
    	   memhdc = CreateCompatibleDC(hdc);
    	   SelectObject(memhdc, mybmp);
    	   //Draws the bitmap on the memory DC
    
    	   GetObject(mybmp, sizeof(bm), &bm);
    
    	   //Gets the info about the bitmap and stores that in "bm"
    	   BitBlt(hdc, 0,0, bm.bmWidth, bm.bmHeight, memhdc, 0,0, SRCCOPY);
    
    	   //Draws the bitmap on the window from the memory DC
    
    	   DeleteDC(memhdc);
    	   EndPaint(hwnd, &ps);
    
    	   return 0;
       
          case WM_CLOSE:
    		  DeleteObject(mybmp);
             DestroyWindow(hwnd);
          break;
          case WM_DESTROY:
             PostQuitMessage(0);
          break;
          default:
             return DefWindowProc(hwnd, Message, wparam, lparam);
       }
       return 0;
    }
    Baaaaaaaaah

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Oops...forgot to say we solved it on MSN

    The code was basically identical apart from I had the window procedure first in the file Hee hee....
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Yeah sorry forgot to mention that....sorry I left and didn't think about posting...Im on my grandparents computer now with 32 megs RAM!!!! IM GOING NUTS!


    Thanks Guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width