|
I have Tabctrl in a dialog.I want to set its background colour for each tab .I tried ON_WM_DRAWITEM but the control never comes in OnDrawItem().Can you help?
#define RED RGB(255,0,0)
#define YELLOW RGB(255,255,0)
#define MAGENTA RGB(255,0,255)
#define WHITE RGB(255,255,255)
#define BLUE RGB(0,0,255)
void CVMListDialog::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpdis)
{
CDialog::OnDrawItem(nIDCtl, lpdis);
char szTabText[100];
RECT rect;
UINT bkColor;
CBrush *cbr;
TC_ITEM tci;
CTabCtrl *pTabCtrl = (CTabCtrl *)GetDlgItem(IDC_TAB_VM);
if (pTabCtrl->m_hWnd == lpdis->hwndItem)
{
// which tab?
switch (lpdis->itemID)
{
case 0:
cbr = &m_brRed;
bkColor = RED;
break;
case 1:
cbr = &m_brYellow;
bkColor = YELLOW;
break;
case 2:
cbr = &m_brMagenta;
bkColor = MAGENTA;
break;
case 3:
cbr = &m_brWhite;
bkColor = WHITE;
break;
case 4:
cbr = &m_brBlue;
bkColor = BLUE;
break;
}
memset(szTabText, '\0', sizeof(szTabText));
tci.mask = TCIF_TEXT;
tci.pszText = szTabText;
tci.cchTextMax = sizeof(szTabText)-1;
pTabCtrl->GetItem(lpdis->itemID, &tci);
CDC *dc = CDC::FromHandle(lpdis->hDC);
dc->FillRect(&lpdis->rcItem, cbr);
dc->SetBkColor(bkColor);
TextOut(lpdis->hDC,
lpdis->rcItem.left,
lpdis->rcItem.top,
tci.pszText,
lstrlen(tci.pszText));
}
}
|
|
|
|
|
You must have set the "owner draw propery " dialouge proprty in your application either by dialouge wizard or by code.
notjing
|
|
|
|
|
Hello All;
i make a user control on c# using ultragrid control the problem is when i take the dll in order to use it in other projects the data doesnt appear, the grid reads the data from the data base
the code of the user control:
the grid name here is ulGrid
<br />
<br />
public partial class GridUserControl : UserControl<br />
{<br />
Infragistics.Win.UltraWinGrid.UltraGrid ulGrid = new UltraGrid();<br />
Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ulExcel = new UltraGridExcelExporter();<br />
Infragistics.Win.UltraWinGrid.UltraGridPrintDocument ulPrint = new Infragistics.Win.UltraWinGrid.UltraGridPrintDocument();<br />
<br />
<br />
bool GridRightLeft;<br />
string HeaderTitle;<br />
string HeaderRightDetails;<br />
string HeaderLeftDetails;<br />
<br />
public GridUserControl()<br />
{<br />
InitializeComponent();<br />
ulItasGrid.ContextMenuStrip = contextMenuStrip1;<br />
}<br />
<br />
public delegate void GridEventKeyDown(object sender,KeyEventArgs e);<br />
public delegate void GridEventKeyUp(object sender, KeyEventArgs e);<br />
public delegate void GridEventMouseDown(object sender, KeyEventArgs e);<br />
public delegate void GridEventMouseClick(object sender, KeyEventArgs e);<br />
<br />
<br />
<br />
<br />
public bool GridRightToLeft<br />
{<br />
set<br />
{<br />
GridRightLeft = value;<br />
}<br />
get<br />
{<br />
return GridRightLeft;<br />
}<br />
}<br />
<br />
<br />
public string LeftDetails<br />
{ <br />
set<br />
{<br />
HeaderLeftDetails = value;<br />
}<br />
get<br />
{<br />
return HeaderLeftDetails;<br />
}<br />
}<br />
public string RightDetails<br />
{<br />
set<br />
{<br />
HeaderRightDetails = value;<br />
}<br />
get<br />
{<br />
return HeaderRightDetails;<br />
}<br />
}<br />
DataTable dt = new DataTable();<br />
public DataTable DataTableSource<br />
{ set<br />
{<br />
ulGrid.DataSource = dt;<br />
}<br />
<br />
<br />
get<br />
{<br />
return dt;<br />
}<br />
<br />
}<br />
<br />
<br />
public object DataSource<br />
{<br />
get<br />
{<br />
return ulGrid.DataSource;<br />
}<br />
set<br />
{<br />
ulGrid.DataSource = value;<br />
<br />
try<br />
{<br />
ulGrid.DataBind();<br />
}<br />
catch (Exception ex)<br />
{<br />
throw new Exception(String.Format("Could not bind data to grid"));<br />
}<br />
}<br />
}<br />
<br />
public string DataMember<br />
{<br />
set { ulGrid.DataMember = value; }<br />
get { return ulGrid.DataMember; }<br />
<br />
}<br />
<br />
<br />
<br />
public string HeaderReport<br />
{<br />
set<br />
{<br />
HeaderTitle = value;<br />
}<br />
get<br />
{<br />
return HeaderTitle;<br />
}<br />
}<br />
<br />
public AutoFitStyle AutoFit<br />
{<br />
set<br />
{<br />
this.ulItasGrid.DisplayLayout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.ResizeAllColumns;<br />
}<br />
get<br />
{<br />
return this.ulItasGrid.DisplayLayout.AutoFitStyle;<br />
}<br />
}<br />
<br />
public Color Appearance<br />
{<br />
set<br />
{ <br />
this.ulItasGrid.DisplayLayout.Appearance.BackColor = Color.White;<br />
}<br />
get { <br />
return this.ulItasGrid.DisplayLayout.Appearance.BackColor;<br />
}<br />
}
and the code of the connection class for testing the grid:
<br />
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Data.SqlClient;<br />
using System.Configuration;<br />
using System.Data;<br />
<br />
<br />
namespace testthegrid<br />
{<br />
class Connection<br />
{<br />
SqlConnection ConnectionStr = new SqlConnection();<br />
<br />
public Connection()<br />
{<br />
ConnectionStr.ConnectionString = "Data Source=.; Initial Catalog=GridExample;Integrated Security=SSPI";<br />
}<br />
<br />
public SqlConnection conn<br />
{<br />
get<br />
{<br />
return this.ConnectionStr;<br />
}<br />
set<br />
{<br />
this.ConnectionStr = value;<br />
}<br />
}<br />
<br />
<br />
public void OpenConnection()<br />
{<br />
if (ConnectionStr.State != ConnectionState.Open)<br />
ConnectionStr.Open();<br />
}<br />
<br />
<br />
public void CloseConnection()<br />
{<br />
try<br />
{<br />
if (ConnectionStr.State != ConnectionState.Closed)<br />
ConnectionStr.Close();<br />
}<br />
catch { }<br />
}<br />
}<br />
}<br />
and the code for testing the grid is:
<br />
<br />
namespace testthegrid<br />
{<br />
public partial class Form1 : Form<br />
{<br />
private Connection connection = new Connection();<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
FillGrid();<br />
}<br />
private void FillGrid()<br />
{<br />
connection.OpenConnection();<br />
DataTable dt = new DataTable();<br />
SqlDataAdapter da = new SqlDataAdapter("select * from AccountInfoA", connection.conn);<br />
da.Fill(dt);<br />
gridUserControl1.DataTableSource = dt;<br />
connection.CloseConnection();<br />
<br />
}<br />
there is no data appears in the grid
thanx a lot
|
|
|
|
|
beesan wrote: i make a user control on c#
If your question is related to C#, then please use the C# forum, not the C++ forum. Thanks.
|
|
|
|
|
hello,
i want to set the value of the ip address control from a string, say ip[100] which is read from a text file.
how this can be done ?
the text file contains ip like --- 127.0.0.1 or 111.111.11.1
|
|
|
|
|
ULONG ulP = inet_addr(szIPAddress );
|
|
|
|
|
i dont get, please explain.
i am using this code but it makes the mfc application crash.
len = strlen(fff);
if(strlen(fff) > 0 && strcmp(fff, "\n") != 0)
{
while(fff[i] != '.')
{
c[j] = fff[i];
j++;
i++;
}
m1 = atoi(c);
j = 0;
i++;
ZeroMemory(c, 3);
while(fff[i] != '.')
{
c[j] = fff[i];
j++;
i++;
}
m2 = atoi(c);
j = 0;
i++;
ZeroMemory(c, 3);
while(fff[i] != '.')
{
c[j] = fff[i];
j++;
i++;
}
m3 = atoi(c);
j = 0;
i++;
ZeroMemory(c, 3);
while(len > i)
{
c[j] = fff[i];
j++;
i++;
}
m4 = atoi(c);
j = 0;
i++;
ZeroMemory(c, 3);
ipAdd.SetAddress(m1, m2, m3, m4);
}
|
|
|
|
|
You may be over complicating the conversion of the 4 number parts of the IP address.
Try this instead:
int m1,m2,m3,m4;
sscanf(fff,"%d.%d.%d.%d",&m1,&m2,&m3,&m4);
ipAdd.SetAddress(m1,m2,m3,m4);
Of course, you'll need to validate the IP address is in the proper format.
|
|
|
|
|
this method shows wrong ip in the ip address control.
|
|
|
|
|
The variable fff must be a string only containing a valid IP address.
try this:
LPSTR lpIPAddress = _T("127.0.0.1");
int m1, m2, m3, m4;
sscanf(lpIPAddress,"%d.%d.%d.%d",&m1,&m2,&m3,&m4);
ipAdd.SetAddress(m1,m2,m3,m4);
Make sure you're passing in just the IP address in the sscanf function.
|
|
|
|
|
it is working now. since i am using
fileh.ReadString((LPTSTR)fff , 100);
therefore i have to use the following code for the correct result ---
swscanf((LPCTSTR)fff,_T("%d.%d.%d.%d"),&m1,&m2,&m3,&m4);
thanks for the help.
|
|
|
|
|
You're welcome! Glad you got it working.
|
|
|
|
|
I assume you are talking about CIPAddressCtrl .
The method CIPAddressCtrl::SetAddress take 4 BYTE parameters (see : doc on MSDN[^])
So, you will need to extract each "part" from the string and convert each substring to a BYTE. (manually or int_addr[^])
This signature was proudly tested on animals.
|
|
|
|
|
Hello,
I have a program that has a dialog box - call this 'box1' on top of another dialog.
I want to create a 'box2' that will have some of the same buttons as 'box1' and perform the same actions - don't ask why i need to do this!
What i think is that making box2 a 'child' / derived class of box1 will be the best idea.
What i want to do is tell the program, when button 'my buttonbox2' is clicked in box2 it just goes to the 'mybuttonbox1' in box1 and carries out that process.
I understand all the class and derived class things in C++, and I understand all the OnBtnClicked stuff etc... i'm just having a hard time with my limited knowledge to connect standard C++ with MFC!
If anyone can help I would be very grateful. Thankyou.
|
|
|
|
|
You wan to relay events from your second message box to the first one? So for example if you click a button on your second dialog you want the first dialog class' instance to handle it?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Pretty much, yes.
Basically my 1st box has for example:
void Cbox1dlg::onbtnplay
{
// box 1 onbtnplay process information
}
I want my second box void Cbox2dlg::onbtnplay to just point back to box1 and do 'box1 onbtnplay process'
Thanks
|
|
|
|
|
If it is only a few buttons AND in your second dialog you know the handle of the first one (for example it is its parent) then you can try simply relaying all the command messages to the first dialog, if this suits your needs or not i can't tell of course.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Thanks for that,
I think that would be right for my needs,
the problem is, i have not been able to work out the actual code to relay back to the 1st dialog, I could do this in standard C++, but with MFC macros I'm sure how to go about actually coding it...
Could you (or anyone else reading this) give me an example code to relay the buttonclick back to the 1st dialog button click?
Sorry, i'm quite new to MFC, and i'm not sure quite how to treat the macros in it as opposed to standard 'int's' or something.
Thankyou very much for your help. (and yes, its only a few buttons - probably 3or 4).
|
|
|
|
|
Does your second dialog know of the first dialog? Is it its parent for example? Then you could try overwriting the OnCommand[^] method of the second dialog's class (it doesn't even have to be a subclass of the original dialog's class). So something like this:
BOOL CMySecondDialog::OnCommand(WPARAM wParam, LPARAM lParam)
{
GetParent()->SendMessage(WM_COMMAND, wParam, lParam);
return TRUE;
} Of course this carries some risks...a more safer aproach is maybe adding message handlers to your buttons and then relaying the events from there. Since we are talking about a few buttons only, it should be easy:
BEGIN_MESSAGE_MAP(CMySecondDialog, CDialog)
ON_COMMAND(IDC_FIRSTBUTTON, OnFirstButton)
ON_COMMAND(IDC_SECONDBUTTON, OnSecondButton)
...
END_MESSAGE_MAP()
void CMySecondDialog::RelayCommand(UINT nID)
{
GetParent()->SendMessage(WM_COMMAND, nID, 0);
}
void CMySecondDialog::OnFirstButton()
{
RelayCommand(IDC_FIRSTBUTTON);
}
void CMySecondDialog::OnSecondButton()
{
RelayCommand(IDC_SECONDBUTTON);
}
I am not completely sure i understood your situation correctly though...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Thats really great, thanks... I think you've understood what i want to do, that looks reasonable to me.
I didn't know about the RelayCommand, so thats really helped!
Thankyou very much.
Penfold.
|
|
|
|
|
1. Write a C program to read a list of books from a file and create a linked list to store them. The purpose of this program is to keep track of the books kept in a shelf. The shelf is a three-tier shelf and each tier can store up to 4500 pages maximum. The books are kept in alphabetical order (ascending).
do u all know about this question ?pls help
|
|
|
|
|
we don't do the homeworks or assignments. we are way past from that stage.
If you can start and are stuck somewhere, someone may help you.
On another note - Can I politely ask you to read the forum guidelines/rules?
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
funjoke88 wrote: do u all know about this question ?
I do now.
|
|
|
|
|
Please read the posting guidelines here[^]. Pay special attention to points 2,3 and 10.
|
|
|
|
|
It's called "homework". It seems to me that if you were given that assignment, then the instructor probably gave you everything you need to implement a solution. That's what I know about it.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|