|
You can detect the font size use the following:
CDC ScreenDC;
ScreenDC.CreateIC(_T("DISPLAY"), NULL, NULL, NULL);
int nLogDPIX = ScreenDC.GetDeviceCaps(LOGPIXELSX),
nLogDPIY = ScreenDC.GetDeviceCaps(LOGPIXELSY);
ScreenDC.DeleteDC();
if(nLogDPIX == 120 && nLogDPIY == 120) { // 120 DPI, Large Fonts
}
else { // 96 DPI, Small Fonts
}
|
|
|
|
|
Yet Another List Control Question
i'm doing a subitem edit on a report-style list control. when the user clicks on a subitem, i put an edit control on top of the list control and the user deposits (types) his junk.
the problem is that the list control holds onto the mouse - you can't mouse-select anything in the edit control. so, i came up with two choices:
1. do a SetCapture/ReleaseCapture thing for the edit control. SetCapture when editing starts, then Release when it loses focus or the user hits Enter. i think this is overkill.
2. disable the list control while the edit control is up. this is ugly, since the list control goes gray.
so, my questions are:
1. if i do #2, is there a good way to control the disabled appearance (maybe just the background color?) or the list control, without doing an owner drawn control?
2. is there another way to make this work?
this is on an Explorer context menu extension, so i don't want to use a full-blown grid control.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
Chris L
This is not an answer to your question. But I am amazed at your ability to create all kinds of nifty custom controls. That really is your speciality.
I must say that of all the custom control stuff on CP yours is the best in my opinion [though I am sorta biased by the fact that I don't think much of those fancy buttons and menus]. I always feel that having a multi colored tooltip or a super-fancy button isn't as useful as having a control that actually does sosme stuff. Like a font selectiopn combo for example which is a lot lot more useful than say a combo box that looks like it walked out of cartoon network.
I raise my hat to you Losinger
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
thanks man.
sadly, i feel that the Clean UI Purist is going the way of the Command Line Purist.
Flash is what the kiddies like
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
Chris, it's late, so i may have read this totally wrong, but how about just doing a ReleaseCapture() on the list control prior to displaying the edit control? I'm assuming you're doing this in response to NM_CLICK and not LVN_BEGINLABELEDIT to make it obvious that the cell is editable (not requiring the user to double-click).
Another possible solution, one that i've used and works very nicely (although it takes a bit more effort) is not to wait for the click at all, but instead to float the edit control as soon as the user moves the mouse cursor over the cell. This lets the edit control behave exactly as it would be expected to, without any subclassing.
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
how does this handle mouse selection of text in the edit control?
i think if you have full-row select enabled, the list control eats all the mouse clicks somehow.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
Chris Losinger wrote:
i think if you have full-row select enabled, the list control eats all the mouse clicks somehow.
??? I stopped and did a quick test app, the list control doesn't seem to be doing anything that nasty... You're using an edit control which is a child of the list control, right?
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
I do the same in many list controls in my apps. When the user double-clicks an item I identift it and place an edit control on top of the list control. As long as I made sure it was top most, I never had any problem with the mouse not being able to select text etc in it.
m_EditList.SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
This code to edit and item is not within the list control itself, its added into the class that has the lst control
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
Can anyone point me in a direction of how to add Checkboxes into a list box?
|
|
|
|
|
use CCheckListBox
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
Thanks for the pointer there... Now I go on to the otehr problem I always seem to have, The Create function for CCheckListBox has a parameter that calls for a CWnd for a parent window. I am using the Dialog editor and I don't know how to get a CWnd for that, I have the HWND of the dialog box, but not a CWnd.
Can anyone point me to how to get that?
Quinn
|
|
|
|
|
if you're using the dialog editor, you probably don't need to worry about Create.
put a normal list box on your dialog. then using ClassWizard (or ctrl-dbl-click from the resource editor) make a CListBox member variable attached to that control.
then, go into the header file for that dialog and change the CListBox to CCheckListBox.
now you can use that member variable to control your listbox.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
Just curious how do you implementent UNDO/REDO capabilities in your projects...?
Currently i've been thinking about an idea using templates for implemententing this functionality. Basically drop the object into your code and call your funcitons in reverse order for an undo effect and visa-versa, my object takes care of the rest.
However I started looking for examples of UNDO/REDO and found only a few which weren't very helpful, i'd like to know how others have maybe done this in the past and possibly will do so in the future.
So anyways...how do you do it...?
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
1. make an object that can encapsulate a single change from one state in your data to the next. the info in this object has to be complete enough so that you can use it to go from state N to state N-1.
ex. if you're writing a text editor, each keystroke could create a "state" object that holds the newly-entered keystroke and the cursor position. that way, to undo that state, remove the character at the cursor pos.
every action that changes the state of the data must be recorded, and you must be able to apply this info to go back to the previous state. this may mean copying the whole data set, if the changes are drastic (ex. resizing an image requires that you store the whole image, since you can't reconstruct from the new image).
2. make an undo stack and a redo stack
3. at each state changing event, create a new state object that records the changes you are making to the data (keystroke, and cursor pos, for example) and push it onto the undo stack. clear the redo stack.
4. for an undo, pop the top object off the stack and use the info therein to undo the action (ex. remove the char at pos X). push the object you just popped onto the redo stack.
5. for a redo, pop an object off the redo stack, apply its changes in a negative way (whereas the undo stack removed char X at pos Y, the redo stack will add char X at pos Y). push tat object onto the undo stack.
this will do unlimited undo/redo.
see my colorizing text editor for a working example.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
Chris Losinger wrote:
2. make an undo stack and a redo stack
Most seem to be implemented this way, but I found mine was easier using a single stack.
Other than that we're pretty much on the same wave length...I guess UNDO/REDO implementations aren't all that different from each other...
Thanx alot
cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I use a 2-way link list. The current position in the list allows undo/redo actions to be performed. This allows the user to navigate up/down the list at will. If the user has undone an action and then does something different, then the "redo" actions in the list are chopped of and deleted.
I typically used a structure in the list which had the undo/redo action ID, and a void* pointer to the undo/redo data. So your code can place nay kind of info into the list.
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
Roger Allen wrote:
typically used a structure in the list which had the undo/redo action ID, and a void* pointer to the undo/redo data. So your code can place nay kind of info into the list.
That was something I hadn't yet thought of...thats a really good idea actually...
cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I created an app with the MFC AppWizard (in VS.net), and chose the "explorer-style project" option, which creates two panes---a TreeView on the left, and a ListView on the right. The wizard also generates a toolbar with buttons for each of the ListView styles (icon, small icon, list, and report), and the necessary code to change between the styles (via the ModifyStyle function).
Unfortunately, it doesn't work. Oh, the style does get changed. I even get the OnStyleChanged notification. But the ListView doesn't change styles. (I can change the initial style in PreCreateWindow, but I want to do it dynamically.)
The only changes made to the AppWizard-generated application were to add a few items to the listbox (in OnInitialUpdate):
<br />
GetListCtrl().InsertColumn(0, "foo");<br />
GetListCtrl().InsertItem(0, "aaa");<br />
GetListCtrl().InsertItem(1, "bbb");<br />
GetListCtrl().InsertItem(2, "ccc");<br />
What's going on? Am I missing something really obvious?
Thanks,
|
|
|
|
|
DWORD dwStyle;
dwStyle=::GetWindowLong(this->m_hWnd,GWL_STYLE);
dwStyle|=LVS_REPORT;
::SetWindowLong(this->m_hWnd,GWL_STYLE,dwStyle);
To change extent style,use GWL_EXSYTLE.
Hope it helps you!
|
|
|
|
|
Thanks for the reply, but this unfortunately doesn't work. Note that the AppWizard already generated code to change the style (using ModifyStyle). The appropriate style DWORD does get changed.
The problem is that the ListView doesn't respond to changing the style. No matter what I change the style to, I can't effect any changes in the actual control.
Any help is appreciated.
|
|
|
|
|
Got it! Turns out all you need to do is call the base class in your OnStyleChanged handler (or remove it the handler altogether).
It's somewhat strange that the AppWizard-generated code would override OnStyleChanged but not have it call the base class.
|
|
|
|
|
Hi.
I have a MFC application that creates a lot of child windows. I want to get a pointer to CMainFrame from my child windows during their OnCreate handlers. Im doing it like this;
CMainFrame * pMain=(CMainFrame *)AfxGetMainWnd();
The problem is that it only works AFTER all initialization is done, for example when i trigger a handler for a window click.
I REALLY need to get a pointer to CMainFrame during the creating procedure but i cant find a place in CMainframe to insert my child windows "Create" function. Ive tried it on "OnCreateClient" and in "OnCreate", even after the CFrameWnd::OnCreate(...).
Thank you in advance
|
|
|
|
|
use the hwndParent parameter of the supplied CREATESTRUCT structure.
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
The hwndParent parameter isnt pointing to CMainFrame. This is a child CWnd fomr a child window from a CMainFrame's child window. So, its CMainFrame great grandaugther.
Also, is there a way i can declare a global variable pointing to CMainFrame?
|
|
|
|
|
You should be abl to set a global variable to a valid CMainFrame in your CMainFrame::OnCreate() member function as long as it is after the call to the base class's OnCreate() function.
I have not tried this, but here goes:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
g_MyGlobalMainFrame = this;
...
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|