|
I am not really and MFC pro either, but perhaps I can grant more insight of what is happening to you.
If you are creating a dialog-based solution, you can use the Dialog Data Exchange to bind a CString object into the contents of the edit box. Then, calling UpdateData(TRUE) would copy the contents of the edit box into the CString variable. Calling UpdateData(FALSE) would update the controls from the variables.
After this, you can use the previously posted method to update the static control's text, issuing the name of CString object as a parameter to the SetWindowText method.
Here is a hands-on example on how it might be implemented:
CString m_csEditBoxText;
CStatic m_StaticControl;<DIV>
.... <DIV>
void CMyDialog::DoDataExchange( CDataExchange* pDX )
{
DDX_Text( pDX, IDC_EDIT_CONTROL_ID, m_csEditBoxText );
DDX_Control( pDX, IDC_STATIC_CONTROL_ID, m_StaticControl );
}<DIV>
.... <DIV>
void CMyDialog::OnClickButtonX( someParams )
{
UpdateData(TRUE);<DIV>
m_StaticControl->SetWindowText( m_csEditBoxText );<DIV>
UpdateData(FALSE);<DIV>
} This implementation should work, assuming you have given an identifier to both the edit box and the static control (all static controls default to having IDC_STATIC as their identifier). Then put these identifiers into the dialog data exchange routine. I have not tested it, but if it does not work, then use the implementation given in the previous post to update the static control's caption, removing the lowest two code lines from the button click handler.
Hope this will help you out
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thanx Guys. I'm on my way out(I have some work I have to go take care of), when I get back I'll try it out and tell you how it comes out. Thanx again, I appreciate it.
One thing I'm having trouble with is getting the data(numbers) from an edit box and turning that into a float variable.(it's for a math equation). Thanx again.
|
|
|
|
|
I did have to change some things around but it worked well. I got the program to do almost everything I wanted it to do. I can't thank you enough for your help. It took me a while but once I figured things out I felt like a compelete idiot. If you just happen to be curios about how I did it and what I changed just email me and put C++ in SBJ line other wise I will probably delete it.
|
|
|
|
|
Hi
I want to create a tab control in such a wany that when user drags the tab button it should display it as separate dialog box. Also if user drags a dialog box on to that, it should set as a tab button. Any idea how this can be done?
Regards
Neha
|
|
|
|
|
You must do it completely yourself.
You could see the MFC source code of the CWnd class for the basic window functionality. For the docking stuff, always when your window is moved near enough to the docking area, the drag rectangle is forced to a certain place/size and is not moved with the mouse until the cursor is enough far away from the 'zone'.
For the tab controls, whenever the window is in the zone, you create a new rectangle that looks like a tab. Then you place this 'outlined' tab control next to the existing ones. If user releases the mouse button while in this mode, a new tab page gets created.
Basically, what you are asking has not been implemented yet, so there is little ready source code available. You must gather bits and pieces, experiment and succeed through trial & error.
Best of luck, though..
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi,
I was thinking to do the same.
Please, if you do any code for it, even not perfect, can you send it to me ( if yes I will give you my email address ) ?
If I will implement on my side I can give my code to you. Unfortuantely though, I am using the VCF library ( which makes this work much simpler than using MFC ), so I am not sure my code will fit your needs.
Cheers,
Marcello
|
|
|
|
|
I want to initialize a executable, making OS to search for the file. I am not able to resolve the error in 5th parameter.
STARTUPINFO si = {sizeof(si)};<br />
PROCESS_INFORMATION pi;<br />
TCHAR szCommandLine[1024] = {0},*pszCommandLine = 0;<br />
<br />
DWORD lFileName = <br />
SearchPathW(NULL,(LPCWSTR)"YPager",(LPCWSTR)".exe",(DWORD)sizeof(szCommandLine), szCommandLine, *pszCommandLine);<br />
<br />
BOOL bCreate = CreateProcessNULL,szCommandLine,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
The error is: 'SearchPathW' : cannot convert parameter 5 from 'char [1024]' to 'unsigned short *'.
Cheers!
Siddharth
|
|
|
|
|
Hello!
This is because you are calling Unicode version (SearchPathW). Use SearchPath or SearchPathA for non-Unicode version.
If parameter 5 is 'char [1024]' then TCHAR is defined as char, so _UNICODE is not defined.
Have a nice day or night
|
|
|
|
|
It's not working even with SearchPath(). There is no compiler error as such but the thing is not execeuting. Any other suggestion for solving the problem
|
|
|
|
|
Tell me exactly what you want to do. You want to locate executable file which is on system path? Or acquire path to executable which is currently running under the debugger?
|
|
|
|
|
I want to loacte executable where ever it is on the Harddisk. Thing is I am not sure whether exe will be in System Directory or Program Files.
Hence Search for the file on My Computer kind of thing.
Waiting for reply.
Cheers!!!
Siddharth
|
|
|
|
|
So you should not use SearchPath()
Use either SHFindFiles or locate the file by yourself, by traversing directories, and using FindFirstFile, FindNextFile.
Search path searches for file in:
1) The directory from which the application loaded.
2) The current directory.
3) The system directory. Use the GetSystemDirectory function to get the path of this directory.
4) The 16-bit system directory. There is no function that retrieves the path of this directory, but it is searched.
5) The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
6) The directories that are listed in the PATH environment variable.
These are not all directories for sure
|
|
|
|
|
That's very nice of you. These are very valuable suggestions. But do U agree with my thinking? Or can U suggest something better then that.
|
|
|
|
|
Hi all,
this is one of my first posts here. Hello.
I am into photography, and i want to write maybe an MFC application or something that does the following:
-take in a directory
-for each jpg in this directory, add a watermark to it
by watermark I mean a signature that shows that picture is mine.
do you guys know if this is possible?
thanks!
|
|
|
|
|
download cximage from here
add 3 (maybe 4) lines of code
voila
"there is no spoon" biz stuff about me
|
|
|
|
|
Hi,
I need to write a small program that backs up a Microsoft Access database in a specific way, and wondered if anybody here could offer me a little help.
Basically, this is what the program needs to do:
1) Copy the original database (.mdb file) to a different folder (the backup folder).
2) Change the database password of the backed up version (the backup needs a different password).
3) Set the properties of the backed up password to "Read-only".
1) and 3) are easy, but 2) is giving me problems. At the moment I have to do this manually at the end of each day - by opening the copy using "Exclusive access", unsetting and then resetting the database password. Essentially I just want to write a program to automate this process and save me time at the end of each day.
I am hoping that there is some way to automate step 2. If this is a really basic question, please accept my apologies. I have written a few basic C/C++ and WinAPI programs, but I have never interfaced with Access from another program.
Many thanks for any help or pointers,
KB
|
|
|
|
|
You might try posing question #2 to the folks in the Access section at http://www.mvps.org/[^].
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Hello,
I'm using the NMLVCUSTOMDRAW (Custom Draw) option in my CListView. During drag/drop, I would like to draw an icon indicating where in the list the drop will insert. I have successfully drawn the icon when cursor is over a list-item, but I cannot get the icon to be erased once the cursor leaves the list item (eventually causing all list items to have this icon---I only want one at a time). I tried to invalidate the 'last' list item's rect, but this caused too much flicker. I tried to find internet examples, but could only find code that entirely drew itself with no help from the MFC CListView (don't want to do that much work).
Does anyone have any suggestions or pointers to helpful code?
thanks! JennyP
|
|
|
|
|
My application works just fine with Access and SQL server2000,but when i use FoxPro as Data Source i can't AddNew,Update or Delete record.
I dont recive eny errors from database.
is my Connection string OK?
Code Example:
//////////////////////////////////////////
#define INITGUID
#import "C:\Program Files\Common Files\System\ADO\msado15.dll"\
rename_namespace("ADOCG")\
rename("EOF", "EndOfFile")
using namespace ADOCG;
#include <stdio.h>
#include "icrsint.h"
class CADORazmena : public CADORecordBinding
{
BEGIN_ADO_BINDING(CADORazmena)
ADO_VARIABLE_LENGTH_ENTRY2(1,adVarChar, m_ID,sizeof(m_ID),lIDStatus,TRUE)
ADO_VARIABLE_LENGTH_ENTRY2(2,adVarChar, m_Garderoba,sizeof(m_Garderoba),lGarderobaStatus, TRUE)
END_ADO_BINDING()
public:
CHAR m_ID[50];
ULONG lIDStatus;
CHAR m_Garderoba[50];
ULONG lGarderobaStatus;
////////////////////////////////////////////////////
Document class
////////////////////////////////////////////////////
BOOL CKucniBudget2004Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// IDBInitialize* pIDBInitialize = NULL;
m_strConection=_T("Provider=vfpoledb;Data Source=c:\\data\\simpoz.dbc;");
m_strCmd=_T("select * from Kupci");
m_pRs = NULL;
m_piAdoRecordBinding = NULL;
// Initialize the COM environment
::CoInitialize(NULL);
try
{
// Create the record set object
m_pRs.CreateInstance(__uuidof(Recordset));
// Open the record set object
m_pRs->Open((LPCTSTR)m_strCmd, (LPCTSTR)m_strConection,
adOpenDynamic, adLockOptimistic, adCmdUnknown);
// Get a pointer to the record binding interface
if (FAILED(m_pRs->QueryInterface(__uuidof(IADORecordBinding),
(LPVOID *)&m_piAdoRecordBinding)))
_com_issue_error(E_NOINTERFACE);
// Bind the record class to the record set
m_piAdoRecordBinding->BindToRecordset(&m_rsRecSet);
// Get a pointer to the view
POSITION pos = GetFirstViewPosition();
CKucniBudget2004View* pView = (CKucniBudget2004View*)GetNextView(pos);
if (pView)
// Sync the data set with the form
pView->RefreshBoundData();
}
// Any errors?
catch (_com_error &e)
{
// Display the error
GenerateError(e.Error(), e.Description());
}
return TRUE;
}
void CKucniBudget2004Doc::AddNew()
{
try
{
m_piAdoRecordBinding->Update(&m_rsRecSet);
if(m_pRs->Supports(adAddNew))
{
CreateBlankRecord();
m_piAdoRecordBinding->AddNew(&m_rsRecSet);
m_pRs->MoveLast();
}
}
catch (_com_error &e)
{
GenerateError(e.Error(),e.Description());
}
}
void CKucniBudget2004Doc::CreateBlankRecord()
{
CString strBlank=" ";
// COleDateTime dtBlank;
strcpy(m_rsRecSet.m_ID,(LPCTSTR)strBlank);
strcpy(m_rsRecSet.m_Garderoba,(LPCTSTR)strBlank);
}
void CKucniBudget2004Doc::Delete()
{
try
{
m_piAdoRecordBinding->Update(&m_rsRecSet);
if(m_pRs->Supports(adDelete))
{
if(AfxMessageBox("Jeste li Sigurni Da hocete da Obrisete tekuci Zapis?",MB_YESNO | MB_ICONQUESTION) == IDYES)
{
m_pRs->Delete(adAffectCurrent);
m_pRs->MovePrevious();
}
}
}
catch (_com_error &e)
{
GenerateError(e.Error(),e.Description());
}
}
void CKucniBudget2004Doc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
if (m_pRs)
m_pRs->Close();
// Do we have a valid pointer to the record binding?
if (m_piAdoRecordBinding)
// Release it
// m_piAdoRecordBinding->Release();
// Set the record set pointer to NULL
m_pRs = NULL;
// Shut down the COM environment
CoUninitialize();
CDocument::DeleteContents();
}
void CKucniBudget2004Doc::GenerateError(HRESULT hr, PWSTR pwszDescription)
{
CString strError;
strError.Format("Greska broj'%d (%x)'",hr,hr);
strError+= "\n\n";
strError+=pwszDescription;
AfxMessageBox(strError);
}
CADORazmena* CKucniBudget2004Doc::GetRecSet()
{
return &m_rsRecSet;
}
///////////////////////////////////////////////
ViewClass
/////////////////////////////////////////
void CKucniBudget2004View::OnZapisBrisanjezapisa()
{
// TODO: Add your command handler code here
UpdateBoundData();
GetDocument()->Delete();
RefreshBoundData();
}
void CKucniBudget2004View::OnZapisNovizapis()
{
// TODO: Add your command handler code here
UpdateBoundData();
GetDocument()->AddNew();
RefreshBoundData();
UpdateData(FALSE);
}
void CKucniBudget2004View::RefreshBoundData()
{
CADORazmena* pRs;
pRs = GetDocument()->GetRecSet();
// Is the field OK
if (adFldOK == pRs->lIDStatus)
m_ID = pRs->m_ID;
else
m_ID = _T(" ");
if (adFldOK == pRs->lGarderobaStatus)
m_Garderoba = pRs->m_Garderoba;
else
m_Garderoba = _T(" ");
UpdateData(FALSE);
}
void CKucniBudget2004View::UpdateBoundData()
{
CADORazmena* pRs;
pRs=GetDocument()->GetRecSet();
UpdateData(TRUE);
if(m_ID != pRs->m_ID)
{
strcpy(pRs->m_ID,(LPCTSTR)m_ID);
}
if(m_Garderoba != pRs->m_Garderoba)
{
strcpy(pRs->m_Garderoba,(LPCTSTR)m_Garderoba);
}
////////////////////////////////////////////////
|
|
|
|
|
Hi-
I've been working with vs.net for awhile, but I need to use VC6 for this
current project. I'm getting linker errors and I have searched and
searched, yet I can't find it anywhere.
Here is the deal;
StdAfx.h
#include "SM2Types.h" // my custom types
SM2Types.h
#include "XYDataArray.h" // this is a nice little template class container that I found on Code Project. I don't want to use MFC
XYDataArray.h is wrapped nicely with #ifndef / #define
XYDataArray.h has this line #include XYDataArray.inl - this is the
implementation file it appears, I've never seen one before
So, somehow I guess it's trying to link to the objects over and over, hence
I'm getting the error:
Linking...
StdAfx.obj : error LNK2005: "int nXYSwap" (?nXYSwap@@3HA) already defined in
CSM2FileTools.obj
STL_testing.obj : error LNK2005: "int nXYSwap" (?nXYSwap@@3HA) already
defined in CSM2FileTools.obj
Debug/STL_testing.exe : fatal error LNK1169: one or more multiply defined
symbols found
Error executing link.exe.
This is very defeating... anyone have any ideas?? please?
-SK
|
|
|
|
|
See if this thread helps.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Thanks David, but I have a #define check at the top.
I learned from another source that the problem is that there is a global variable "int nXYSwap" used for a macro "#define XYSWAP(x,y) (nXYSwap=x,x=y,y=nXYSwap)"
so adding extern to the int declaration was the suggested solution, however that cause unresolved external error with the macro still trying to call the varaible.
I don't know what to make of it. here is the problem area if anyone is interested:
extern int nXYSwap;
#define XYSWAP(x,y) (nXYSwap=x,x=y,y=nXYSwap)
Thanks for the reply!
Steve
|
|
|
|
|
#define XYSWAP((x),(y)) {int z=(x);(x)=(y);(y)=z;}
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
!!
Thanks MAN! Obviously I don't know what I can do w/ macros.... this is great, thanks so much.
|
|
|
|
|
A better solution to the macro XYSWAP would be a templated function such as this:
<template typename T>
void XYSWAP(T& left, T& right) {
T tmp(left);
left = right;
right = tmp;
} There you have a function which
1) is type safe: you can't swap an int with a float
2) is type polymorphic (you can use it to swap other types than int
3) is reusable, thanks to 2)
4) does not rely on global variables
The template function simply replaces the macro in the header file.
--
C'est normal!
|
|
|
|
|