Thomas Stockbruegger
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_BUTTO N_ANGEBOT 378
BOOL CAngebot_Dialog::OnInitDia log()
{
.
.
.
int Button_ID=0;
Button_ID=378;
//======================== ========== ========
Verschiebe_Button_bei_groe sser_Auflo esung(Butt on_ID);
//======================== ========== ========
void CAngebot_Dialog::Verschieb e_Button_b ei_groesse r_Aufloesu ng(int Button_ID)
{
//Maße von Exitbutton ermitteln
CRect CBtnRect;
CButton *pButton =(CButton*) GetDlgItem(Button_ID);
pButton->GetWindowRect(CBt nRect);
//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(nButto nPosLinks+ 25,nButton PosOben+25 ,nButtonBr eite,nButt onHoehe,TR UE);
}
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_BUTTO
BOOL CAngebot_Dialog::OnInitDia
{
.
.
.
int Button_ID=0;
Button_ID=378;
//========================
Verschiebe_Button_bei_groe
//========================
void CAngebot_Dialog::Verschieb
{
//Maße von Exitbutton ermitteln
CRect CBtnRect;
CButton *pButton =(CButton*) GetDlgItem(Button_ID);
pButton->GetWindowRect(CBt
//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(nButto
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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_groe sser_Auflo esung(IDB_ BITMAP_SPE ICHERN_BUT TON_ANGEBO T);
Now I know what I did wrong. That was stupid from me.
IDB_BITMAP_SPEICHERN_BUTTO N_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.
I did this earlier and it would not work, I got a crash.
Verschiebe_Button_bei_groe
Now I know what I did wrong. That was stupid from me.
IDB_BITMAP_SPEICHERN_BUTTO
With a real button it works just fine.
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