|
You know, you COULD put it as a global variable... but then again, we also COULD write poor poor poor code...
If I were you, i would stick to putting it as a member variable of the Document class or the View class...depends on how it is used...
-Reid the C++/C# programmer
(Caution: I am a teenager, and that means that I think I know everything...but probably don't...)
|
|
|
|
|
Yes you're right about the global variable (obviously) but I said that because....hmmmm....don't know why I said that. You're right - it should be a member of the class that's using it.
Truth be told, the reason I said global variable was because I thought maybe he wasn't doing OOP programming, in which case that's pretty much the only alternative.
> Andrew.
|
|
|
|
|
you were right about the ASSERT parameter, but still, i dont understand why i get this error message, and it happens only because i used the AfxGetInstanceHandle() function.
Please heeelp!
thanks.
|
|
|
|
|
How can I create a toolbar whose buttons can be rearranged by drag/drop without needing to hold down any keys?
Also, another question: in VC++ 6, why can't I create a new MFC class that derives from CToolBar, only from CToolBarCtrl? I've gotten around this by creating the ToolBarCtrls and then changing the inheritance myself, which I don't think ClassWizard is too fond of.
thanks,
Jake
|
|
|
|
|
I can't answer to the first question, sorry.
As for the second... it's just what I did two days ago and it works well. May this could comfort you
After you replaced each occurence of CToolBarCtrl with CToolBar, make sure you delete the .clw file and start ClassWizard to create a new one.
Paolo.
|
|
|
|
|
Hi gurus,
Could somebody point me to some documentation for writing makefiles for use with nmake? Everybody seems to use thaem but I cant find any documentation...
Thanks
"A surprise to be sure, but a welcome one."
- Senator Palpatine
|
|
|
|
|
I need to get the current time only in 12 BYTE
2 BYTE - year
2 - month
2 - day
2 - hour
2 - minute
2 - second
|
|
|
|
|
Call GetSystemTime() which returns the date/time in a SYSTEMTIME struct. SYSTEMTIME has the values in WORDs, which are 2-byte unsigned ints.
--Mike--
http://home.inreach.com/mdunn/
"Make sure that if you are using a blow torch that you don't set anything on fire."
-- Chris Maunder
|
|
|
|
|
Hi there,
I need to get the numerical value of COleDateTime..i.e. the 37097.999
and I need to put into a CString.
I was wondering what the best method is for doing this since this value is a double!
|
|
|
|
|
Take a look at the _AfxTmFromOleDate() function in olevar.cpp (located in your MFC source directory) this should give you an idea as to how to do it.
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Ok, this is a bit of a doosey...
I need to save 4-bit (16 color) PNG files, with the
pnglib. What I'm starting with is a 24-bit(RGB)
unsigned char array style bitmap.
I need to figure out two things:
1) How do I convert my 24-bit RGB byte array into a 16
color image?
2) How do I save it as a 4-bit PNG?
I have absolutely no clue where to go with this...
never done any graphics processing other than full
color stuff. I REALLY NEED help!!
Any ideas?
Code examples?
Miracles?
Thanx in advance,
J. A.
|
|
|
|
|
Hi,
Does anyone knows how to set the Shutdown Privilege to WMI on Remote Computers in Visual C++ ?
Microsoft did not documented this very well as usual.
Any reply is welcome.
Thanks in Advance.
Best Regards,
Mario M.
|
|
|
|
|
When the user makes an item selection in the CComboBox, I want to change the edit portion of the combo box to be some calculated value based on the user's selection.
I've tried just about every event for the combo box to get the user's selection and call SetWindowText on the combo box for the new value. Unfortunately, it looks like events processed after mine then change the edit field back to the actual selection. What is the last possible event that I can trigger on and not have my window text overwriten?
Example of what I'm trying to do:
CComboBox has:
1 Hour
12 Hours
1 Day
2 Days
When a user selects "1 Day", I want the edit portion of the ComboBox to display "86400" seconds.
Any help is greatly appreciated.
|
|
|
|
|
The edit control has a grey background & black text, but the grey background only fills as far as the text, the rest of the edit control's background is WHITE.
HOW CAN I FILL THE WHOLE BACKGROUND COLOR AS GREY.
edit controls properties is set at read-only.
OnCtlColor code.....
HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor==CTLCOLOR_EDIT)
{
CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp();
pDC->SetBkColor(pApp->BK_COLOR);
pDC->SetTextColor(pApp->FG_COLOR);
return hbr;
}
return NULL;
}
Gerry.
|
|
|
|
|
You need to change the brush.
1) add a member variable in the dialog:
CBrush m_brush;
2) init in in OnInitDialog() :
m_brush.CreateSolidBrush(pApp->BK_COLOR);
3) in the destructor :
m_brush.DeleteObject();
4) modify your OnCtlColor() function :
HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor==CTLCOLOR_EDIT)
{
CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp();
pDC->SetBkColor(pApp->BK_COLOR);
pDC->SetTextColor(pApp->FG_COLOR);
return (HBRUSH)m_brush.GetSafeHandle();
}
return hbr; // why did you return NULL here ?
}
|
|
|
|
|
You need to change the brush.
1) add a member variable in the dialog:
CBrush m_brush;
2) init in in OnInitDialog() :
m_brush.CreateSolidBrush(pApp->BK_COLOR);
3) in the destructor :
m_brush.DeleteObject();
4) modify your OnCtlColor() function :
HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor==CTLCOLOR_EDIT)
{
CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp();
pDC->SetBkColor(pApp->BK_COLOR);
pDC->SetTextColor(pApp->FG_COLOR);
return (HBRUSH)m_brush.GetSafeHandle();
}
return hbr; // why did you return NULL here ?
}
|
|
|
|
|
Thank you Mr Anonymous, this works brilliant.
We have to change lots of dialog classes, is there a place, perhaps at the app level, we could create the solidbrush & it would work for all dialogs....
Currently, we are creating the brushes in each class, this works.
Again, Thanks.....
Gerry.
|
|
|
|
|
I'm desiging this program in C/C++ with my friend. We are just testing a concept we would like to get to work. All I want to happen... is the program connect to a website and find out if a file exists or not. If it does then it opens it. If not then it says it doesn't exist. One other thing, no mfc!! Is there any "simple" way to do this without have millions of classes and libraries designed to work with web browsers included in the program? Any help on this would be great, because we are relly stuck on this one.
|
|
|
|
|
Yes it can be done. You need to create a simple HTTP class that connects to a server and sends a GET request. The server will send back a standard HTTP response which you can parse to determine if the file exists or not. You will need to use winsock for the networking stuff.
There's a simple program called wget that does just that. I believe the source code is available.
|
|
|
|
|
Take a look at the "internet" functions like InternetConnect()
They don't use MFC, they uses Wininet, and works great
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Use this functions.
::InternetOpen();
::InternetConnect();
::FtpFindFirstFile();
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Hi,
I have a Listview where i have some 5 columns.In the first two columns i am supposed to put some bitmaps and again the bitmaps should be transparent.
I am not facing any problem in doing this.But when i select a particular row the bitmaps which are sitting there in the ListView columns are not looking transparent even though i mask it with the background color of the bitmap.The background of the bitmap takes the back color of the ListView window.
Could u please help me solving this problem.
Waiting for ur response.
Manohar Mishra
Digital India.Bangalore
|
|
|
|
|
What about some code?
|
|
|
|
|
Hi,
thanx for the quick reply.I am sending some portion of the code.
Here CTest1View is derived from CListView.The bitmap is a small red cicle , and the background is white.
Here is the code for the PreCreateWindow method
BOOL CTest1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style |= (LVS_SHOWSELALWAYS | LVS_REPORT );
return CListView::PreCreateWindow(cs);
}
Here is the code for the OnCreate method.
int CTest1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListView::OnCreate(lpCreateStruct) == -1)
return -1;
CListCtrl &lc = GetListCtrl();
LVCOLUMN lvCol;
LVITEM lvItem;
int n, x;
DWORD dwOldBits;
dwOldBits = lc.GetExtendedStyle();
dwOldBits |= LVS_EX_FULLROWSELECT;
dwOldBits |= LVS_EX_SUBITEMIMAGES | LVS_TYPEMASK;
dwOldBits |= LVS_EX_HEADERDRAGDROP |LVS_NOSCROLL;
// images in the subitems
lc.SetExtendedStyle(dwOldBits);
COLORREF crBkColor = ::GetSysColor(COLOR_WINDOW);
m_pDocImgLst = new CImageList();
BOOL bCreate = m_pDocImgLst->Create(22, 14, ILC_MASK, 2, 0);
CBitmap bmp;
int nImgIndx = -1;
bmp.LoadBitmap(IDB_BITMAP1);
n=m_pDocImgLst->Add(&bmp,RGB(255,255,255));
bmp.DeleteObject();
lc.SetImageList(m_pDocImgLst,LVSIL_SMALL);
for (int i = 0; i < 3; i++)
{
lvCol.mask = LVCF_IMAGE | LVCF_WIDTH|LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT;
lvCol.fmt = LVCFMT_BITMAP_ON_RIGHT;
lvCol.cx = 50;
lvCol.pszText = "aaa";
lvCol.iImage = 0;
lvCol.iOrder = 2;
int er = lc.InsertColumn(i,&lvCol);
}
for(int k=0;k<10;k++)
{
lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
lvItem.iItem = k;
lvItem.iSubItem = 0;
lvItem.cchTextMax = 50;
lvItem.iImage = 0;
lvItem.pszText = "Manohar";
lc.InsertItem(&lvItem);
}
LVITEM lvItem1;
for(int j=0;j<10;j++)
{
lvItem1.mask = LVIF_IMAGE |LVIF_TEXT;
lvItem1.iItem = j;
lvItem1.iSubItem = 1;
lvItem1.pszText = "ZZZZ";
lvItem1.iImage = 0;
lvItem1.state = 2;
lvItem1.stateMask = 2;
lc.SetItem(&lvItem1);
}
// TODO: Add your specialized creation code here
return 0;
}
Please let me know if this is not enough.....
Thanx again.......
Waiting for ur reply
|
|
|
|
|
Well, I'm not an expert of image lists, but did you try to create the image list from the bitmap directly?
Something like:
BOOL bCreate = m_pDocImgLst->Create(IDB_BITMAP1, 22, 0, RGB(255,255,255));
Paolo.
|
|
|
|