Hi,
I try to set focus by object ID, but I haven't got any idea. I have got cell 3x3 of CEdit and I want do something like Excel ... by arrows change focus ...
Thanks for your ideas ...
Stanley
Hi,
I try to set focus by object ID, but I haven't got any idea. I have got cell 3x3 of CEdit and I want do something like Excel ... by arrows change focus ...
Thanks for your ideas ...
Stanley
and what does it have to do with C++...
for example I have:
it isnīt function I only want show what it should do ...Code:... #define ID_EDIT1 101 #define ID_EDIT2 102 #define ID_EDIT3 103 #define ID_EDIT4 104 #define ID_EDIT5 105 #define ID_EDIT6 106 #define ID_EDIT7 107 #define ID_EDIT8 108 #define ID_EDIT9 109 ... OnKeyDown(UINT nChar) { if(nChar == "KeyDown")FocusObject += 3; if(nChar == "KeyUp")FocusObject -= 3; if(nChar == "KeyRight")FocusObject += 1; if(nChar == "KeyLeft")FocusObject -= 1; // in FocusObject is for example 106 and I need set focus to ID_EDIT6 } ...
Ah I see. My bad. Didn't know it's MFC.
Can't help you, though. I don't know MFC.
I use a custom Listview in report mode for this type of control.
Or draw the text on a DC and use hot spots and mouse clicks (ie for tic tac toe).
SetFocus() will change the focus to the required edit.
In my example FocusEdit is a member to hold the current selected edit's ID (not offset from 101).
Code:OnKeyDown(UINT nChar) { if(nChar == "KeyDown")FocusObject += 3; if(nChar == "KeyUp")FocusObject -= 3; if(nChar == "KeyRight")FocusObject += 1; if(nChar == "KeyLeft")FocusObject -= 1; //also needs test for invalid (?) presses ie Left Arrow in 101, 104, 107 //validation for ID (please test as not checked) if(FocusObject>ID_EDIT9) { FocusObject=ID_EDIT1+(FocusOject-(ID_EDIT9+1)); } //EDIT Add low value test, I am thinking switch / case instead of the 'if's // in FocusObject is for example 106 and I need set focus to ID_EDIT6 CEdit *pEdit=NULL; pEdit=(CEdit*)GetDlgItem(FocusObject); if(pEdit)//no error { pEdit->SetFocus(); } //handle error }
Last edited by novacain; 06-30-2008 at 12:20 AM.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
Thanks, it works ...