|
Ok ... I want to have Tabs
on all my MDIClients of my
application so all I need to
do is this ....
In my CMainFrame::OnCreateClient method I add the lines
...
tab = new MyTab();
tab.AddItem(this)
...
right?
Wrong of course.
What should I be doing?
I have looked at all the examples
on TabControls none of them
are what I need and I really don't
understand MFC.
Please help you might "win" a convert.
(pardon the pun)
|
|
|
|
|
check out the doc/view section here on cp
there are a few very good articles / frameworks for what you want
situations to avoid #37: "good morning ... how many sugars do you take in your coffee ... and what was your name again?"
coming soon: situations to avoid #38: "...and the dog was there too?"
|
|
|
|
|
Thanks for the info ... but the examples there
are pretty much the same. They have MDI "client"
brought to the front by clicking on a tab in the
MDI "main frame". I would like to have the
tabs inside the "client".
I can see that having the tab on the "main frame"
has its advantages but that is not what my user
wants.
Here's what i am trying to do ...
http://www.codeproject.com/useritems/newtomfcneedhelp.asp
Thanks
|
|
|
|
|
I embedded the WebBrowser control in my app... couple questions:
In Internet Explorer whenever the user navigates to a new page,
the logo up in the top right hand corner (on the same level as the
menu) rotates between a globe and the start symbol. How can I add
something like that to my app? Would I use the CAnimateCtrl or whatever
it's called? How doe I get it on the same level as the menu bar in
my app? I have a dialog based app... in case that's important.
When I run my app and browse to a page, it loads fine. But then
whenever I hit the Escape key on the keyboard, the whole WebBrowser
control disappears. If I enter a new URL in my ComboBox and hit the
Go button, then the WebBrowser control reappears. How can I make it
so the Escape key does not make the WebBrowser control disappear?
thanks,
thundercatzlair
|
|
|
|
|
Hi, folks,
I got some problems for multi-threading/multiple instances with one thread function. What's wrong with the following code segment.
In some cases, I got wrong instance as showed below. The case is: if I have 2 jobs triggered, say Job 1 and Job 2, Job 1 is triggered first but Job 2 would be done first (i.e, done prior to Job 1). Then, when Job 2 Set event (i.e, set to signaled state), I found in Master Thread Function,
in the line of WaitForSingleObject(..), what I got is Job 1's instance and Job 1's event ? Could anyone tell me how to solve this problem ? Anything wrong ? Thanks in advance.
PS> I do need to wait for events, because I have more than one tasks to do and I need to wait until all tasks are done, although in this small code, it seems just one task.
/// JOBINST: my job instance
DWORD WINAPI StartJob( JOBINST pJobObj )
{
pJobObj->hMasterThread( 0, 0, MasterThreadFunc, pJobObj, 0, &( pJobObj->dwMasterThreadID ) );
}
DWORD WINAPI MasterThreadFunc( LPVOID lpParam )
{
JOBINST pJobObj = (JOBINST) lpParam;
pJobObj->hMailEvent = CreateEvent( 0, FALSE, FALSE, "Mail Thread Event" );
pJobObj->hMailThread = CreateThread( NULL, 0, MailThreadFunc, pJobObj, 0, &( pJobObj->dwMailThreadID ) );
WaitForSingleObject( pJobObj->hMailEvent, INFINITE );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
///<------ In some cases, I got wrong pJobObj and wrong pJobObj->hMailEvent here
CloseHandle( pJobObj->hMailEvent );
ExitThread( 0 );
}
DWORD WINAPI MailThreadFunc( LPVOID lpParam )
{
JOBINST pJobObj = (JOBINST) lpParam;
//// do something here...
//// when finished with something, set event; set to signaled state
SetEvent( pJobObj->hMailEvent );
ExitThread( 0 );
}
|
|
|
|
|
Sorry, just typo... the correct one is as follows:
DWORD WINAPI StartJob( JOBINST pJobObj )
{
pJobObj->hMasterThread = CreateThread( 0, 0, MasterThreadFunc, pJobObj, 0, &( pJobObj->dwMasterThreadID ) );
}
|
|
|
|
|
Could you setting the event on SetEvent(pJobObj->hMailEvent) before WaitForSingleObject()? Do a simple test add:
Sleep(100); before //// do something here!
Let me know...
Al
|
|
|
|
|
>Could you setting the event on SetEvent(pJobObj->hMailEvent) before >WaitForSingleObject()? Do a simple test add:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Why ? Originally, the pJobObj->hMailEvent is on non-signaled state. And, when the MailThreadFunc() is finished, I set this event to signaled state.
So, I can NOT put SetEvent(pJobObj->hMailEvent) before WaitForSingleObject() in MasterThreadFunc(). (Is this what you mean ?)
>Sleep(100); before //// do something here!
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Al:
In fact, I have a Sleep(5000) right before SetEvent(pJobObj->hMailEvent) in MailThreadFunc(..).. Same result as I described.
|
|
|
|
|
I don't know then!
Looks good to me.
Sorry!
Al
|
|
|
|
|
That isn't a problem with events unless you use something like PulseEvent.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
It looks like it would be a problem in how you are managing your job pointers. You have them stored in a std::vector?
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
>>It looks like it would be a problem in how you are managing your job >>pointers. You have them stored in a std::vector?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
No, I did not use std::vector. I use my own linked list (queue) to store my job pointers. And, when I try to remove the "store operation" to list (i.e, now I did not keep these job pointers), same thing. So, I guess the problem should be on the thread or thread function ?
But the above code is fine in this case: job 1 is triggered before job 2 and, job 1 is also "done" before job 2.
I still don't know why.
|
|
|
|
|
I got it already ! Thanks for everybody's reply.
JOBINST pJobObj = (JOBINST) lpParam;
pJobObj->hMailEvent = CreateEvent( 0, FALSE, FALSE, "Mail Thread Event" );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Wrong for the event string - "Mail Thread Event" !!
Every event should be unique !
So, the correct one is something like this:
char strMailEvent[ 64 ];
wsprintf( strMailEvent, "MyMailEvent %x",( DWORD )pJobObj );
pJobObj->hMailEvent = CreateEvent( 0, FALSE, FALSE, strMailEvent );
because every pJobObj is unique (allocated from heap), I use this as key for every event.
|
|
|
|
|
Ok,... I would rather use the help files that C++ comes with rather than ask you guys all the time. "no offence" There are good reasons for this, 1. dont have to bother you with stupid questions i can first find out on my own. 2. It would just be more helpfull for me
ok... i wanted to change the color of the background using win32 console app.
the file said... "exactly "
---------------------------------------------------
CDC::SetBkColor
virtual COLORREF SetBkColor( COLORREF crColor );
Return Value
The previous background color as an RGB color value. If an error occurs, the return value is 0x80000000.
Parameters
crColor
Specifies the new background color.
Remarks
Sets the current background color to the specified color. If the background mode is OPAQUE, the system uses the background color to fill the gaps in styled lines, the gaps between hatched lines in brushes, and the background in character cells. The system also uses the background color when converting bitmaps between color and monochrome device contexts.
If the device cannot display the specified color, the system sets the background color to the nearest physical color.
CDC Overview | Class Members | Hierarchy Chart
See Also CDC::BitBlt, CDC::GetBkColor, CDC::GetBkMode, CDC::SetBkMode, CDC::StretchBlt,::SetBkColor
---------------------------------------------------------------
Now,... how do i use the info that this help file tells me, for that i can do what i want to do in my program? "that is, change the color to white, or blue"
How do i read this and use it?
Thanks All!
~SilverShalkin
|
|
|
|
|
SetBkColor is not related to the console. It looks like you looked up a function from MFC, and MFC is only useful for developing windows applications.
SilverShalkin wrote:
How do i read this and use it?
If you were using MFC, you would create a CDC object. Then you would be able to call the member function of CDC called SetBKColor. One more thing to note, is that a COLORREF can be created
with the RGB() macro, were you provide the RGB color combinations to create a new color.
If you wanted to set the background color to red, you would do this:
void DoSomething (CDC *dc)
{
dc->SetBkColor(RGB(255,0,0));
...
}
I am sorry I do not know console programming well enough to tell you how to change the background color.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
SilverShalkin wrote:
i wanted to change the color of the background using win32 console app.
[...]
CDC::SetBkColor
This is a GDI functions that has nothing to do with console I/O. Have a look at SetConsoleTextAttribute .
|
|
|
|
|
Ok... my mistake... "that makes things a little bit easier to understand
How do i find files only on Win32 console App.'s that i can use to program? and how do i know wether it is a mfc or win32?
Thanks!
~SilverShalkin
|
|
|
|
|
You browse the "outline" of the "books". The window to the left tells you where you are and what "book" you are reading. The path element "Platform SDK" should be obvious. From that one you drill down to "Windows Base Services" and somewhere under that you find this functions. I really hope there's no way in h*ll the POS MFC manages to creep into the SDK also.
|
|
|
|
|
I want to pass a handle to an stl container to a windows callback. However, what I'm doing is causing an exception and that's because what I get in the callback isn't the original container. How do I do this correctly?
typedef std::map<int, std::string> MyMap;
BOOL CALLBACK MyCallback(HWND hwnd, LPARAM lParam)
{
MyMap& myMap = reinterpret_cast<MyMap&>(lParam);
// if I change myMap here it goes BOOM!
myMap[0] = std::string("test");
}
void Test()
{
MyMap myMap;
EnumWindows(MyCallback, &map);
}
<b>Todd Smith</b>
|
|
|
|
|
Todd Smith wrote:
MyMap& myMap = reinterpret_cast(lParam);
Try changing that, to this:
MyMap *myMap = reinterpret_cast<MyMap*>(lParam);
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Forget my original post - you proposed what I was about to, but I misread your post altogether
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Hi.
I am working on a program that displays displays text similar to a text editor. The program works as expected, however, it takes a very long time to display a text file that is 60k or larger.
I am using CEditView as view. Here is the algorithm that displays the texts.
-----
int MAXSIZE = 256;
char text[MAXSIZE];
CEdit &edit = GetEditCtrl();
edit.SetWindowText("first line");
edit.GetLine(0, text, MAXSIZE); // get first line "first line"
CString newText, temp;
temp.Format("%s", text);
newText.Formate("%s%s%s", temp, "\r\n", newText);
...
-----
The concept of the algorithm is this:
1) display first line
2) get first line
3) add first line & new line in a string
4) display string
5) continue until all *new lines* are added
As you can see, this algorithm is extremely impractically. I compared it to Microsoft's Notepade. Notepage *does not* slow done until you open a file that is 1mb or larger.
Is there a better and *faster* way to display multiple lines of text while using the CEditView? Is there a way at all?
Thanks,
Kuphryn
|
|
|
|
|
Why are you allocating memory for each separate string?
Why do you not just load the entire string into one buffer?
You can store newline information in the string.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Each line of text is saved inside of a linked list of CString. If a file contains ten lines of text, then the program would inside ten CString objects inside the linked list. The program can edit text. As the user make changes to a, the program would update the mirror object inside the linked list.
I need a better way to display all the lines inside the linked list.
Kuphryn
|
|
|
|
|
You may want to consider storing the lines of your text in a different type of container besides a linked list. The lookup time for a linked list is O(n). Meaning, if you have n lines in your file, in order to lookup the last line of the text you would have to navigate through n objects.
Consider your 60K file. Say that each line is 100 bytes long. That would give you 600 lines. If you want to get to the string on the 600th line, you will have to navigate through all 600 lines to get to the end and access the last line.
A better choice would be a vector, where lookup is O(1), which means you can access any of the lines with one lookup. Memory allocations may become a problem with a vector. So you could also consider a Map, which its underlying representation is a tree (if you are using STL) and the look up time would be O(log(n)). Which still beats O(n) by a long shot.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|