|
Since you know when first window is alive or not (after all you create, destroy or hide the window...) why don't you set a global flag and use it?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
What will happen or what will be the problem if I hide and create window as mentioned above. Why we should go that way and problem it will cause and why is it a bad idea?
|
|
|
|
|
Nandu_77b wrote: Now my question is, finding a window handle using window name and hiding the window is a good idea or not in the real time application. Will this create a problem in the future? If not what is the best way to do it?
Using FindWindow() could work or it could possibly result in a failure or a deadlock. What FindWindow() does internally is call EnumWindows() , and for each top-level window handle found, it sends a WM_GETTEXT message to the window handle. Now if the thread that owns the handle is blocked (e.g., on a Semaphore, a Mutex, an Event, an I/O operation, or some other manner), the SendMessage() call will block until that thread is freed up. Worst case, this may never happen so FindWindow() will block forever.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I want to draw an image on wizard(CpropertySheet - wizard mode)'s top, it has Wizard97 style and I hide the header, so that this image can be seen on every page of that wizard.
I have drawn the image in OnPint() handler and return TRUE from OnEraseBkgnd() handler of CPropertySheet derived class. From every page, I return FALSE from OnEraseBkgnd() handler.
But this is not working as I want to work.
BOOL MyWizardSheet::OnInitDialog()
{
if(NULL == m_hBitmap)
{
m_hBitmap = (HBITMAP)LoadImage( NULL,
szManufactureLogoName.GetBuffer(),
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE );
szManufactureLogoName.ReleaseBuffer();
}
return CPropertySheet::OnInitDialog();
}
void MyWizardSheet::OnPaint()
{
CPaintDC dc(this);
CBitmap cbitmap;
BITMAP pbm;
if(NULL != m_hBitmap)
{
cbitmap.Attach(m_hBitmap);
cbitmap.GetBitmap(&pbm);
CDC dcMemory;
dcMemory.CreateCompatibleDC (&dc);
CBitmap* pOldBitmap = dcMemory.SelectObject (&cbitmap);
CRect rect;
GetClientRect (&rect);
dc.StretchBlt(0, 0, rect.Width(),pbm.bmHeight,
&dcMemory,
0, 0, pbm.bmWidth, pbm.bmHeight, SRCCOPY);
dcMemory.SelectObject (pOldBitmap);
}
}
|
|
|
|
|
You may try moving your drawing code to CPropertyPage derived classes.
|
|
|
|
|
Morning,everybody !
why doesn't this code use option "/O2" in VC/VS2003 compiler, it can print "Error".
but if you use "/Od" , it doesn't print Error. why ???
#include <stdio.h>
int main()
{
static const int T[1] = {0};
int n = 0;
for(int i = 536000000; i < 536000004; ++i)
{
if(i < 0)
{
printf("Error is %d\t%x\n",i,i);
break;
}
if(i >= 0 && i < 1)
n += T[i];
}
printf("end\n");
return n;
}
Thanks for your reply !
Best Reguards !
|
|
|
|
|
Appears to be a compiler bug.
It disassembles to:
; 12 :
; 13 : for(int i = 536000000; i < 536000004; ++i)
00003 b9 00 b6 f2 1f mov ecx, 536000000 ; 1ff2b600H
00008 b8 00 d8 ca 7f mov eax, OFFSET FLAT:_?T@?1??main@@9@4QBHB+2144000000
$L585:
; 14 : {
; 15 : if(i < 0)
0000d 3d 00 00 00 00 cmp eax, OFFSET FLAT:_?T@?1??main@@9@4QBHB
00012 7c 25 jl SHORT $L599
|
|
|
|
|
wangningyu wrote: but if you use "/Od" , it doesn't print Error. why ???
Because /Od suppresses code movement, the compiler likely removed the if() block since it detects i is never less than 0 .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
This appears to be fixed in newer compilers.
|
|
|
|
|
|
VC6/VS2003 are old compilers and so I don't think the bug is "new".
|
|
|
|
|
|
Here's some code:
View declaration:
class CCookItDBView : public CRecordView
{
enum{ IDD = IDD_COOKITDB_FORM };
CMyDB* m_pSet;
// Attributes
public:
CCookItDBDoc* GetDocument() const;
void InsertItemsIngred();
void SetExtendedIngred();
void SetColumsIngred();// gives error at runtime NOT Compile time
// Operations
public:
// Ingredients LC
CListCtrl m_cIngred_LC;
CRecipeDataVec m_vRecipe;
CRecipeData m_cRecipeData;
.....
};
void CCookItDBView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
DDX_Control(pDX, IDC_INGRED_LC, m_cIngred_LC);IDC_INGRED_LC is the List Control and m_cIngred_LC is it's varable
// you can insert DDX_Field* functions here to 'connect' your controls to the database fields, ex.
// DDX_FieldText(pDX, IDC_MYEDITBOX, m_pSet->m_szColumn1, m_pSet);
// DDX_FieldCheck(pDX, IDC_MYCHECKBOX, m_pSet->m_bColumn2, m_pSet);
// See MSDN and ODBC samples for more information
}
void CCookItDBView::SetColumsIngred()
{
//CString csWorkDate = "";
CString csAmt = "Amount:";
CString csUnit = "Unit:";
CString csIngred = "Ingredients:";
// insert two columns (REPORT mode) and modify the new header items
CRect rect;
m_cIngred_LC.GetClientRect(&rect);// gives error at Runtime NOT compile Time
int nColInterval = rect.Width()/7;
m_cIngred_LC.InsertColumn(0, csAmt, LVCFMT_LEFT, nColInterval*2);
m_cIngred_LC.InsertColumn(1, csUnit, LVCFMT_LEFT, nColInterval*2);
m_cIngred_LC.InsertColumn(2, csIngred, LVCFMT_LEFT, nColInterval*2);
}
A C++ programming language novice, but striving to learn
|
|
|
|
|
Where are you calling SetColumsIngred from.
You cannot call it from the dialog constructor.
It has to be called From the OnInitDialog function.
|
|
|
|
|
void CCookItDBView::OnInitialUpdate()
{
SetColumsIngred();
m_pSet = &GetDocument()->m_CookItDBSet;
}
ass you can see, I am calling it from the CRecordView class (see previous header code)
A C++ programming language novice, but striving to learn
|
|
|
|
|
Set a breakpoint in OnInitialUpdate and single step into SetColumsIngred .
|
|
|
|
|
I did that already. That's how I know where if crashes. I crashes on the three lines I indicated above.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Does the list control window exist at this point?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Yes!
A C++ programming language novice, but striving to learn
|
|
|
|
|
So then what's the error?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
David it doesn't give an error, it just crashes.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: ...it just crashes.
Assertion, exception, what?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
//This crashes because as you indicated the window has not been created yet:
void CCookItDBView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_CookItDBSet;
SetColumsIngred();
CRecordView::OnInitialUpdate();
}
// THIS IS CORRECT IT WORKS NOW
void CCookItDBView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_CookItDBSet;
CRecordView::OnInitialUpdate();
SetColumsIngred();
}
I didn't understand you previous comment until in debug I caught it.
Thanks David.
Question: I have several "Tables" in the database that hopefully will point me to data contained in other tables that are not presently linked in the RecordSet. For example: Table "RecipeData" is not linked in the RecordSet (I didn't select it when I selected the Tables) can I still do this: CString str = m_pSet->[RecordDate].Recipe;
A C++ programming language novice, but striving to learn
|
|
|
|
|
Yes, you can reference whatever tables you want in the GetDefaultSQL() method. Make sure that the fields in the query match the order of the associated variables in the DoFieldExchange() method.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
David,
I tried to write to the DB and I get an error "The RecordSet is read only." How do I change that?
A C++ programming language novice, but striving to learn
|
|
|
|