|
This is my class, which should help you. It uses my CSeException class from this site. Note, you must pass handle of your main window to DoModal() function.
class CDominikDlg : public CDialog
{
// Construction
public:
CDominikDlg(DWORD dwID, CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CDominikDlg)
//}}AFX_DATA
MSG m_msgCur;
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDominikDlg)
public:
virtual int DoModal(HWND hWndParent);
virtual int RunModalLoop(DWORD dwFlags = 0);
virtual BOOL PumpMessage(void);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
CFont m_font;
// Generated message map functions
//{{AFX_MSG(CDominikDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#define WM_KICKIDLE 0x036A // (params unused) causes idles to kick in
CDominikDlg::CDominikDlg(DWORD dwID,CWnd* pParent /*=NULL*/)
: CDialog(dwID, pParent)
{
//{{AFX_DATA_INIT(CDominikDlg)
//}}AFX_DATA_INIT
m_font.CreateFont(8, 6, 0, 0, FW_THIN, 0, 0, 0, DEFAULT_CHARSET,
OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, _T("Courier New"));
}
void CDominikDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDominikDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDominikDlg, CDialog)
//{{AFX_MSG_MAP(CDominikDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDominikDlg message handlers
int CDominikDlg::DoModal(HWND hWndParent)
{
// can be constructed with a resource template or InitModalIndirect
ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL ||
m_lpDialogTemplate != NULL);
// load resource as necessary
LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;
HGLOBAL hDialogTemplate = m_hDialogTemplate;
HINSTANCE hInst = g_hDll;
HINSTANCE hinTmp = afxCurrentInstanceHandle;
HINSTANCE hresTmp = afxCurrentResourceHandle;
afxCurrentResourceHandle = g_hDll;
afxCurrentInstanceHandle = g_hDll;
if (m_lpszTemplateName != NULL) {
HRSRC hResource = ::FindResourceEx(g_hDll,RT_DIALOG,m_lpszTemplateName,MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
hDialogTemplate = LoadResource(hInst, hResource);
}
if (hDialogTemplate != NULL)
lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);
// return -1 in case of failure to load the dialog template resource
if (lpDialogTemplate == NULL)
return -1;
// disable parent (before creating dialog)
//HWND hWndParent = PreModal();
//AfxUnhookWindowCreate();
BOOL bEnableParent = FALSE;
if (hWndParent != NULL && ::IsWindowEnabled(hWndParent)) {
::EnableWindow(hWndParent, FALSE);
bEnableParent = TRUE;
}
try {
// create modeless dialog
//AfxHookWindowCreate(this);
if (CreateDlgIndirect(lpDialogTemplate,
CWnd::FromHandle(hWndParent), hInst)) {
if (m_nFlags & WF_CONTINUEMODAL) {
// enter modal loop
DWORD dwFlags = MLF_SHOWONIDLE;
if (GetStyle() & DS_NOIDLEMSG)
dwFlags |= MLF_NOIDLEMSG;
VERIFY(RunModalLoop(dwFlags) == m_nModalResult);
}
// hide the window before enabling the parent, etc.
if (m_hWnd != NULL)
SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW|
SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
}
} catch(CSeException *e) {
DUMPEXCEPTION(e);
::SetLastError((unsigned long)NTE_FAIL);
e->Delete();
} catch (...) {
TRACE(_T("%s(%d): Unknown exception.\n"),__FILE__,__LINE__);
m_nModalResult = -1;
}
if (bEnableParent)
::EnableWindow(hWndParent, TRUE);
if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd)
::SetActiveWindow(hWndParent);
// destroy modal window
DestroyWindow();
PostModal();
// unlock/free resources as necessary
if (m_lpszTemplateName != NULL || m_hDialogTemplate != NULL)
UnlockResource(hDialogTemplate);
if (m_lpszTemplateName != NULL)
FreeResource(hDialogTemplate);
afxCurrentInstanceHandle = hinTmp;
afxCurrentResourceHandle = hresTmp;
return m_nModalResult;
}
int CDominikDlg::RunModalLoop(DWORD dwFlags)
{
ASSERT(::IsWindow(m_hWnd)); // window must be created
ASSERT(!(m_nFlags & WF_MODALLOOP)); // window must not already be in modal state
// for tracking the idle time state
BOOL bIdle = TRUE;
LONG lIdleCount = 0;
BOOL bShowIdle = (dwFlags & MLF_SHOWONIDLE) && !(GetStyle() & WS_VISIBLE);
HWND hWndParent = ::GetParent(m_hWnd);
m_nFlags |= (WF_MODALLOOP|WF_CONTINUEMODAL);
MSG* pMsg = &m_msgCur;
// acquire and dispatch messages until the modal state is done
for (;;) {
ASSERT(ContinueModal());
// phase1: check to see if we can do idle work
while (bIdle &&
!::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE)) {
ASSERT(ContinueModal());
// show the dialog when the message queue goes idle
if (bShowIdle) {
ShowWindow(SW_SHOWNORMAL);
UpdateWindow();
bShowIdle = FALSE;
}
// call OnIdle while in bIdle state
if (!(dwFlags & MLF_NOIDLEMSG) && hWndParent != NULL && lIdleCount == 0) {
// send WM_ENTERIDLE to the parent
::SendMessage(hWndParent, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)m_hWnd);
}
if ((dwFlags & MLF_NOKICKIDLE) ||
!SendMessage(WM_KICKIDLE, MSGF_DIALOGBOX, lIdleCount++)) {
// stop idle processing next time
bIdle = FALSE;
}
}
// phase2: pump messages while available
do {
ASSERT(ContinueModal());
// pump message, but quit on WM_QUIT
if (!PumpMessage()) {
AfxPostQuitMessage(0);
return -1;
}
// show the window when certain special messages rec'd
if (bShowIdle &&
(pMsg->message == 0x118 || pMsg->message == WM_SYSKEYDOWN)) {
ShowWindow(SW_SHOWNORMAL);
UpdateWindow();
bShowIdle = FALSE;
}
if (!ContinueModal())
goto ExitModal;
} while (::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE));
}
ExitModal:
m_nFlags &= ~(WF_MODALLOOP|WF_CONTINUEMODAL);
return m_nModalResult;
}
BOOL CDominikDlg::PumpMessage()
{
ASSERT_VALID(this);
if (!::GetMessage(&m_msgCur, NULL, NULL, NULL)) {
return FALSE;
}
// process this message
if (m_msgCur.message != WM_KICKIDLE && !PreTranslateMessage(&m_msgCur)) {
::TranslateMessage(&m_msgCur);
::DispatchMessage(&m_msgCur);
}
return TRUE;
}
|
|
|
|
|
Hi there ,
I have a class lets say CMyClass, it contains a member variable of type CArray of lets say int.
Now I have a public function of this Class GetValue(int nIndex) now this function returns the Reference of int which is actually a reference to a particular index of my CArray type member variable.
Now here is the problem .. My GetValue function performs some checks before returning the Refrence . now in case the checks fails I dont want to return the reference .. in that case WHAT DO I RETUNR FROM MY CODE.
does any body understand what I am trying to ask ?
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
Throw an exception. There's no reference equivalent of a NULL pointer, so you must either return a valid reference or throw.
|
|
|
|
|
Wonderfull Idea !! thanks .. please tell me more about throwing exceptions also ..
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
Throw an exception.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hmm that seems a better idea .. please throw some light on thoring exceptions also ..
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
Essentially, you just throw with throw , which interrupts the normal flow of execution and throws an object that can be catched by some point up the call stack with catch .
Just read your docs for throw and catch , and/or search some tutorial on the net, sure there're many out there.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
It goes like this:
1. Create a class CMyException. Here is an example:
class CMyException
{
CString strError;
public:
CMyException (CString& a) : strError (a) {}
void HandleError ()
{
AfxMessageBox (strError);
}
}
2. Do this in that function:
if (index_is_out_of_bounds)
throw CMyException ("Index out of bounds");
3. Catch the exception like this:
try
{
}
catch (CMyException& e)
{
e.HandleError ();
return;
}
You can also check MSDN for details or download a good C++ book. "Thinking in C++" from www.bruceeckel.com
Best regards,
Alexandru Savescu
|
|
|
|
|
Hi,
Can someone please tell me how can I set the size for a
CFormView, say if I want to set size to ( 1000, 1000 ).
Thanks,
Sansky
John 3:16
For God so loved the world,
that he gave his only begotten Son ( Jesus Christ ) ,
that whosoever believeth in him should not perish, but have everlasting life.
|
|
|
|
|
Use MoveWindow and then ResizeParentToFit .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
In the view call SetScaleToFitSize()
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
Hi,
I am trying to open a html file. for this i use DDE.
My DdeClientTransaction() call is as follows.
DdeClientTransaction( 0,
0,
hConv,
hItem,
CF_TEXT,
XTYP_REQUEST,
5000,
&dwResult )
It works fine, if the path for html file doesn't contain a space.
Could anyone knows how to make it work if the path contains a space in it?
Regards
Neha
|
|
|
|
|
|
I think that the first question that you should ask is who is the audience that you are developing your program for? I do not think that that interface looks so cluttered, so it may be a good one to follow. I guess the people at 3D Studio Max have had success with that interface so it probably would not hurt you to follow it.
One more thing to keep in mind, the more complicated that you make your interface the more advanced the user will need to be.
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!
|
|
|
|
|
It's kind of hard to read for old folks like me. Hopefully you'll use more contrast instead of black and dark gray.
BTW, on your sig, is the word "Wonders" correct or should it be "Wanders"? Wanders would make more sense to me.
|
|
|
|
|
Deal all,
In a dialog-based application, i have detect all the cd-rom devices
successfully. Now i want to insert and eject a cd-rom.
How to insert and eject a cd-rom by using sendAspi32Command ?
Thanks in advance!
chen
|
|
|
|
|
|
Hi,
I have a 24bit BMP and want to programatically convert
it to GIF file.
How do i do that
Sameer
|
|
|
|
|
Use any of the varios graphics libraries available on the net. For one, paintlib seems a good choice.
PS: Seems paintlib does not output GIFs, probably because of the patents problems associated with this format. If you can switch to PNG then the library will serve your needs.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
If you can switch to PNG then the library will serve your needs.
Actually, I have a 24 bit BMP and I want a format, which
converts it to a Browser Compatible format and its
size is the smallest.
Wha about the size of PNGs
Sameer
|
|
|
|
|
If you're outputting synthetic images (chart diagrams, simple icons), then PNG is fine. For all other things, specially photographies, JPEG is a much better choice.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi all,
I have to develop a ISO9660 File System in windows NT platform.I have dowmloaded the mkisofs whihc is written mainly for UNIX.How can i use this code for windows.Also, if somebody had already worked in this code meand how can we use this code(can u explain how the exe works& how we have to give the args at command line).Is any config file used.
I tried going thro the docs for this.But, cuold not succeed in creating the file system..
TIA.
|
|
|
|
|
From your explanation it sounds like what you try to accomplish is to write an ISO-9660 image. The file system driver for it is already provided by Microsoft.
You are right that mkisofs is written mainly for *nix, but it's works almost as good on Win32 (perhaps/probably equally well is compiled under cygwin). The tiny problem is with inodes used for hashing, why recursing directory trees can be a bit strange.
As for the syntax of how you invoke mkisofs, have you read any of the docs included? Let's say you want to create an image where the "volume name" is to be "Mush" and it is to be only used on Windows why a an additional Joliet directory but no Rock Ridge directory would suffice, and that CD is to have two files "foo" and "bar" in the root, and finally the image file is to be named barf.img.
mkisofs -V Mush -J -o barf.img foo bar
|
|
|
|
|
Hi,
Thanx for the information.
I am using windows NT.I am using the earliest version 0.99 and don't want Joliet or Rock Ridege extensions.
I am facing prob with vms.c file as certain functions like opendir(),readdir() use certain unix specific functions.The code compliation gives error becos of this.
Moreover if iam having jpeg file(for forming image file) in a particular path how can i specify that in the command line.
TIA.
Y.Yamini Devi
|
|
|
|
|
Hi,
Thanx for the information.
I am using windows NT.I am using the earliest version 0.99 and don't want Joliet or Rock Ridege extensions.
I am facing prob with vms.c file as certain functions like opendir(),readdir() use certain unix specific functions.The code compliation gives error becos of this.
Moreover if iam having jpeg file(for forming image
file) in a particular path how can i specify that in the command line.
TIA.
Y.Yamini Devi
|
|
|
|
|