Bonjour à tous,
je sais qu'il existe déjà des posts sur ce sujet. D'ailleurs mon code s'en inspire.
Mais voila, malgrè la lecture de ceux ci je n'arrive toujours pas à faire afficher une image (bitmap) sur mon bouton
J'ai essayé plusieurs méthodes mais aucune ne semble fonctionner.
En fait SendMessage ou SendDlgItemMessage renvoi toujours NULL. Du coup je n'arrive pas à avoir mon image.
La fonction LoadBitmap semble retourner un handle correct dou coup je bloque complètement
Je travail avec Dev-C++ 4.9.9.2 sous Windows 2000 Pro sp4.
Mon fichier ressource à était crée via ResED
J'ai posté les 3 trois fichiers de mon projet de test.
Si quelqu'un pouvais me dépanner, se serait vraiment cool.
Merci d'avance pour votre aide.
test_dlg.h :
-------------
#define IDD_DLG_MAIN 1000
#define IDC_BTN_MYBITMAP 1001
#define MY_BITMAP 10001
/*************************************************************************/
test_dlg.rc :
-------------
#define IDD_DLG_MAIN 1000
#define IDC_BTN_MYBITMAP 1001
#define MY_BITMAP 10001
IDD_DLG_MAIN DIALOGEX 6,5,200,121
CAPTION "Test Bitmap"
FONT 8,"MS Sans Serif"
STYLE 0x10CA0800
EXSTYLE 0x00000000
BEGIN
CONTROL "",IDC_BTN_MYBITMAP,"Button",0x50018000,28,5,130,105,0x00000000
END
MY_BITMAP BITMAP DISCARDABLE "MyBitmap.bmp"
/*************************************************************************/
main.cpp :
-------------
#include <windows.h>
#include <stdio.h>
#include "test_dlg.h"
// prototype for the dialog box function
static BOOL CALLBACK DialogFunc(HWND, UINT, WPARAM, LPARAM);
// Globals variables
HINSTANCE g_hInst;
HWND g_hDlg;
char s[255];
// Main function
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
g_hInst = hThisInstance;
DialogBoxParam(hThisInstance, MAKEINTRESOURCE(IDD_DLG_MAIN), NULL, (DLGPROC) DialogFunc, 0);
ExitProcess(0);
}
// Initialize the main dialog box
int InitializeApp(HWND hDlg,WPARAM wParam, LPARAM lParam)
{
g_hDlg = hDlg;
long res;
HWND g_Bt;
g_Bt = GetDlgItem(hDlg, IDC_BTN_MYBITMAP);
wsprintf(s, "g_Bt : %d", g_Bt); MessageBox(0,s,0,0);
HBITMAP g_Img;
g_Img = LoadBitmap(g_hInst, MAKEINTRESOURCE(MY_BITMAP));
wsprintf(s, "g_Img : %lu", g_Img); MessageBox(0,s,0,0);
res = SendDlgItemMessage(hDlg, IDC_BTN_MYBITMAP, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g_Img);
// res = SendMessage(g_Bt, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g_Img);
wsprintf(s, "res : %lu", res); MessageBox(0,s,0,0);
return TRUE;
}
// Callback function for the main dialog box
BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
InitializeApp(hwndDlg,wParam,lParam);
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, FALSE);
return TRUE;
}
return FALSE;
}
Afficher la suite