|
-
Mar 6th, 2001, 06:18 PM
#32
Frenzied Member
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

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|