|
Yeah, I have a tendency to go crazy on making statements smaller, at the expense of readability. I kind of miss being able to do that in c#, there's no implicit conversion to bool a lot of the time.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
D'oh, thanks a lot.
I was absolutely sure C++ allowes that kind of evaluation I used in my original if-statement, but the results were somewhat unpredictable
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I think it this is happening.
(!(bMouse4Old == (bMouse4 == false)))
with == being processed like = as in
x=y=0;
I hope there isn't a lot of this stuff.
-Andy Brummer
|
|
|
|
|
In the Table "C++ Operator Precedence and Associativity",
= "Assignment" "Right to left"
== "Equality" "Left to right"
(A == B == C)
stands for
((A == B) == C)
X = Y = Z;
stands for
X = (Y = Z);
<b>Maxwell Chen</b>
|
|
|
|
|
Totally offtopic, but I have two more questions:
2) My program uses DirectInput to capture the state of the 4th and 5th mousebutton (DIMOUSESTATE2).
Depending on the state I call SendInput to map the mousebuttons to a key, thus being able to play games with 5 buttons by emulating a keypress. is there an easier way to map a mousebutton to a key? I find the SendInput way quite uncomfortable, though it works.
2) I need to save a single integer into a config file, no more, no less. Hence my program consists only of a single exe-file, I don't want to create a config file just to save the integer. Is there another way to save the integer? (I don't want to save into the registry, because when the user deletes my exe the value would stay in the registry having no function anymore)
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Regarding item 2:
a file or the registry is your only option as far as I can see. I doubt a single digit in the registry is going to make much difference, and that's what uninstall programs are for.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Well, you already got your answer but I will attempt to explain what's happening with your code. At first bMouse4 == false returns "true" since bMouse4 is false. Afterwards, you have bMouse4Old == true. Now the statement becomes:
if( !false )
SendInput(...)
Therefore if bMouse4Old and bMouse4 are both false then SendInput() will be called.
// Afterall, I realized that even my comment lines have bugs
If the sun were to blow up, it would take us 7-8 minutes to realize it.
|
|
|
|
|
1) Ragarding to your if block, it does work well with VC++ 6.0 on my machine. What I tested is as the below:
bool bMouse4Old = false;
bool bMouse4 = false;
if(!(bMouse4Old == bMouse4 == false))
std::cout << "SendInput(...)\n";
2) According to the Table "C++ Operator Precedence and Associativity" in MSDN,
== "Equality" "Left to right"
Thus, your code can be translated as:
a) if(!( (bMouse4Old /*false*/ == bMouse4 /*false*/) == false)) // then
b) if(!(true == false)) // then
c) if(!false) // then
d) if(true)
<b>Maxwell Chen</b>
|
|
|
|
|
I have a CListCtrl in a CFormView that represents objects. In the form view I have controls that represent data of the selected object.
When a new object is selected in the list, I need to:
1. validate the data
2. if the data is not valid, keep the original list item selected, and do not select the new item.
3. if the data is valid, then show the data of the new object.
I have added OnItemchangingX and OnItemchangedX for the list control to my form view class.
void CAddonView::OnItemchangingX(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
BOOL bValidateSuccessful = validate();
if (!bValidateSuccessful) {
--------------------------------------------------
...what do I do here to keep the old item selected
...and keep the new one from getting selected?
--------------------------------------------------
}
}
void CAddonView::OnItemchangedX(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int iSelItem = m_listAP.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
if (iSelItem != -1 && pNMListView->uNewState & LVIS_SELECTED)
{
...load data of newly selected item...
}
} What do I need to do to keep the old selection if the validation fails?
Thanks.
--
David Hisel
Internet Business Software
|
|
|
|
|
Most likely not the best solution, but I had a similar
problem, and I just used a static variable to keep track
of the previously selected item, and after I processed what
I wanted, I updated it (the variable, that is) with the new
selection.
Sp+
|
|
|
|
|
I have a .dll with "C" functions that I need to call. One of the functions returns a simple struct(2 doubles)
If I try to use DllImport like this:
[ DllImport("somedll.dll]<br />
SomeStruct1 f1(SomeStruct1 *pS);
I get compiler error C3385 "a function that has a DllImport Custom Attribute cannot return an instance of a class"
How can I import a function from a DLL that returns a struct???
Thanks a ton,
Sam
|
|
|
|
|
I have ever thought, that exported functions cannot return a struct or class. Try to pass the return value by pointer: void f1(SomeStruct1 *pS, SomeStruct1 *pReturn);
Robert-Antonio
"Love without sex is like a fish without antlers"
|
|
|
|
|
Is it possible to lock toolbars in place, a bit like what IE is doing when checking the "lock the toolbars" in the view mene, without having to chant incantations and lighting incense to the god of win32 API ?
I think that I need to change the style, and maybe have to remove the gripper.
Any info ?
Thanks ...
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
If this is an MFC application, not calling EnableDocking() and DockControlBar() in the mainframe's OnCreate() method will keep the toolbar from docking (i.e., locked).
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
How do you permit scientific notation to be accepted in an edit box? Currently, I have it set to accept a float, but need it to accept scientific notation. Then I will need to pass this value to a register on a PCI board.
Thanks for any assistance.
Walt
|
|
|
|
|
Walt_S wrote:
How do you permit scientific notation to be accepted in an edit box? Currently, I have it set to accept a float, but need it to accept scientific notation.
By default, an edit box can accept any charcter that can be typed, and most that can be pasted. If you are wanting to limit the input to only scientific characterfs, you'll need a formatted edit control. Check here for ideas.
Walt_S wrote:
Then I will need to pass this value to a register on a PCI board.
What format (e.g., long, double, char) is the register expecting the number in?
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
The register is expecting a double.
Thank you for the info.
Walt
|
|
|
|
|
Hello people,
I have an MDI application, and i want to change the menu of the child frames.....but the GetMenu command gives me the pointer to the Menu of the Main Frame.....on the other hand i want to change the Menu of My childFrames ...please help ...tell me how to access it..and then modify it ...thank you..
|
|
|
|
|
From MSDN Library:
An MDI child window does not have a menu bar of its own, but instead shares the menu of the MDI frame window. The framework automatically changes the MDI frame menu to represent the currently active MDI child window.
This explicitly states that by using base-MFC, you cannot have a MDI Child window with a real menu bar, but the menu associated with the child window is automatically replacing the frame window's menu when you give focus to a child frame.
You need to rebuild some basic functionality automatically provided to you by the framework if you want to achieve a child frame with a menu. Firstly, you need to derive a new class from CFrameWnd. This will be your child frame class. Give it a ON_WM_CREATE handler and force it to load a menu by explicitly creating a CMenu object and calling CWnd::SetMenu. Frame windows support menus, so the call is valid. After this, you need to create a view and bind it to the child frame.
Lastly, you must create a handler for command ID_FILE_NEW on your parent frame window. Here, you must manually create a child frame window and show it.
In order to get you into a good start, create a new MDI project and remove the tick 'Doc/View arhitecture'. Examining the generated code gives you an idea of the processes required to create non-doc/view MDI applications.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Ok first of thanks for answering my question. You said that MDI child doesnt have its own menu but the framework automatically changes MDi frame to represent the active MDI child window...hmm well ok...
I dont want to create a menu for the child window then , all i want to do is to be able to make changes to it..how to do that...actually i want to add a feature to my menu that it displays all the currently open documents in the menu(i know this thing is already built in when u make the MDi or SDI app, but i want to make my own.
To do this i need to be able to change the menu that is displayed when child is active...plz help me with this thank you..
|
|
|
|
|
As the framework alters the frame window's menu when a child gets activated, it is possible to access this menu through the CWnd::GetMenu routine. Then, you can alter the menu using CMenu operations. Although the menu resides on the parent frame's menu bar, nothing prevents you from altering it in the standard way. If you want to be certain, call GetMenu for the child frame. This, for certain, should return the child frame's menu that is currently visible on the parent frame's menu bar.
Furthermore, when a child window is activated (it's title bar is clicked), a Windows message WM_MDIACTIVATE is generated and sent to the frame that is being activated as well as to the frame that is being deactivated. That is, two messages in total. For the child frame class, the default handler of CMDIFrameWnd answers to this message by modifying the parent's menu. You could add to this, by first calling the base class (to modify the menu), then use CWnd::GetMenu to return the menu and do additional modifications to it.
This way, you would only need to write the basic layout of the menu as a resource, then modify it on-the-fly as required.
There is a function called OnMDIActivate implemented in the CWnd class. If I remember correctly, the same function is declared in the header file that defined CMDIChildWnd , and it is declared virtual in there. If this is correct, you can override it straight through in your derived class to implement the above idea. I am not completely sure whether this approach will work, but it's at least something concrete you could try.
Naturally, everytime the designated child frame is active, you can use CWnd::GetMenu to modify the currently active menu, thus adding the list of currently open documents. However, I am not certain if these changes last over frame deactivation/re-activation..
Hope this will help..
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hello,
I've encountered a strange behaviour of a toolbar (using CToolBar). I add programatically buttons to it from a modal dialog. The strange part is, that when I call RecalcLayout, the toolbar resizes (adds the buttons) but does not display correctly the associated bitmaps and does not manage their state immediatelly. If i manually flow or dock the toolbar, I get the command handling (i.e. the bitmaps appear correctly, and the buttons are clickable and not disabled). If I don't manually dock or flow the toolbar, I get only a resized toolbar without any bitmaps and with disabled buttons. My question here is, what am I missing, and what am I doing wrong.
Greetings,
Deian
|
|
|
|
|
You have to programmatically dock and re-float the toolbar to get it to accept changes in size; at least that has been my experience.
|
|
|
|
|
Thanks for the idea, I've tried this, but I'm making changes from a modal dialog, which is called by the frame. If I try to dock and refloat the toolbar it crashes. May be making the dialog no-modal will work fine, or will have to handle this after the dialog is closed. It's not a clean solution
Thanks for your time!
|
|
|
|
|
GDI+ looks good, sounds good, smells good, but how can i have it on my VS ver 6.
"When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)
|
|
|
|
|