|
Is there an easy way to display text ontop of a dialog bar? I have noticed that to simply display the percent complete, the projects shown here on code project do a whole bunch, including adding a seperate class to avoid flickering. It really shouldn't be this hard IMHO...
- John
|
|
|
|
|
I wanted to write a contact manager system but amhaing problems linkint it all up, at the moment I have two main classes -
CPerson - info about a contact
CDatabaseConn - Database functionality
When the user clicks on a button (from within the view) I wanted to know what the best way of getting in all of the contact info into a list in the iew. There are many ways I can see:
1. Overload << in the CPerson class to make the database connection and generate a linked list and pass this back from the view.
2. Instantiate a database connection and then some person objects and get them one by one.
And many other ways I can think of now. I dont know what to have an instance of where.
I hope people can help as Im sure people have these same kind of problems when learning. Also, is there a kind of ystem/approach or tool we can use when doing this...
thanks
|
|
|
|
|
Always I instantite de database clase in the CwinApp class, because this class is easy to access from all others classes.
And I prefer to put in that class all my publics variables, like connection status, user, etc.
Carlos Antollini.
|
|
|
|
|
I have a textbox on the toolbar. Everytime i start the program or go back to the main window, it will be highlight(because there is "ENTER COMMAND HERE" and highlight all these text so that we don't have to delete these string and enter the command). However, sometimes the user can type something, but then do something else, then the textbox will lose focus. If I want to type the command again, i have to use a mouse to highlight the text inside......not very convenient.
Does anyone know how to make it "ALWAYS" highlighted or when the mouse click that textbox, it highlights everything itself. I've tried using message "LBUTTONDOWN" in the view and frame class. It works when i click in the output area, but when i click the tool bar or menu, no highlight.
thanks!!!!
|
|
|
|
|
Does anyone know how to make it "ALWAYS" highlighted or when the mouse click that textbox, it highlights everything itself.
To keep the text highlighted when the control does not have the focus, set the ES_NOHIDESEL style.
When the edit box gets the focus, it sends EN_FOCUS to its parent. You can handle this notification and call SetSel() to select all the text in the control.
--Mike--
http://home.inreach.com/mdunn/
"You named the Borg... Hugh?"
-- Guinan
|
|
|
|
|
Hi,
I have a problem using private temporary tables, from VC.
The Private table is supose to remain throughout the session.
I can create one fine, but i can't access it! If I was to convert my code to use a global temporary table, it works fine.
Anyone offer any advice:
SQLHSTMT hStmt;
SQLAllocHandle(SQL_HANDLE_STMT, m_hDbc, &hStmt);
// Prepare the SQL statement
SQLCHAR szS[] = "create table #test(val integer)";
SQLPrepare(hStmt,szS,strlen((char*)szS));
nResult = SQLExecute(hStmt); <- Work Fine
SQLFreeHandle(SQL_HANDLE_STMT,hStmt);
SQLAllocHandle(SQL_HANDLE_STMT, m_hDbc, &hStmt);
//Ensure That The User Has Not Already Assigned A ReadCode To This Phrase.
SQLCHAR szCheckPresenceSQL[] = "SELECT * FROM #test ";
SQLPrepare(hStmt,szCheckPresenceSQL,strlen((char*)szCheckPresenceSQL));
nResult = SQLExecute(hStmt); //FAILS GET -1
Cheers
Richard
|
|
|
|
|
Your problem is no in VC. Is in SQL Server.
The Temporary tables only exist for the transaction, when you use a temporary table with # this table is droped for the system when you finish the transaction.
In your Application you are usin two transactions, The create if the table and the select from that table.
Is better to use a Stored Procedure, where the table exists only during the execution of the Store, and put de create and select in the store or
you need tu create a global temporary table with ##, this type of table are droped for the system when the user is disconnected.
Do you Understand?
Good Luck
Carlos Antollini.
|
|
|
|
|
I believe SQLEXECUTE Actually creates a stored procedure to cope with the binding of parameters. By using SQLEXECDIRECT the problems solved. And The table is visible through the current session
Richard
|
|
|
|
|
Anyone out there that knows how to get the MX Records for a domain name. Is there any standard win32 functions for that?
I have been looking at gethostbyname(), but it doesn't seem to do what I need, it just get's the IP Address.
I could write all the socket stuff to talk with a DNS Server myself, but if there's allready a way to do it, it would be kinda waste of time...
I have the same problem with Reverse Lookup...
Any ideas?
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
I found out my self.
I found windns.h, which only works for win2k, but in the application I work on we only support Win2k or later...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Hi,
I'm tying to implement some code to restrict the charcters that can be entered into an edit control.
I'm handling the EN_UPDATE message, using CEdit::GetSel to work out where the cursor currently is, checking the charcter prior to the cursor to see if it's allowed. If it isn't, i remove it, and then update the controls contents. When I update the contents, I want to put the cursor back where it was. How?
I tried this:
void CContactDlg::OnUpdateEdit1()
{
// TODO: Add your control notification handler code here
CString m_text;
m_Number1.GetWindowText(m_text.GetBuffer(1024),1024);
m_text.ReleaseBuffer(-1);
int a,b;
m_Number1.GetSel(a,b);
// a is where the cursor is
// i want to place the cursor at (a-1)
m_Number1.SetSel(a-1,a-1,FALSE);
}
This code puts the cursor at the beginning of the line. How can I implement this?
|
|
|
|
|
I beleive you problem is the GetSel is not returning what you think.
Try m_Number1.SetSel(0, m_Number1.LineLenght(-1),TRUE);
Your name implies this is a number only edit box. If that is true have you tried the ES_NUMBER style?
|
|
|
|
|
Ok, this one gets even more wierd now. I'm not using ES_NUMBER because i need to allow a "+" charcter as well (it's for a telephone number in international format).
Tracing through the steps in a debug, the most wierd thing is happening. This is the code for the function that handles the EN_UPDATE message (with line numbers for clarity).
1 CString m_text;
2 m_Number1.GetWindowText(m_text.GetBuffer(1024),1024);
3 m_text.ReleaseBuffer(-1);
4
5 int a,b;
6 m_Number1.GetSel(a,b);
7
8 char new_char;
9 if (m_text.GetLength() > 0) {
10 new_char=m_text.GetAt(a-1);
11 if ( ((new_char < '0') || (new_char > '9')) && (new_char != '+') ) {
12 CString s;
13 s=m_text.Left(a-1);
14 m_Number1.SetWindowText("hello does this work?");
15 m_Number1.SetSel(1,1,FALSE);
16 }
17 }
Ok. Please don't complain about the poor coding style!
Imagine i fill the edit with "1111a", and break at the EN_UPDATE message that entering the "a" character triggered.
m_Number1 is the CEdit bound to the control through classwizard.
lines 1-3 fill m_text with the current text. line 6 fills a with the cursor position.
line 10 puts the charcter to the left of the cursor (the one that was just entered) into new_char.
the if block on line 12 happens if the last character was in invalid one... when i get to line 14, s contains "1111".
This is where the wierdness starts... line 14, when run, does nothing, and the program pointer jumps to line 9. At this point variable a has been set to 0, and therefore i get a debug assertation failure at line 10.
Why on earth is SetWindowText failing to do anything? and why does the program pointer get moved mysteriously?
I can supply the source to the project if it would help.
Please help me!
|
|
|
|
|
You're going about it the wrong way. When the user hits a key, the edit box gets a WM_CHAR message. Handle that message and throw away any characters you don't want to be entered:
void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if ( (nChar >= '0' && nChar <= '9') || nChar == '+' || nChar == '\010' )
CEdit::OnChar(nChar, nRepCnt, nFlags);
} ('\010' is backspace)
--Mike--
http://home.inreach.com/mdunn/
"You named the Borg... Hugh?"
-- Guinan
|
|
|
|
|
That is correct.
As you say this edit box is for phone numbers I would consider using a masked edit control and avoiding the mess all together.
|
|
|
|
|
Hi, I happened to write some months ago a CEdit-derived control for this purpose. Unfortunately, it is in Spanish, but I hope you can find it useful nevertheless.
The way to go definitely is OnUpdate, as WM_CHAR messages are not always sent (if, for instance, you paste a piece of text from the clipboard).
The code I'm sending does a little more than you need. The BOOL variable modo_lista sets a "list mode" in which you can enter more than one tlf number separated by commas or semicolons.
A valid tlf number (as implemented by my control) has the following syntax: an optional beginning '+' followed by one or more digits, arbitrarily decorated with spaces, '-' and '.', and parentheses. Parentheses are not allowed to nest. Considering this sintax, a tlf number not completely written could not be valid, if no digit has been entered. You can check whether the number introduced so far is actually a valid tlf number (or a list of them if modo_lista==TRUE) by calling CNumTlfEdit::numero_valido().
Hope it helps. It must be easy to change the code to suit your particular needs. If this prove useful and people request, maybe I'll translate to English and make an article with it.
Regards,
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
NumTlfEdit.h
#if !defined(AFX_NUMTLFEDIT_H__4ECA6D61_8551_11D2_8DC1_0000E2140DA0__INCLUDED_)
#define AFX_NUMTLFEDIT_H__4ECA6D61_8551_11D2_8DC1_0000E2140DA0__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
class CNumTlfEdit : public CEdit
{
public:
CNumTlfEdit(BOOL modo_lista=FALSE);
public:
public:
public:
BOOL numero_valido(void);
virtual ~CNumTlfEdit();
protected:
afx_msg void OnUpdate();
DECLARE_MESSAGE_MAP()
BOOL modo_lista;
};
#endif // !defined(AFX_NUMTLFEDIT_H__4ECA6D61_8551_11D2_8DC1_0000E2140DA0__INCLUDED_)
NumTlfEdit.cpp
#include "stdafx.h"
#include "NumTlfEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CNumTlfEdit::CNumTlfEdit(BOOL modo_lista)
: modo_lista(modo_lista)
{
}
CNumTlfEdit::~CNumTlfEdit()
{
}
BEGIN_MESSAGE_MAP(CNumTlfEdit, CEdit)
ON_CONTROL_REFLECT(EN_UPDATE, OnUpdate)
END_MESSAGE_MAP()
#define ES_NUMERO(ch) ((ch)>=TCHAR('0')&&(ch)<=TCHAR('9'))
void CNumTlfEdit::OnUpdate()
{
CString str,str_formateada;
BOOL hubo_fallos=0;
BOOL signo_mas=FALSE;
BOOL dentro_parentesis=FALSE;
BOOL ultimo_numero=FALSE;
BOOL hubo_numero=FALSE;
int comienzo_sel,fin_sel;
GetWindowText(str);
GetSel(comienzo_sel,fin_sel);
for(int i=0;i<str.GetLength();i++){
if(str[i]==TCHAR(' ')){
}
else if(ES_NUMERO(str[i])){
signo_mas=TRUE;
ultimo_numero=TRUE;
hubo_numero=TRUE;
}
else if(str[i]==TCHAR('+')){
if(signo_mas){
hubo_fallos=TRUE;
if(i<comienzo_sel){
comienzo_sel--;
fin_sel--;
}
continue;
}
else{
signo_mas=TRUE;
ultimo_numero=FALSE;
}
}
else if(str[i]==TCHAR('-')||str[i]==TCHAR('.')){
if(!ultimo_numero){
hubo_fallos=TRUE;
if(i<comienzo_sel){
comienzo_sel--;
fin_sel--;
}
continue;
}
else{
signo_mas=TRUE;
ultimo_numero=FALSE;
}
}
else if(str[i]==TCHAR('(')){
if(dentro_parentesis){
hubo_fallos=TRUE;
if(i<comienzo_sel){
comienzo_sel--;
fin_sel--;
}
continue;
}
else{
dentro_parentesis=TRUE;
signo_mas=TRUE;
ultimo_numero=FALSE;
}
}
else if(str[i]==TCHAR(')')){
if(!dentro_parentesis){
hubo_fallos=TRUE;
if(i<comienzo_sel){
comienzo_sel--;
fin_sel--;
}
continue;
}
else{
dentro_parentesis=FALSE;
signo_mas=TRUE;
ultimo_numero=FALSE;
}
}
else if(modo_lista&&(str[i]==TCHAR(',')||str[i]==TCHAR(';'))){
if(dentro_parentesis||!hubo_numero){
hubo_fallos=TRUE;
if(i<comienzo_sel){
comienzo_sel--;
fin_sel--;
}
continue;
}
else{
signo_mas=FALSE;
dentro_parentesis=FALSE;
ultimo_numero=FALSE;
hubo_numero=FALSE;
}
}
else{
hubo_fallos=TRUE;
if(i<comienzo_sel){
comienzo_sel--;
fin_sel--;
}
continue;
}
str_formateada+=str[i];
}
if(hubo_fallos){
MessageBeep(MB_ICONEXCLAMATION);
SetWindowText(str_formateada);
SetSel(comienzo_sel,fin_sel);
}
}
BOOL CNumTlfEdit::numero_valido()
{
CString str;
BOOL hay_numeros=FALSE;
GetWindowText(str);
for(int i=0;i<str.GetLength();i++){
if(ES_NUMERO(str[i])){
hay_numeros=TRUE;
break;
}
}
return hay_numeros;
}
|
|
|
|
|
IN a program I am implementing I can see a graphic with different type of lines (PS_SOLID,PS_DOT), etc but when I try to print it the dot lines appear like solid. Which could be the problem?
|
|
|
|
|
Has anybody a code example for a dialog like the 'map network drive' of the explorer?
I need it to map a network drive in my own MFC application.
I need no shell command i.e. 'net use' but the MFC-Control (or is it an Active-X).
Thanks.
|
|
|
|
|
You could shell execute the "net use" command.
ie, net use r: \\mymachine\c$
|
|
|
|
|
I've been working on quite a big database project and after a while i decided to start using CRecordsets for my database communication. Unfortunately I have had some problems with adding and updating entries. Selecting entries works fine though.
To simplify my problems I decided to create a new small database program using the class application wizard. The structure of this small testprogram is the same as my larger program, but without all the irrelevant parts. The strange thing is that this small program is working. I have no problem with adding new entries or updating existing ones.
After this discovery I started looking for differences between the two programs but I found none that I could see would make a difference. I started using the canUpdate and canAppend methods on my CDatabase and CRecordset objects and I noticed that both program's database objects are updatable, but only my new testprogram's recordset are updatable and appendable.
Here's some code from my large program:
CRSAAtgard rsaAtgard(pDB);
CString filter;filter.Format("BesiktningId=%d AND AtgardskodId=%d", besiktningId, atgardskodId);
rsaAtgard.m_strFilter = filter;
rsaAtgard.Open(CRecordset::snapshot, NULL, CRecordset::none);
if (pDB->CanUpdate())
AfxMessageBox("DB is updatable!"); // True
if (rsaAtgard.CanUpdate())
AfxMessageBox("rsaAtgard is updatable!"); // False
if (rsaAtgard.CanAppend())
AfxMessageBox("rsaAtgard is appendable!"); // False
The same if-statements in my testprogram all evaluate to true. The database are the same for the two programs. The tables differ though, even if they are very similiar.
One thing that I don't know if it related to this problem is that my testprogram displays an odbc dialog before opening the recordset, even though the odbc-connection string has been specified inside the program, and the database connection established without any problems.
I know this problem may be hard to solve without having more of the code to look at, but maybe someone has had about the same problems and could give me a hint what to look for. It would surely save my day and besides it might even help against my MFC related headache. =)
Thanks a lot,
Jimmy Ehrnström
P.s. Sorry about some of the variables having swedish names. I guess it won't make much difference though. D.s.
|
|
|
|
|
What type of back end database is in use?
Since the two programs go after different tables, is this maybe a permissions difficulty? Check for any permission differences.
What is the specific problem with adding or updating entries. Does the code say the changes were successfull, but checking the data afterwards shows no change? Or is there some kind of error message?
Chris
|
|
|
|
|
Try to programatically add a record, even if the recordset says you cannot. Do it in a try/catch block, and report the error from the catch. This should give you the exact error that is happening:
try
{
myRecordset.AddNew();
}
catch (CDBException* pDx)
{
pDx->ReportError(MB_OK);
pDx->Delete();
}
//assign the field values here
try
{
myRecordset.Update();
}
catch (CDBException* pDx)
{
pDx->ReportError(MB_OK);
pDx->Delete();
}
|
|
|
|
|
Thanks for your advice. I did add the try/catch blocks as you suggested and at the addNew() statement I caught an exception stating that the recordset is readOnly. I have no idea why that is but maybe it's because of some setting in the database table. I will try using my test table in my real program and see if that solves the problem.
I assume that it's the recordset/table that's giving me problems, since all tests on my database object indicates that it is both open and updatable.
|
|
|
|
|
I'm working against Microsoft SQL Server. I'm not sure about what version but I think it's 7.0.
I think you might be on to something about different permissions. I tried using my test recordset, working on another table, in my real program and it still works there. At least it's updatable and appendable. Before this I was quite sure there were no permission differences, but now I'm not sure. I have to look into that.
With my original recordset, when ignoring the fact that the methods CanAppend() and CanUpdate() returns false, I get an exception at the AddNew() statement, indicating that the recordset is readOnly.
I appreciate your effort in trying to help me. I really needed some new ideas for what might be wrong and now you've given me some to look into. Thanks!
|
|
|
|
|
Check that the database class is open with the proper ODBC connection. Check the CDataBase.Open function
|
|
|
|
|