|
I have an MDI MFC app where for "ease of use" I want the MDI child windows to stay maximized. When I create them, the frames are initially maximized (WS_MAXIMIZE is set as a style), and they have no minimize or maximize button.
So far so good, but when I use the "Windows" menu to switch between them, it insists on restoring all the MDI child frames.
I hacked around this by handling the OnMDIActivate, and if the frame is being activated, I do a ShowWindow(SW_MAXIMIZE).
Only problem is that this shows as a set of restored windows (as the other MDI children are repainted), and then the active window repaints itself maximized. This leaves a flickering effect on screen for around a quarter of a second
Is there a way I can suppress this?
Steve S
[This signature space available for rent]
|
|
|
|
|
You're must add red line
void CChildFrame::ActivateFrame(int nCmdShow)
{
<code>nCmdShow = SW_SHOWMAXIMIZED;</code>
CMDIChildWnd::ActivateFrame(nCmdShow);
}
Best regards,
Eugene Pustovoyt
|
|
|
|
|
Thanks, Eugene, but that was the first thing I'd tried.
I still get the flashing effect. (Presumably it's something to do with the way the windows are being managed). I think I might be able to get around it by making the (other) frames invisible, rather than having them switched to restored size. It wouldn't be a problem, but one of the panes in the child frame is a form, and I don't want the user to have to scroll it, as there's no non-mouse interface to achieve that, and at least one of the users cannot use a mouse or pointing device.
Steve S
[This signature space available for rent]
|
|
|
|
|
Hi Steve,
This MDI behavior is a pain, and varies across Windows versions. The snippet below is what I do in ED (see sig) to try and handle this. Hope it helps.
CWnd* pMDIClient = NULL;
BOOL bMaximized;
pMF->MDIGetActive( &bMaximized );
if ( bMaximized )
{
pMDIClient = pMDIChild->GetParent();
pMDIClient->SetRedraw( FALSE );
}
pMF->MDIActivate( pMDIChild );
if ( bRestoreMinimized and pMDIChild->IsIconic() )
pMDIChild->MDIRestore();
if ( bMaximized )
{
pMDIClient->SetRedraw( TRUE );
pMDIClient->RedrawWindow( NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN );
}
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
I have a thread handle,when the thread exit.the handle is invalid(0xfeeefeee).
and i want to clearly when is it valid and when is it invalid.
please show me a solution,thanks.
Scratch
|
|
|
|
|
A Thread handle IS valid even after the Thread exits. There is an error in your code that's corrupting the handle value.
But, answering your question: you can always call a harmless API function that needs a thread handle, say GetThreadPriority. If it returns ERROR_INVALID_HANDLE, you know the handle is invalid.
lazy isn't my middle name.. its my first.. people just keep calling me Mel cause that's what they put on my drivers license. - Mel Feik
|
|
|
|
|
thank you for your help,but my code goes like:
In main thread.
<br />
if(m_pScanThread && m_pScanThread->m_hThread != NULL)<br />
{<br />
m_pScanThread->PostThreadMessage(UWM_TIMERON,0,0);<br />
}<br />
else<br />
{<br />
m_pScanThread = AfxBeginThread((AFX_THREADPROC)fnScanProc,NULL);<br />
if(m_pScanThread && m_pScanThread->m_hThread != NULL)<br />
m_pScanThread->PostThreadMessage(UWM_TIMERON,0,0);<br />
}<br />
Thread function.
<br />
CoInitializeEx(NULL,COINIT_MULTITHREADED );<br />
try<br />
{<br />
DWORD dwRet;<br />
MSG msg;<br />
while(dwRet = GetMessage(&msg,NULL,0,0) != 0)<br />
{<br />
if(dwRet == -1)<br />
{<br />
continue;<br />
}<br />
else<br />
{<br />
if(msg.message == UWM_TIMERON)<br />
Scan(...);<br />
else<br />
DispatchMessage(&msg);<br />
}<br />
}<br />
}<br />
catch(...)<br />
{<br />
return -1;
::CoUninitialize();<br />
}<br />
::CoUninitialize();<br />
return 0;
Scratch
|
|
|
|
|
I never use MFC thread classes, for me they are just so much trouble for a simple _beginthread. But I'm sure that you can store the m_hThread in another variable just before the thread starts.
and, beware of this code:
m_pScanThread = AfxBeginThread((AFX_THREADPROC)fnScanProc,NULL);
if(m_pScanThread && m_pScanThread->m_hThread != NULL)
m_pScanThread->PostThreadMessage(UWM_TIMERON,0,0);
IIRC, you need a small Sleep or a Sleep(0) just after the AfxBeginThread for the other thread begin starting, otherwise in a 100% CPU machine you'll have problems.
lazy isn't my middle name.. its my first.. people just keep calling me Mel cause that's what they put on my drivers license. - Mel Feik
|
|
|
|
|
Be warned!
Using ::BeginThread with mfc corupts the mfc state handling!
As far as I understand _beginthread is a wrapper for the Win32 API.
|
|
|
|
|
hi,
i want to know more detailed usage of CCriticalSection.
if i have a global CDatabase object. and, i used it to create a local instance of CRecordSet object in each thread.
do i need to Lock() the whole progress using CRecordSet or just the moment CDatabase be used by CRecordSet? you know, the CRecordSet used CDatabase when start the instance.
there is big diff. on the time holding the public resource, CDatabase.
anyone have any idea?
thanks,
jim
|
|
|
|
|
Hello,
i have an MDIChildWnd with StatusBar and Sizegripper.
I now want to change this resizable window into a non-resiable one, and vice versa. I removed WS_THICKFRAME from frame window. The window size is now fixed but the Statusbar don't get updated and the sizegipper is still shown. I tried a lot (e.g. invalidate, setwindowpos with SWP_FRAMECHANGE) to get it repainted correctly but it only works if i call the function twice (from menu or button).
Has anyone an idea how to change this dynamically.
Any help would be great
|
|
|
|
|
Hi all,
I am trying to create an XML file (containing Greek characters also) from within Visual C++ 6. The code is listed below:
FILE *v_myfile;
_TCHAR v_fileline[100];
_TCHAR v_filename[100];
swprintf(v_filename, _T("%s"), _T("myfile.xml"));
v_myfile=_wfopen(v_filename, _T("w"));
swprintf(v_fileline, _T("%s"), _T("<?xml version=\"1.0\" encoding=\"UNICODE\" ?>"));
fwrite(v_fileline, sizeof(_TCHAR), wcslen(v_fileline), v_myfile);
swprintf(v_fileline, _T("%s"), _T("<Mytag>some text</Mytag>"));
fwrite(v_fileline, sizeof(_TCHAR), wcslen(v_fileline), v_myfile);
....... similar writes to the file and finally..
fclose(v_myfile);
Well, the file is created and I am able to view it using the notepad. However, when I am trying to open it using Internet Explorer I am getting an error related to an invalid character at position 2, line 1 (at the "<" character).
If I open the file with notepad and then save the file WITHOUT making any changes (notepad automatically suggests that I save it as UNICODE), the Internet Explorer is then able to read the file correctly .
Before I save it using notepad, the length of the file is 752 bytes. After I save it, the length is 754. I guess that these two bytes make the difference.
Anybody have any idea about what is happening?
also, instead of "UNICODE" at the "<?xml....." line I have tried to put "UTF-8", "UTF-16" without any success.
I thank you in advance,
Christos P.
p.s. I have defined _UNICODE at the project setting.
|
|
|
|
|
If I remember right there are two bytes at the beginning of every Unicode
text file. Just copy the two first bytes of the "correct file" in front of Your file and all will be fine.
|
|
|
|
|
Thank you for your reply Alois, but I want to create the file at runtime.
Regards,
Christos P.
|
|
|
|
|
These two bytes will always be the same once You know them. Just prepend them.
|
|
|
|
|
All unicode text files must begin with the Unicode char 0xFEFF
eperales
|
|
|
|
|
I have a big problem with my MFC PocketPC application!
I have a simple SDI (single document) application, and two command bars on top of my application.
It works very fine, but when I open a dialog (let's say the "Open File..." dialog") and I invoke any one of the SIP components, i.e. the Keyboard and then close the dialog (the Keyboard is visible when I click the "Close" button of my dialog) I will see the view of my application, but the command bars are missing! It look like, that the view resized to the whole area and the command bars are moved outside the screen, so that the command bars are not vissible!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
The following question relates to a programming technique Andrei Alexandrescu presents in Modern C++ Design. Due to the lack of time, I assume you either have read it or understand the concept via experience.
In his book, Alexandrescu shows a generic programming technique he calls "Mapping Integral Constant to Types" in chapter 2, section 2.4. Here is an example.
-----
template <<int a="">>
struct Int2Type
{
enum {type = A};
};
enum TypeA{WIN = 0x0000, LOSS};
template <<typename t,="" int="" u="">>
class XYZ
{
T *Create(Int2Type<<win>> );
T *Create(Int2Type<<loss>> );
};
// Usage
XYZ<<myclass, win="">> zyx;
-----
Again, I assume you understand the concept above.
XYZ<<myclass, win="">> ... compiles as along as you pass in WIN or LOSS. However, here is what I want to do, but have not been able to get Visual C++ to compile without errors.
-----
TypeA myType;
myType = WIN;
XYZ<<myclass, mytype="">> zyx;
-----
I would like to know if there is a solution to the problem above.
The general idea is I want to pass in WIN or LOSS via a variable. The reason I have not implemented WIN and/or LOSS instead of the variable is because in the way I have setup the algorithm. Typing in WIN and LOSS will require switch states and if/else statements.
Thanks,
Kuphryn
|
|
|
|
|
I cannot read your code because you did not set it to show template arguments, but I'm presuming it won't compile in VC because the book in question relies on partial template specialisation, which to date is not offered in any currently available Microsoft compiler. My copy is sitting on the shelf, awaiting Everett.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
It is not entirely clear to me what you're after. Anyway, the lines of code
TypeA myType;
myType = WIN;
XYZ<MyClass, myType> zyx; can't compile because template parameters must be either types (classes, primitive types) or compile-time constants. If you want to hold a variable, pass it on to the object in its constructor. If you specify with a little more detail your problem maybe I can be of any real help
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Okay. Thanks.
I understand the concept more and why I my design will not work.
I want to create random objects that derive from other objects, but I do not know what.
Object -> A or B or C
A -> D or E or F
B -> G or H or I
C -> J or K or L
Basically, I am implementing an object, but I do not know what classes it and its ancestors are derived from.
Kuphryn
|
|
|
|
|
?? Pardon? I really do not get your point. If you explain it with some pseudocode or something maybe I can try to be of help (the thing seems promising, though ).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I will try a quick example.
-----
- Generate a random number
1 = object 1A
2 = object 2A
...
Given: object xA derives from xB
- Generate a random number
1 = object 1B
2 = object 2B
...
..
..
- Use an object factory to create the object based on the results of the random number.
-----
In general, I am trying to stay away from implement many lines of switch and if/else statements in order to create a single object.
Kuphryn
|
|
|
|
|
Well, you'd have to write some sort of class factory, as you point out. Here's a sketch of what could be done:
class A
{
typedef A* (creator *)();
typedef map<int,creator> creators_map;
static creators_map m;
protected:
static void register(int n,creator c)
{
m[n]=c;
}
public:
A* create(int n)
{
creators_map::iterator it=m.find(n);
if(it==m.end())return 0;
return it->second();
}
};
class A1: public A
{
static A* create(){return new A1;}
public:
static void register()
{
A::register(1,create);
}
...
};
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|