|
-
May 9th, 2006, 12:43 AM
#1
Bitmap change on button press..
I wrote this as a lead up to something I need to develop further down the track..
All I want to do at the moment is change the bitmap image when the button is pressed!
It is not working this way, and I am stuck for ideas ATM!
Can anyone tell me why it is not working correctly..
Cheers
Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>
#include <iostream>
#include "Resource.h"
using namespace std;
#pragma comment(lib, "comctl32.lib")
INT_PTR CALLBACK DlgProc( HWND hwnd , UINT msg , WPARAM wparam , LPARAM lparam)
{
HWND Pic = GetDlgItem(hwnd, IDC_GREEN);
HWND Button = GetDlgItem(hwnd, IDC_BUTTON1);
switch(msg)
{
case WM_INITDIALOG:
{
static HBITMAP hbmp;
hbmp = (HBITMAP)LoadImage(0, MAKEINTRESOURCE(IDB_GREEN), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
SendMessage(Pic, BM_SETIMAGE, IDC_GREEN, (LPARAM)hbmp);
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(0)));
}
break;
case WM_COMMAND:
switch(HIWORD(wparam))
{
case BN_CLICKED:
if(LOWORD(wparam) == IDC_BUTTON1)
{
//MessageBox(hwnd, "check for Message", 0 ,0);
static HBITMAP hbmp = (HBITMAP)LoadImage(0, MAKEINTRESOURCE(IDB_RED), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
SendMessage(Pic, BM_SETIMAGE, IDC_GREEN, (LPARAM)hbmp);
}
break;
}
break;
case WM_CLOSE:
{
PostQuitMessage(0);
}
break;
}
return false;
}
INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance,
LPSTR lpcmdline, int ncmdshow)
{
InitCommonControls();
DialogBox(hinstance, MAKEINTRESOURCE(IDD_MAIN), 0, DlgProc);
return 0;
}
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
|