|
Yes, it's possible. Have a look at NM_CUSTOMDRAW notification and TBSTYLE_CUSTOMERASE style.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi there!
I would like to have variables and being able to access them from all the views, the dialogs and menus and stuff.
How can I make this happen?
Should all variables be placed in the Document? the View?
I have a dialogbox that should be able to change a CString, and somewhere on the menu i'd like to just show the CString using a MessageBox()...
How can I access the variables when I'm pressing a button i've created in the Menu? Because then i'm in a function belonging to the CMainFrame-class.
How can I reference a function in forinstance the view when I'm in a function belonging to the CMainFrame?
*sigh*
I'm trying to learn the MS Visual 6.0
argh..
|
|
|
|
|
If your variables relate to the document they should be put there. From there they will be accessible to all views throught the GetDocument() member function.
If the variables are more global of nature and as such not related to a specific document but more to the program instance as such (e.g. username/pw or default file locations)I would put them in the application object (your CWinApp derivative). Then they will be accessible from anywhere in the program through AfxGetApp().
I'd say you put your CString in the document.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Yeah well...
the AfxGetApp() returns a CWinApp.
and my main CWinApp-derived is not the same type as CWinApp.
So when I try to cast the AfxGetApp() to my derived CWinApp-class it simply don't know jack sh*t about any of my variables (they're all 0 even though I have set them otherwise)
Any other suggestions?
Or maybe a workaround?
|
|
|
|
|
Casting the AfxGetApp() to your derived type is a very common, and useful thing to do. You could be having problems with the timing (when and where you are calling AfxGetApp() from). Do you have a sample?
|
|
|
|
|
Hello, the codegurus around the world.;)
Generally speaking, we can use our own class derived from CObject
for the complicated data structure.
This is a powerful approach since we can use serialize function from CObject to save
the data, and this has a flexibilty to access CObject derived class.
So, try to find the sample code for this approach in MSDN help.
At the same time, we can put any variables in our CView class, (not good CDoucument class), but this approach seems not to expand the other project.
But, once we create our own class drived from CObject, we can use the other project easily.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
I did it like this and then it worked.
[CODE]
CFileDownloadApp *argh = NULL;
argh = (CFileDownloadApp *)AfxGetApp();
[/CODE]
when I tried to do something like this:
[BROKEN_CODE]
CFileDownloadApp *argh = (CFileDownloadApp *) AfxGetApp();
[BROKEN_CODE]
it didn't work.
I don't know why tho'!
|
|
|
|
|
in dialog base application i used two modal dialog boxes in first dialog box i using two text boxes where i entered username and password and do modal the second dialog where i want to used this values in second dialog box but when i used getdlgitemtext() and getwindowtext()
from second dialog box it giving the blank values can any one tell me how to get the values of edit box in second dialog box class
Thanks
|
|
|
|
|
Before calling DoModal on the second dialog, get the values from the edits in the first dialog, put them in member variabels of the second dialog class and call DoModal. In the second dialog's OnInitDialog you can the get the values from the member variables.
There is no way to directly get the values from the first dialog while in the second dialog by using GetDlgItemText() and likes - the edit controls are simply not controls of the second dialog!
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I am trying to do the following ! ( SQL Server 2000 )
Open one session of Query Analyser Window
Begin Trans
Update Table1 Set ...
But I don't commit !
Open another session of Query Analyser Window
Select from Table1
Select gets Blocked unless Update is committed !
CAN'T I DO A SELECT WHEN UPDATES/INSERTS Occur ?
I Can do with NOLOCK but we don't want uncommitted data to appear !
I have tried with all transaction isolation levels.
Anyone can help ?
Thanks
Anand
|
|
|
|
|
Why is it so damn hard to find an example of how to change colour on buttons and text???
Is it really that complicated or am I stupid?
I have a Button. I attach a variable to it: m_cButton
I can access lots of member functions and do amazing things to m_cButton BUT WHY is it so hard to make a simple f...ing color change????
|
|
|
|
|
WM_CTLCOLORxxx messages are used to change text/background colors of controls. However, there's a problem with buttons, here's what MSDN says:
The system sends a WM_CTLCOLORBTN message to a button's parent window before drawing a button. This message contains a handle to the button's device context and a handle to the child window. The parent window can use these handles to change the button's text and background colors. However, only owner-drawn buttons respond to the parent window processing the message.
So you'll have to use owner-draw, in this case you have complete control over button appearance - you draw every pixel yourself.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi all,
Surely there has to be someone who knows the internal workings of CSplitterWnd!
There is a bug and a problem in CSplitterWnd which I must get rid off.
Bug:
When having nested splitters and you're clicking a splitter bar WITHOUT miving the bar, the clicked bar jumps 2 pixels to the right (or down depending on splitter orientation).
How to eliminate this bug?!?!!?
Problem:
Having nested splitters again, when I move (see picture) bar1, bar2 automatically gets moved along because bar2 is part of the splitter that is nested inside the splitter of bar1. This implementation works for most of the cases, but how do I make the nested splitter bar (bar2) NOT to move when I move bar1?
Having the orientation below and...
+-------------------------+
| |
| |
| |
+-----parent splitter-----+ <--- bar1
| |
+-----nested splitter-----+ <--- bar2
| |
+-------------------------+
...moving bar1 up a bit I get this orientation...
+-------------------------+
| |
+-----parent splitter-----+ <--- bar1
| |
+-----nested splitter-----+ <--- bar2
| |
| |
| |
+-------------------------+
...where bar2 follows every move of bar1. I don't want this.
Any ideas anyone?
/Tommy
|
|
|
|
|
1) Bug with clicking a splitter bar without moving:
There's no easy solution. The fastest way to solve this problem looks more or less like this
- add BOOL flag, m_bBarDragged, to CSplitterWnd-derived class.
- handle WM_LBUTTONDOWN. Call base class and set m_bBarDragged to FALSE
- handle WM_MOUSEMOVE. Call base class and set m_bBarDragged to TRUE
- handle WM_LBUTTONUP. This is where resizing occurs. If m_bBarDragged is TRUE, user has really moved the bar. Just call the base class in this case. Otherwise, don't call base class, just StopTracking(FALSE). This should restore the splitter internal state without actually moving child panes.
bar2 follows every move of bar1. I don't want this.
The only solution is to override CSplitterWnd::RecalcLayout. Or - nest splitters differently: place child splitter into upper pane of parent splitter.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thx Tomasz,
I tried the bug solution again (have tried it before) just to realize I need to call the base class' onlbuttonup in order to release the tracking bar rectangle... if I don't I'm stuck with it til I maliciously terminate the program. Any ideas on how to go around this?
I've also tried overriding RecalcLayout() but the job seems to be done ion _AfxLayoutRowCols and I can't get to that code anyhow.
What I would like to know, but haven't figured out, is to determine where in the CSplitterWnd code the base splitter tells the nested splitter to move it's bar according to the base splitter bar move. Don't know how to debug it...
/Tommy
|
|
|
|
|
I need to call the base class' onlbuttonup in order to release the tracking bar rectangle
Base class just calls StopTracking(TRUE). As I've posted above: when user didn't move the mouse after pressing button, call StopTracking(FALSE). It will release the tracking rectangle and will not resize panes.
determine where in the CSplitterWnd code the base splitter tells the nested splitter to move it's bar
Nowhere, at least explicitly. When you move the bar, the pane is resized. Child splitter is a pane, it changes its size and gets WM_SIZE. CSplitterWnd::OnSize handler calls RecalcLayout; that's all.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thx a lot Tomasz,
Just realized the first one!
Ok, I'll get my hands dirty in RecalcLayout.
/Tommy
|
|
|
|
|
Tomasz,
Thx, first part of the bug eliminated (when clicking and not moving). But, the bug is still there when clicking AND moving the bar. The bar here jumps off 2 pixels to the right (or down).
Now this can't be THAT easy?!
/Tommy
|
|
|
|
|
So you'll have to dig deep into RecalcLayout.
BTW: Are you a perfectionist yourself or just have a perfectionist boss? Is it really that important?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
It has to be perfect since we're dealing with high res models and 2 pixels do account for a loss of image quality if it gets in the way of the image...
That's why I don't want the bar to jump by itself, mostly because the above and secondly because it's really annoying! If you release the bar tracker then it's supposed to splitt at that exact location, not 2 pixels off... don't you agree...?
|
|
|
|
|
If you release the bar tracker then it's supposed to splitt at that exact location, not 2 pixels off... don't you agree...?
Hmmmm... I would say that most users can't move mouse with pixel or even 2-pixel accuracy. However, I can see that this issue is really important for you
Assuming that you have three-way splitter without scrollbar sharing, you could simply implement resizing 'manually' - create the views inside a frame window, leave some space between them, set the frame class cursor to <-|-> (rotated 90 degrees) and handle mouse messages in the frame window. Enter tracking mode at WM_LBUTTONDOWN, capture the mouse, move your views in WM_MOUSEMOVE, end the sequence with WM_LBUTTONUP. This gives you on-the-fly resizing.
You may find this technique may be easier to implement than fixing CSplitterWnd.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I need help with a CTreeCtrl !!! What am I doing wrong ???
// CMyClass is derived from CTreeView !!!!!
// m_stupidTree is declared in MyClass.h as
// CTreeCtrl *m_stupidTree;
CMyClass::CMyClass()
{
m_stupidTree = new CTreeCtrl;
}
CMyClass::~CMyClass()
{
delete m_stupidTree;
}
CMyClass::OnInitialUpdate()
{
// Some code
m_stupidTree->Create(0, CRect(0,0,0,0), this, 0)
}
void thisfunctiondoesntwork (HTREEITEM hAItem)
{
TVITEM tvItem;
tvItem.hItem = hAItem;
this->GetTreeCtrl().GetItem(&tvitem);
// Do some code
m_stupidTree->InsertItem(&tvinsertplease);
// tvinsertplease is a TV_INSERTSTRUCT inicializated before
}
But I get an assertion failure and I don't know what am I doing wrong !!!! The problem is that when it runs this->GetTreeCtrl().GetItem(&tvitem) the m_stupidTree is lost, and I can no longer see it's value so obviously when I do InsertItem it doesn't exists and crashes !!!!
Can you help me ?????
|
|
|
|
|
Assertion message box tells you where (in which file and line) the problem is. Run your program again and post this information.
BTW, your 'thisfunctiondoesntwork' looks funny. Seems that it's a method of CTreeView-derived class. Why do you need another tree, the 'stupid' one? Are you trying to copy items between two trees?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
When it crashes I see a message box and says it's in file MFC42.dll and then goes to this line:
_AFXCMN_INLINE HTREEITEM CTreeCtrl::InsertItem(LPTVINSERTSTRUCT lpInsertStruct)
{ ASSERT(::IsWindow(m_hWnd)); return (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct); }
And yes, you guessed correctly why I am using two trees
|
|
|
|
|
Assertions fires because your m_stupidTree is not a valid Win32 window. In other words, you haven't called CTreeCtrl::Create yet, --or-- the call has failed (invalid parameters passed are most likely the problem).
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|