Results 1 to 35 of 35

Thread: Resource Files: Pictures

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I know how to use menus....now how do I use pictures?

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    If you mean bitmaps you can just import them in the resource editor, if you are using MSVC. If you arent then I am not sure how exactly to do it.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I mean like in the code you need to add SetMenu...is there a command for bitmaps?

  4. #4
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    So you want to display a bitmap on an object?
    What kind of object? Picturebox? Static?

    Or add a picture to your menu?
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    ooooh... didn't know there were so many choices

    I'd like to know how to add them to menus and picture boxes.

    Thanks

  6. #6
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Well I am not sure how to add to a menu, because I have never done it before, but I know it can be done.

    How are you creating your picture box?
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    you know what... scratch that idea, I know how to make Static boxes....so how would I add pictures to them?

    Sorry wasn't thinking before

  8. #8
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    With a static box, you will have to use DCs and BitBlt. Are you familure with those?
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  9. #9

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

  10. #10
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Ok, well this is a long process to explain, are you up to it?
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Sure...I'm off of school today due to the snow!

    (Thanks by the way! )

  12. #12
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    No problem, ok here it goes:

    Here is a VB world tutorial if you get stuck. I know its in VB but all the code is about the same.

    http://www.vb-world.net/graphics/lander/

    Ok first thing you need to do is load your bitmap into memory, or a DC (Device Handle).

    I am writing this free hand so there might be spelling or ; errors

    Code:
    HDC hdc;   //File that will hold the bitmap in memory
    
    hdc = CreateCompatibleDC(NULL);   //Creates a space in memory
    Ok now we have the DC setup now its time to get the bitamp. You will need to have a VAR with your instance, ie hInstance.

    Code:
    HBITMAP hBitmap;   //This will hold the Bitmap so we can load it into the DC
    
    //If you have the bitmap loaded as a resource
    hBitmap = (HBITMAP)SelectObject(hdc, LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_YOURBITMAP)));
    
    //What we did is load the bitmap from the resource editor to the VAR hBitmap, then move it to the DC using SelectObject.
    
    //Little error checking
    if ((!hdc) || (!hBitmap))
    MessageBox(NULL,"ERROR","ERROR",NULL);
    Its important that when you go to exit your program, or you are COMPLETELY done with them, you kill the DC and the Bitmap from memory or else you have a leak.

    Code:
    DeleteDC(hdc);
    DeleteObject(hBitmap);
    Ok now come BitBlt, I need a sec to look something up so I will post the rest in a sec
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I get these errors:
    Code:
    C:\Windows\Profiles\Steve\Desktop\C c++\Pictures\Pictures.cpp(17) : error C2065: 'hdc' : undeclared identifier
    C:\Windows\Profiles\Steve\Desktop\C c++\Pictures\Pictures.cpp(18) : error C2065: 'hBitmap' : undeclared identifier
    C:\Windows\Profiles\Steve\Desktop\C c++\Pictures\Pictures.cpp(48) : error C2065: 'IDB_BITMAP1": undeclared identifier

  14. #14
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Let me see your code
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  15. #15
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Ok BitBlting, here comes the hard part and the part that will drive you insane if you have anything wrong.

    You will need to have the HDC of the device you want to paint to. You can use GetDC to get it or you can catch the WM_PAINT message and use PAINTSTRUCT. Since this is your first time you should just use GetDC for right now.

    Example:
    Code:
    HDC hdc_topaint;
    
    hdc_topaint = GetDC(hWndOfTheDeviceToPaint);
    Once you have that you need to know the size of the bitmap and the size of the device you are painting to. You can get that using a number of different ways but for now just write the sizes down when you make your static object, and most bitmap editors will give you the size. I would make the bitmap the same size as your static object to make your life easier for right now.

    Ok now BitBlt:
    Code:
    BitBlt(hdc_topaint, Xdest, Ydest, Width, Height, hdc, Xsrc, Ysrc, SRCOPY);
    
    //hdc_topaint is the hdc of the device to paint to
    //Xdest, put the X position to start painting at, you will prob use 0 most of the time
    //Ydest, put the Y position to start painting at, you will prob use 0 most of the time
    //Width, this is the exact width of the static device you are painting to
    //Height, this is the exact height of the static device you are painting to
    //hdc, this is the DC of the bitmap we loaded into memory
    //Xsrc, put the X position to start copying the bitmap from, you will prob use 0 most of the time
    //Ysrc, put the Y position to start copying the bitmap from, you will prob use 0 most of the time
    //SRCOPY, this is the raster code we will use, this means exact copy from bitmap to device.  There are a bunch of others that do different things, just look up BitBlt in the MSDN.
    Now for some bad news, the image is not "actually" on that object. What the means is that each time the object is refreshed it will disapear. I can tell you how to fix that, but try to get it up there first then we will work on the refresh.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    PHP Code:
    // Pictures in Static Boxes
    // By Steve Mack 
    // March 6, 2001 (06.03.01)

    #include <windows.h>

    HWND ghWnd_Main// this is the main window 
      //  }
    HWND ghWnd_ExitButton;
    HWND ghWnd_label;
    HWND ghWnd_Hello;

    LRESULT CALLBACK WndProc(HWND hWndUINT uMsgWPARAM wParamLPARAM lParam) {
        switch(
    uMsg) {
            case 
    WM_CLOSE:
                
    DestroyWindow(ghWnd_Main); // Destroy the main window
                
    DeleteDC(hdc);
                
    DeleteObject(hBitmap);
                return 
    0;

            case 
    WM_DESTROY:
                
    PostQuitMessage(0); // Quit the application
                
    DeleteDC(hdc);
                
    DeleteObject(hBitmap);
                return 
    0;

            case 
    WM_COMMAND:
                if(
    LOWORD(wParam) == BN_CLICKED && (HWND)lParam == ghWnd_ExitButton) {
                    
    PostQuitMessage(0);
                }
                if(
    LOWORD(wParam) == BN_CLICKED && (HWND)lParam == ghWnd_Hello) {
                    
    SendMessage(ghWnd_labelWM_SETTEXT0, (LPARAM) (LPCTSTR"Hello World!");
                }
                return 
    0;
        }
        return 
    DefWindowProc(hWnduMsgwParamlParam); // Not handled - let the system deal with it
    }

    int WINAPI WinMain(HINSTANCE hInstanceHINSTANCE hPrevInstanceLPSTR lpCmdLineint nCmdShow) {
        
    WNDCLASSEX wcxMyClass;


        
    HDC hdc;   //File that will hold the bitmap in memory
        
    hdc CreateCompatibleDC(NULL);   //Creates a space in memory
        
    HBITMAP hBitmap;   //This will hold the Bitmap so we can load it into the DC

        //If you have the bitmap loaded as a resource
        
    hBitmap = (HBITMAP)SelectObject(hdcLoadBitmap(hInstanceMAKEINTRESOURCE(IDB_BITMAP1)));
        
        
    //What we did is load the bitmap from the resource editor to the VAR hBitmap, then move it to the DC using SelectObject.
        
        //Little error checking
        
    if ((!hdc) || (!hBitmap)) {
            
    MessageBox(NULL,"ERROR","ERROR",NULL);
        }


        
    wcxMyClass.cbSize sizeof(WNDCLASSEX); // Size of structure in bytes
        
    wcxMyClass.style 0// Extra style information
        
    wcxMyClass.lpfnWndProc WndProc// Pointer to window procedure
        
    wcxMyClass.cbClsExtra 0// Extra bytes in class definition
        
    wcxMyClass.cbWndExtra 0// Extra bytes for each window
        
    wcxMyClass.hInstance hInstance// Instance handle for the class
        
    wcxMyClass.hIcon NULL// Default icon - use system
        
    wcxMyClass.hCursor LoadCursor(NULLIDC_ARROW); // Load the system arrow
        
    wcxMyClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE 1); // Background brush
        
    wcxMyClass.lpszMenuName NULL// Menu name [MAKEINTRESOURCE(IDM_MAINMENU)] - none here
        
    wcxMyClass.lpszClassName "TESTCLASS"// Class name
        
    wcxMyClass.hIconSm NULL// Small icon
        
        
    RegisterClassEx(&wcxMyClass); // Register the class

        
    ghWnd_Main CreateWindow("TESTCLASS""Steve's Program!", \
                                  
    WS_OVERLAPPEDWINDOW100100300300, \
                                  
    NULLNULLhInstanceNULL);
        if(
    ghWnd_Main) {
            
    ghWnd_ExitButton CreateWindow("Button""E&xit"WS_CHILD WS_VISIBLE10020010030ghWnd_MainNULLhInstanceNULL);
            
    ghWnd_label CreateWindow("Static""&What Will I Say?"WS_CHILD WS_VISIBLE501020030ghWnd_MainNULLhInstanceNULL);

            
    ShowWindow(ghWnd_MainnCmdShow); // Show using the specific show style
        
    }

        
    /////////////////////////
        // Handle message loop //
        /////////////////////////
        
    MSG msg;
        while(
    GetMessage(&msgNULL00)) {
            
    TranslateMessage(&msg); // Translate keycode messages
            
    DispatchMessage(&msg); // Send to the window
        
    }

        
    UnregisterClass("TESTCLASS"hInstance); // Unregister our window class
        
    return msg.wParam// msg.wParam contains the code passed to PostQuitMessage()

    (I have included the bitmap resource file and the resource header)

  17. #17
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Ah ok, you need to move
    HDC hdc;
    HBITMAP hBitmap;
    to be global so move them under
    HWND ghWnd_Hello;
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  18. #18
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    You also need to include your resource header file so you can use IDB_BITMAP1

    #include "resource.h" is the most common header for the resources
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  19. #19

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    errors:
    Code:
    C:\Windows\Profiles\Steve\Desktop\C c++\Pictures\Pictures.cpp(14) : error C2501: 'hdc' : missing storage-class or type specifiers
    C:\Windows\Profiles\Steve\Desktop\C c++\Pictures\Pictures.cpp(14) : error C2040: 'hdc' : 'int' differs in levels of indirection from 'struct HDC__ *'
    C:\Windows\Profiles\Steve\Desktop\C c++\Pictures\Pictures.cpp(14) : error C2440: 'initializing' : cannot convert from 'struct HDC__ *' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    C:\Windows\Profiles\Steve\Desktop\C c++\Pictures\Pictures.cpp(21) : error C2065: 'hBitmap' : undeclared identifier
    Code:
    Code:
    // Pictures in Static Boxes
    // By Steve Mack 
    // March 6, 2001 (06.03.01)
    
    #include <windows.h>
    #include "resource.h"
    
    HWND ghWnd_Main; // this is the main window 
      //  }
    HWND ghWnd_ExitButton;
    HWND ghWnd_label;
    HWND ghWnd_Hello;
    	HDC hdc;   //File that will hold the bitmap in memory
    	hdc = CreateCompatibleDC(NULL);   //Creates a space in memory
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    	switch(uMsg) {
    		case WM_CLOSE:
    			DestroyWindow(ghWnd_Main); // Destroy the main window
    			DeleteDC(hdc);
    			DeleteObject(hBitmap);
    			return 0;
    
    		case WM_DESTROY:
    			PostQuitMessage(0); // Quit the application
    			DeleteDC(hdc);
    			DeleteObject(hBitmap);
    			return 0;
    
    		case WM_COMMAND:
    			if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == ghWnd_ExitButton) {
    				PostQuitMessage(0);
    			}
    			if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == ghWnd_Hello) {
    				MessageBox(hWnd, "Hello World", "...", MB_OK);
    			}
    			return 0;
    	}
    	return DefWindowProc(hWnd, uMsg, wParam, lParam); // Not handled - let the system deal with it
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    	WNDCLASSEX wcxMyClass;
    
    
    	HBITMAP hBitmap;   //This will hold the Bitmap so we can load it into the DC
    
    	//If you have the bitmap loaded as a resource
    	hBitmap = (HBITMAP)SelectObject(hdc, LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1)));
    	
    	//What we did is load the bitmap from the resource editor to the VAR hBitmap, then move it to the DC using SelectObject.
    	
    	//Little error checking
    	if ((!hdc) || (!hBitmap)) {
    		MessageBox(NULL,"ERROR","ERROR",NULL);
    	}
    
    
    	wcxMyClass.cbSize = sizeof(WNDCLASSEX); // Size of structure in bytes
    	wcxMyClass.style = 0; // Extra style information
    	wcxMyClass.lpfnWndProc = WndProc; // Pointer to window procedure
    	wcxMyClass.cbClsExtra = 0; // Extra bytes in class definition
    	wcxMyClass.cbWndExtra = 0; // Extra bytes for each window
    	wcxMyClass.hInstance = hInstance; // Instance handle for the class
    	wcxMyClass.hIcon = NULL; // Default icon - use system
    	wcxMyClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Load the system arrow
    	wcxMyClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); // Background brush
    	wcxMyClass.lpszMenuName = NULL; // Menu name [MAKEINTRESOURCE(IDM_MAINMENU)] - none here
    	wcxMyClass.lpszClassName = "TESTCLASS"; // Class name
    	wcxMyClass.hIconSm = NULL; // Small icon
    	
    	RegisterClassEx(&wcxMyClass); // Register the class
    
    	ghWnd_Main = CreateWindow("TESTCLASS", "Steve's Program!", \
    		                      WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, \
    							  NULL, NULL, hInstance, NULL);
    	if(ghWnd_Main) {
    		ghWnd_ExitButton = CreateWindow("Button", "E&xit", WS_CHILD | WS_VISIBLE, 100, 200, 100, 30, ghWnd_Main, NULL, hInstance, NULL);
    		ghWnd_label = CreateWindow("Static", "&What Will I Say?", WS_CHILD | WS_VISIBLE, 50, 10, 200, 30, ghWnd_Main, NULL, hInstance, NULL);
    
    		ShowWindow(ghWnd_Main, nCmdShow); // Show using the specific show style
    	}
    
    	/////////////////////////
    	// Handle message loop //
    	/////////////////////////
    	MSG msg;
    	while(GetMessage(&msg, NULL, 0, 0)) {
    		TranslateMessage(&msg); // Translate keycode messages
    		DispatchMessage(&msg); // Send to the window
    	}
    
    	UnregisterClass("TESTCLASS", hInstance); // Unregister our window class
    	return msg.wParam; // msg.wParam contains the code passed to PostQuitMessage()
    }

  20. #20
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Ummm........HEHE you can do this
    hdc = CreateCompatibleDC(NULL); //Creates a space in memory
    here move it back and put
    HBITMAP hBitmap; //This will hold the Bitmap so we can load it into the DC
    there
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  21. #21

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Okay no errors, but no picture either...do I have to change the declaration of the static box?

    Code:
    	ghWnd_label = CreateWindow("Static", "Picture", WS_CHILD | WS_VISIBLE, 50, 10, 200, 30, ghWnd_Main, NULL, hInstance, NULL);

  22. #22
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Try this
    Code:
    ghWnd_label = CreateWindowEx(WS_EX_NOPARENTNOTIFY, "Static", NULL, WS_CHILD | SS_REALSIZEIMAGE, 50, 10, 200, 20, ghWnd_Main, NULL, hInstance, NULL);
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  23. #23
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I dont see your BitBlt, am I missing it?
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  24. #24

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    how would I use bitblt?

  25. #25
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I explained how to use it a few posts up.

    Put it under your Hello button just as a test
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  26. #26

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Oh I'm sorry I didn't see you posted twice there!

    still doesn't show up though

  27. #27
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Can you zip you entire project dir and post it
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  28. #28

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    ITs a little too big...I'll email it.
    What's your email?

  29. #29
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  30. #30

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

  31. #31
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Got it I am looking at it right now
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  32. #32
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Ok first of you did not put in BitBlt, that is what puts the Image on the screen for you, everything else just gets it ready.

    I maked all the changes I think

    Code:
    // Pictures in Static Boxes
    // By Steve Mack 
    // March 6, 2001 (06.03.01)
    
    #include <windows.h>
    #include "resource.h"
    
    HWND	ghWnd_Main; // this is the main window 
    HWND	ghWnd_ExitButton;
    HWND	ghWnd_label;
    HWND	ghWnd_Hello;
    
    HDC		hdc;   //File that will hold the bitmap in memory
    
    HBITMAP	hBitmap; //This will hold the Bitmap so we can load it into the DC 
    
    
    	
    LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
    {
    	switch(uMsg) 
    	{
    		case WM_CLOSE:
    			DeleteDC(hdc);				//<----------------Change
    			DeleteObject(hBitmap);		//<----------------Change
    			DestroyWindow(ghWnd_Main); // Destroy the main window
    			return 0;
    
    		case WM_DESTROY:
    			DeleteDC(hdc);			//<----------------Change
    			DeleteObject(hBitmap);	//<----------------Change
    			PostQuitMessage(0); // Quit the application
    			return 0;
    
    		case WM_COMMAND:
    			if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == ghWnd_ExitButton) 
    			{
    				PostQuitMessage(0);
    			}
    			//<----------------Changed To Be Used For BitBlt
    			if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == ghWnd_Hello) 
    			{
    				HDC hdc_label;
    				hdc_label = GetDC(ghWnd_label);
    				BitBlt(hdc_label, 0, 0, 200, 50, hdc, 0, 0, SRCCOPY);
    			}
    			return 0;
    	}
    
    	return DefWindowProc(hWnd, uMsg, wParam, lParam); // Not handled - let the system deal with it
    }
    
    
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 
    {
    	WNDCLASSEX wcxMyClass;
    
    	hdc = CreateCompatibleDC(NULL);   //Creates a space in memory
    	//HBITMAP hBitmap;   //<------------Delete
    
    	//If you have the bitmap loaded as a resource
    	hBitmap = (HBITMAP)SelectObject(hdc, LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1)));
    	
    	//What we did is load the bitmap from the resource editor to the VAR hBitmap, then move it to the DC using SelectObject.
    	
    	//Little error checking
    	if ((!hdc) || (!hBitmap)) 
    	{
    		MessageBox(NULL,"ERROR","ERROR",NULL);
    	}
    
    
    	wcxMyClass.cbSize = sizeof(WNDCLASSEX); // Size of structure in bytes
    	wcxMyClass.style = 0; // Extra style information
    	wcxMyClass.lpfnWndProc = WndProc; // Pointer to window procedure
    	wcxMyClass.cbClsExtra = 0; // Extra bytes in class definition
    	wcxMyClass.cbWndExtra = 0; // Extra bytes for each window
    	wcxMyClass.hInstance = hInstance; // Instance handle for the class
    	wcxMyClass.hIcon = NULL; // Default icon - use system
    	wcxMyClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Load the system arrow
    	wcxMyClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); // Background brush
    	wcxMyClass.lpszMenuName = NULL; // Menu name [MAKEINTRESOURCE(IDM_MAINMENU)] - none here
    	wcxMyClass.lpszClassName = "TESTCLASS"; // Class name
    	wcxMyClass.hIconSm = NULL; // Small icon
    	
    	RegisterClassEx(&wcxMyClass); // Register the class
    
    	ghWnd_Main = CreateWindow("TESTCLASS", "Steve's Program!", \
    		                      WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, \
    							  NULL, NULL, hInstance, NULL);
    	if(ghWnd_Main) 
    	{
    		ghWnd_ExitButton = CreateWindow("Button", "E&xit", WS_CHILD | WS_VISIBLE, 100, 200, 100, 30, ghWnd_Main, NULL, hInstance, NULL);
    		
    		//<----------Made Bigger
    		ghWnd_label = CreateWindowEx(WS_EX_NOPARENTNOTIFY, "Static", NULL, WS_CHILD | SS_REALSIZEIMAGE, 50, 10, 200, 50, ghWnd_Main, NULL, hInstance, NULL);
    
    		//<----------Added To Be Used For A Test
    		ghWnd_Hello = CreateWindow("Button", "BitBlt", WS_CHILD | WS_VISIBLE, 100, 230, 100, 30, ghWnd_Main, NULL, hInstance, NULL);
    
    
    		ShowWindow(ghWnd_Main, nCmdShow); // Show using the specific show style
    		ShowWindow(ghWnd_label, nCmdShow); //<----------Added
    	}
    
    	/////////////////////////
    	// Handle message loop //
    	/////////////////////////
    	MSG msg;
    	while(GetMessage(&msg, NULL, 0, 0)) {
    		TranslateMessage(&msg); // Translate keycode messages
    		DispatchMessage(&msg); // Send to the window
    	}
    
    	UnregisterClass("TESTCLASS", hInstance); // Unregister our window class
    	return msg.wParam; // msg.wParam contains the code passed to PostQuitMessage()
    }
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  33. #33
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Bad Me you should change/add

    Code:
    if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == ghWnd_Hello) 
    			{
    				HDC hdc_label;
    				hdc_label = GetDC(ghWnd_label);
    				BitBlt(hdc_label, 0, 0, 200, 50, hdc, 0, 0, SRCCOPY);
    				DeleteDC(hdc_label);
    			}
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  34. #34

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Thats perfect! Thank you so much for all of your help!

    (sorry it took so long )

  35. #35
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    No prob, glad to help, but remember what I said earlier, a BitBlt image will not stay on when the window gets refreshed, unless you make it stay.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


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