Link to home
Start Free TrialLog in
Avatar of Thomas Stockbruegger
Thomas StockbrueggerFlag for Germany

asked on

Would like to move button in a function

Hello, I would like to send the button ID to a function (where I move the button).
The moving code works just fine, but I do not know how to submit the value/ID to the function.
It will not work as an int or as an CString.
Please help. 500 points with a solution.

Best regards,
Thomas




Resource.h
.
.
.
#define IDB_BITMAP_SPEICHERN_BUTTON_ANGEBOT 378





BOOL CAngebot_Dialog::OnInitDialog()
{
        .
        .
        .
     int Button_ID=0;
     Button_ID=378;
    //==========================================
    Verschiebe_Button_bei_groesser_Aufloesung(Button_ID);
   //==========================================







void CAngebot_Dialog::Verschiebe_Button_bei_groesser_Aufloesung(int Button_ID)
{
                //Maße von Exitbutton ermitteln
             CRect CBtnRect;
             CButton *pButton =(CButton*) GetDlgItem(Button_ID);
             
             pButton->GetWindowRect(CBtnRect);

             //ermittle Koordinaten bzw. Maße umwandeln
              ScreenToClient(&CBtnRect);
              int nButtonBreite   =CBtnRect.Width();    
              int nButtonHoehe    =CBtnRect.Height();  
              int nButtonPosLinks =CBtnRect.left;      
              int nButtonPosOben  =CBtnRect.top;      

              //Exitbutton verschieben
              pButton->MoveWindow(nButtonPosLinks+25,nButtonPosOben+25,nButtonBreite,nButtonHoehe,TRUE);

}
ASKER CERTIFIED SOLUTION
Avatar of siki
siki
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sarabande
It will not work as an int or as an CString.
can you describe what you mean by 'it will not work'?

did you get a compiler error?
check the prototype of your new function in the header file.

did you get a crash?
check the pButton whether it is not NULL before calling GetWindowRect.
if it is null, check the Dialog resource whether the button was included and has the correct ID.

did you call CDialog::OnInitDialog() before moving the button?

Sara
Avatar of Thomas Stockbruegger

ASKER

Thank you for your help. I am sorry it was just my error.
I did this earlier and it would not work, I got a crash.
 Verschiebe_Button_bei_groesser_Aufloesung(IDB_BITMAP_SPEICHERN_BUTTON_ANGEBOT);

Now I know what I did wrong.  That was stupid from me.
IDB_BITMAP_SPEICHERN_BUTTON_ANGEBOT this is not a button, it is a bitmap. I have so many button and bitmaps that I choose the wrong ID.

With a real button it works just fine.