Mi scompaiono le bitmap OBM cliccandoci sopra

di il
2 risposte

Mi scompaiono le bitmap OBM cliccandoci sopra

Salve, ho realizzato un programma in C che utilizza le funzioni API e che dovrebbe mostrare un dialogo dove digitando su 4 possibili pushbotton con stile bitmap OBM_UPARROW, OBM_DNARROW, OBM_RGARROW, OBM_LFARROW, viene spostato un controllo static verso l' alto, il basso, destra, sinistra. Lo static viene spostato, ma cliccando sulle bitmap OBM esse scompaiono. Il programma l' ho riguardato più volte e non capisco perchè scompaiono e dove sbaglio.

Il file.cpp del programma è il seguente:
#define STRICT
#define WIN32_LEAN_AND_MEAN
#define OEMRESOURSE
#include <windows.h>
#include "risorse1.h"

BOOL CALLBACK spostamento_static_desiderato(HWND hwnd_static, int dx, int dy)
{
  WINDOWPLACEMENT wp;
  ZeroMemory(&wp, sizeof(wp));
  wp.length= sizeof(wp);
  GetWindowPlacement(hwnd_static, &wp);
  wp.rcNormalPosition.left= wp.rcNormalPosition.left +dx;
  wp.rcNormalPosition.right= wp.rcNormalPosition.right +dx;
  wp.rcNormalPosition.top= wp.rcNormalPosition.top +dy;
  wp.rcNormalPosition.bottom= wp.rcNormalPosition.bottom +dy;
  return SetWindowPlacement(hwnd_static, &wp);
 }


BOOL CALLBACK sposta_static(HWND hwnddlg, UINT umsg, WPARAM wparam, LPARAM lparam)
{
  
  HWND hwnd_button1= GetDlgItem(hwnddlg, IDC_BUTTON1);
  HBITMAP hwnd_bitmap1= LoadBitmap(0, MAKEINTRESOURCE(OBM_LFARROW));
  // OBM_LFARROW indica l'identificatore del bitmap freccia a sinistra
  SendMessage(hwnd_button1, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hwnd_bitmap1);

  HWND hwnd_button2= GetDlgItem(hwnddlg, IDC_BUTTON2);
  HBITMAP hwnd_bitmap2= LoadBitmap(0, MAKEINTRESOURCE(OBM_RGARROW));
  // OBM_RGARROW indica l'identificatore del bitmap freccia a destra
  SendMessage(hwnd_button2, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hwnd_bitmap2);

  HWND hwnd_button3= GetDlgItem(hwnddlg, IDC_BUTTON3);
  HBITMAP hwnd_bitmap3= LoadBitmap(0, MAKEINTRESOURCE (OBM_UPARROW));
  // OBM_UPARROW indica l'identificatore del bitmap freccia in alto
  SendMessage(hwnd_button3, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hwnd_bitmap3);

  HWND hwnd_button4= GetDlgItem(hwnddlg, IDC_BUTTON4);
  HBITMAP hwnd_bitmap4= LoadBitmap(0, MAKEINTRESOURCE(OBM_DNARROW));
  // OBM_DNARROW indica l'identificatore del bitmap freccia in basso
  SendMessage(hwnd_button4, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hwnd_bitmap4);

  if(umsg==WM_CLOSE)
   {
     EndDialog(hwnddlg,0);
     return TRUE;
    }
     if(umsg==WM_COMMAND)
      {
        int spostamento=5;
        int id_button=LOWORD(wparam);
        HWND hwnd_static= GetDlgItem(hwnddlg, IDC_STATIC);

        if(id_button==IDC_BUTTON1)
         return spostamento_static_desiderato(hwnd_static, -spostamento, 0);

        if(id_button==IDC_BUTTON2)
         return spostamento_static_desiderato(hwnd_static, +spostamento, 0);

        if(id_button==IDC_BUTTON3)
         return spostamento_static_desiderato(hwnd_static, 0, -spostamento);

        if(id_button==IDC_BUTTON4)
         return spostamento_static_desiderato(hwnd_static, 0, +spostamento);
        }
      return FALSE;
    }


int WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
  DialogBoxParam(0,"IDD_DIALOG8",0,sposta_static,0);
  return 0;
}
L' header file risorse1.h è il seguente:
#define IDC_STATIC 101
#define IDC_BUTTON1 102
#define IDC_BUTTON2 103
#define IDC_BUTTON3 104
#define IDC_BUTTON4 105
Il resource file IDD_DIALOG8.rc risulta essere:
#define OEMRESOURSE
#include <windows.h>
#include "risorse1.h"

IDD_DIALOG8 DIALOG DISCARDABLE 0,0,200,134
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialogo (finestra) per spostare uno static con bitmap"
FONT 8, "MS Sans Serif"
BEGIN
CONTROL "Static da spostare", IDC_STATIC,  "STATIC", SS_CENTER | WS_BORDER, 40,58,70,12
CONTROL "", IDC_BUTTON1, "BUTTON", BS_PUSHBUTTON | BS_BITMAP | BS_NOTIFY, 100,30,10,10
CONTROL "", IDC_BUTTON2, "BUTTON", BS_PUSHBUTTON | BS_BITMAP | BS_NOTIFY, 150,30,10,10
CONTROL "", IDC_BUTTON3, "BUTTON", BS_PUSHBUTTON | BS_BITMAP | BS_NOTIFY, 125,10,10,10
CONTROL "", IDC_BUTTON4, "BUTTON", BS_PUSHBUTTON | BS_BITMAP | BS_NOTIFY, 125,50,10,10
END

Ringrazio per l' aiuto.
Matteo

2 Risposte

  • Re: Mi scompaiono le bitmap OBM cliccandoci sopra

    Devi gestire il WM_PAINT.
  • Re: Mi scompaiono le bitmap OBM cliccandoci sopra

    Ho cercato di gestire WM_PAINT, utilizzando le funzioni UpdateWindow e WindowProc modificando il file .cpp, ma continuano a scomparirmi le bitmap cliccandoci sopra. Non capisco perchè facendo queste modifiche ancora non funzioni.

    Il file .cpp modificato è il seguente:
    #define STRICT
    #define WIN32_LEAN_AND_MEAN
    #define OEMRESOURSE
    #include <windows.h>
    #include "risorse1.h"
    
    LRESULT CALLBACK WindowProc(HWND hwnddlg, UINT umsg, WPARAM wParam, LPARAM lParam)
    {
       if(umsg==WM_PAINT)
        {
         HWND hwnd_button1= GetDlgItem(hwnddlg, IDC_BUTTON1);
         HBITMAP hwnd_bitmap1= LoadBitmap(0, MAKEINTRESOURCE(OBM_LFARROW));
         // OBM_LFARROW indica l'identificatore del bitmap freccia a sinistra
         SendMessage(hwnd_button1, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hwnd_bitmap1);
    
         HWND hwnd_button2= GetDlgItem(hwnddlg, IDC_BUTTON2);
         HBITMAP hwnd_bitmap2= LoadBitmap(0, MAKEINTRESOURCE(OBM_RGARROW));
         // OBM_RGARROW indica l'identificatore del bitmap freccia a destra
         SendMessage(hwnd_button2, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hwnd_bitmap2);
    
         HWND hwnd_button3= GetDlgItem(hwnddlg, IDC_BUTTON3);
         HBITMAP hwnd_bitmap3= LoadBitmap(0, MAKEINTRESOURCE (OBM_UPARROW));
         // OBM_UPARROW indica l'identificatore del bitmap freccia in alto
         SendMessage(hwnd_button3, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hwnd_bitmap3);
    
         HWND hwnd_button4= GetDlgItem(hwnddlg, IDC_BUTTON4);
         HBITMAP hwnd_bitmap4= LoadBitmap(0, MAKEINTRESOURCE(OBM_DNARROW));
         // OBM_DNARROW indica l'identificatore del bitmap freccia in basso
         SendMessage(hwnd_button4, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hwnd_bitmap4);
        }
        return FALSE;
    }
    
    BOOL CALLBACK spostamento_static_desiderato(HWND hwnd_static, int dx, int dy)
    {
      WINDOWPLACEMENT wp;
      ZeroMemory(&wp, sizeof(wp));
      wp.length= sizeof(wp);
      GetWindowPlacement(hwnd_static, &wp);
      wp.rcNormalPosition.left= wp.rcNormalPosition.left +dx;
      wp.rcNormalPosition.right= wp.rcNormalPosition.right +dx;
      wp.rcNormalPosition.top= wp.rcNormalPosition.top +dy;
      wp.rcNormalPosition.bottom= wp.rcNormalPosition.bottom +dy;
      return SetWindowPlacement(hwnd_static, &wp);
     }
    
    
    BOOL CALLBACK sposta_static(HWND hwnddlg, UINT umsg, WPARAM wparam, LPARAM lparam)
    {
      HWND hwnd_button1= GetDlgItem(hwnddlg, IDC_BUTTON1);
      HBITMAP hwnd_bitmap1= LoadBitmap(0, MAKEINTRESOURCE(OBM_LFARROW));
      // OBM_LFARROW indica l'identificatore del bitmap freccia a sinistra
      SendMessage(hwnd_button1, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hwnd_bitmap1);
    
      HWND hwnd_button2= GetDlgItem(hwnddlg, IDC_BUTTON2);
      HBITMAP hwnd_bitmap2= LoadBitmap(0, MAKEINTRESOURCE(OBM_RGARROW));
      // OBM_RGARROW indica l'identificatore del bitmap freccia a destra
      SendMessage(hwnd_button2, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hwnd_bitmap2);
    
      HWND hwnd_button3= GetDlgItem(hwnddlg, IDC_BUTTON3);
      HBITMAP hwnd_bitmap3= LoadBitmap(0, MAKEINTRESOURCE (OBM_UPARROW));
      // OBM_UPARROW indica l'identificatore del bitmap freccia in alto
      SendMessage(hwnd_button3, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hwnd_bitmap3);
    
      HWND hwnd_button4= GetDlgItem(hwnddlg, IDC_BUTTON4);
      HBITMAP hwnd_bitmap4= LoadBitmap(0, MAKEINTRESOURCE(OBM_DNARROW));
      // OBM_DNARROW indica l'identificatore del bitmap freccia in basso
      SendMessage(hwnd_button4, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hwnd_bitmap4);
    
       if(umsg==WM_CLOSE)
       {
         EndDialog(hwnddlg,0);
         return TRUE;
        }
    
         if(umsg==WM_COMMAND)
          {
            UpdateWindow(hwnddlg);
            WindowProc(hwnddlg, umsg, wparam, lparam);
            int spostamento=5;
            int id_button=LOWORD(wparam);
            HWND hwnd_static= GetDlgItem(hwnddlg, IDC_STATIC);
    
            if(id_button==IDC_BUTTON1)
              return spostamento_static_desiderato(hwnd_static, -spostamento, 0);
    
            if(id_button==IDC_BUTTON2)
              return spostamento_static_desiderato(hwnd_static, +spostamento, 0);
    
            if(id_button==IDC_BUTTON3)
              return spostamento_static_desiderato(hwnd_static, 0, -spostamento);
    
            if(id_button==IDC_BUTTON4)
              return spostamento_static_desiderato(hwnd_static, 0, +spostamento);
            }
          return FALSE;
        }
    
    int WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
    {
      DialogBoxParam(0,"IDD_DIALOG8",0,sposta_static,0);
      return 0;
    }
     
Devi accedere o registrarti per scrivere nel forum
2 risposte