|
Thanks...Appreciate your help
C++Prog
|
|
|
|
|
I would recommend against using the registry for a couple reasons:
1) It is a very old technology that is being phased out (slowly, but surely)
2) It is far more complicated than what you need anyway.
A simple solution is to write out a text file in some format (XML is nice for this) that you check for when your app starts. If the file exists, it loads the settings; if not, it uses a default configuration. Additionally, you can configure the file to exist anywhere you like (though, if you want to cooperate properly with Windows XP, you should put it in the users Document and Settings directory).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Preeti9 wrote: I have a dialog based application. I want to save the last configuration of the that application. For example if I have a # of selected countries field set to 7 in last configuration, then next time if I open it, it should be saved.
You may profile the data into .ini file for the application....
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
I have an outside application.
I found the buttons window using EnumChildWindows
I send the following to it:
SendMessage(hwnd, WM_LBUTTONDOWN, 0, 0);
SendMessage(hwnd, WM_LBUTTONUP, 0, 0);
I put in a 300 millisecnd delay but the event for the button never fires.
Does anyone know why it would fire?
I can see the image of the button change. But its not releasing correctly. I have to click my app really fast to get the release to work right. But, the click event still doesn't fire.
Is there somethibng special require to get the button event to fire?
Thanks,
Nick
1 line of code equals many bugs. So don't write any!!
-- modified at 14:01 Tuesday 30th May, 2006
|
|
|
|
|
Use SendInput() to simulate user input.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Yes, i tried that first. But I have a problem.
It is a tabbed windows app.
It Registers each tab as a Window.
I need to click this tab. How do I get the exact screen coordinate to feed into SendInput?
GetClientRect is only local coordinates I think.
Please Tell me what methods to call to get rectangle to place the mouse position?
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
BM_CLICK instead of WM_LBUTTONDOWN
----------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
I am trying to set the edit control part of the dropdown to a specific number such as 15 (m_data = "15"). But because a value of 150 exists in the dropdown, it automatically sets it that number. How to I disable this? Thanks.
-- modified at 12:10 Tuesday 30th May, 2006
|
|
|
|
|
|
Yes, it's a dropdown combo box.
|
|
|
|
|
experiment:
edit does not change even if string exists in combo box
any specific non-default styles?
Kuphryn
|
|
|
|
|
No. It's just a dropdown with a CString member variable mapped to it. When I set the value to 16 for instance, it accepts that value. But for some reason, the value changes or the auto-complete kicks in when the number resembles what's in the pull-down.
|
|
|
|
|
handle CBN_EDITCHANGE
what you see after UpdateData?
Kuphryn
|
|
|
|
|
How to prevent CListCtrl from hiding its scrollbars?
Thanks
|
|
|
|
|
Hi again
I'm trying to connect to an access db using ADO
i use some sample codes to perform a simple SELECT query and display them through a recordset. I've tryed really hard to make it work i've searched everywhere pls help me find the problem.
This is the code i use::
<br />
#include <windows.h><br />
#include <stdio.h><br />
#include <iostream.h><br />
<br />
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \<br />
no_namespace rename("EOF", "EndOfFile")<br />
<br />
void main(int argc, char* argv[])<br />
{<br />
<br />
HRESULT hr = S_OK;<br />
_ConnectionPtr m_pConn;<br />
try<br />
{<br />
HRESULT hr = m_pConn.CreateInstance(__uuidof(Connection));<br />
if (FAILED( hr ))<br />
cout<<"Can't create an intance of ADO.Connection"<<endl;<br />
<br />
if (FAILED( m_pConn->Open(_bstr_t("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =ADOTestDB.MDB"),<br />
_bstr_t( "" ),<br />
_bstr_t( "" ), <br />
adModeUnknown )))<br />
<br />
cout<<"Can't open datasource"<<endl;<br />
<br />
<br />
_CommandPtr pCommand;<br />
pCommand.CreateInstance (__uuidof (Command));<br />
pCommand->ActiveConnection = m_pConn; <br />
pCommand->CommandText = "Select Name,Dept From Student";<br />
_RecordsetPtr pRecordset;<br />
pRecordset.CreateInstance (__uuidof (Recordset));<br />
pRecordset->CursorLocation = adUseClient;<br />
pRecordset->Open ( (IDispatch *) pCommand, vtMissing, adOpenStatic,<br />
adLockBatchOptimistic, adCmdUnknown);<br />
<br />
_bstr_t valField1;<br />
int valField2;<br />
pRecordset->MoveFirst();<br />
if (!pRecordset->EndOfFile)<br />
{<br />
while(!pRecordset->EndOfFile)<br />
{<br />
valField1 = pRecordset->Fields->GetItem("Name")->Value;<br />
valField2 = pRecordset->Fields->GetItem("Dept")->Value.intVal;<br />
printf("%d - %s\n",valField2,(LPCSTR)valField1);<br />
pRecordset->MoveNext();<br />
}<br />
}<br />
<br />
<br />
}catch( _com_error &ce )<br />
{<br />
printf("Error:%s\n",ce.Description);<br />
<br />
}<br />
m_pConn->Close();<br />
<br />
}<br />
i get an exeption
"Can't create an intance of ADO.Connection"
and the i asks if i want to debug
Pls help me i'm trying a lot to connect to a db and enything i do seems to be wrong
and the truth is that everytime i post a msg about C++ and ADO no one
replies.
pls i'm desparate
|
|
|
|
|
ADO is a set of COM objects. To use COM from any thread, you need to call CoInitialize (or for advanced users that won't run on W9x or ME, CoInitializeEx).
Try putting
CoInitialize(NULL);
after your declaration of hr,
move your connection pointer inside your try block [it's a smart pointer, and needs to go out of scope or be released before calling CoUninitialize()]
Add
CoUninitialize();
after your catch block.
Steve S
Developer for hire
|
|
|
|
|
Hey Thanks Steve is FINALLY WORKING!!!
thanks you Steve S i'm so happy i was about to give up
BTW do you know any good reference that i can use to learn about ADO and COM objects because using sample codes i cannot understand the reall structure of ADO
i just copy paste without understanding.
Thanks again Steve S i appreciate all the help
|
|
|
|
|
No problem;
I'm more of an OLEDB man myself, but SAMS had a "Database Programming in VC++" which I think covered most techniques. COM itself has a relatively small surface area to learn, but there are lots of things that you need to know. Best bet is to look for tutorials in places like CodeProject.
Steve S
Developer for hire
|
|
|
|
|
Thanks again i found that book of Sams and Db programming in 21 days the problem is that he use the MFC and wizards which i don't really understand either.
Maybe your right the best place to learn from is the web
BTW can i ask something else.
i need to execute a query like:
"Select Name,Dept From Student WHERE Name=? "
i want the query to get the name from a variable of type string.
"Select Name,Dept From Student WHERE Name=token//token is a variable of type string which get the value from a different function
how can i do that? di i need to use stored procedures?
Thanks again steve S
|
|
|
|
|
I'd suggest putting CoInitialize(NULL) in WinMain/InitInstance/whatever, and CoUninitialize() in respective counterparts, if the design allows it. CoInitialize(NULL) is time consuming (although not as bad on newer operating systems, as it was back in the 9x days), and is therefore best kept out of the loop so to speak.
--
100% natural. No superstitious additives.
|
|
|
|
|
I thought that's what I'd said, but did not explicitly make the point, so thanks for pointing it out.
Good practice is to keep as much as possible out of loops - just look at the different code produced with and without optimisations turned on
Steve S
Developer for hire
|
|
|
|
|
Hey, I have been programming c++ for 4-5 years now (my real love is Java), but I am trying to make an mfc project (VS 2005) for the first time.
I went through the wizard and then made some extra dialog boxes making sure to name all of the compnents(dropdown boxes, textboxes, etc). Now I am trying to connect the dialog boxes and I am having some problems.
I have tried looking at some tutorials online, but am still having some problems.
I am trying to create a dialog box (Main_DIALOG) when "ok" is clicked on in the orginal box (LogOn_DIALOG).
Here is what I have now:
I know this is a lot of code to look at, but I really don't know where the problem is. The wizard wrrote most of the code and I am freaking hating that.
-----------------------------------------------------------
#pragma once
class CMyLogOnDialog : public CDialog
{
DECLARE_DYNAMIC(CMyLogOnDialog)
public:
CMyLogOnDialog(CWnd* pParent = NULL);
virtual ~CMyLogOnDialog();
enum { IDD = LogOn_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedButton();
};
----------------------------------------
#pragma once
class CMyMainDialog : public CDialog
{
DECLARE_DYNAMIC(CMyMainDialog)
public:
CMyMainDialog(CWnd* pParent = NULL);
virtual ~CMyMainDialog();
enum { IDD = Main_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
DECLARE_MESSAGE_MAP()
};
-------------------------------------------------
#include "stdafx.h"
#include "ECO.h"
#include "MyLogOnDialog.h"
#include "MyMainDialog.h"
IMPLEMENT_DYNAMIC(CMyLogOnDialog, CDialog)
CMyLogOnDialog::CMyLogOnDialog(CWnd* pParent )
: CDialog(CMyLogOnDialog::IDD, pParent)
{
}
CMyLogOnDialog::~CMyLogOnDialog()
{
}
void CMyLogOnDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CMyLogOnDialog, CDialog)
ON_BN_CLICKED(LogOnOK_Button, &CMyLogOnDialog::OnBnClickedButton)
END_MESSAGE_MAP()
void CMyLogOnDialog::OnBnClickedButton()
{
CMyMainDialog dlg;
dlg.DoModal();
}
----------------------------------------------
#include "stdafx.h"
#include "ECO.h"
#include "MyMainDialog.h"
IMPLEMENT_DYNAMIC(CMyMainDialog, CDialog)
CMyMainDialog::CMyMainDialog(CWnd* pParent )
: CDialog(CMyMainDialog::IDD, pParent)
{
}
CMyMainDialog::~CMyMainDialog()
{
}
void CMyMainDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CMyMainDialog, CDialog)
END_MESSAGE_MAP()
----------------------------------------------------
I don't get any error messages, but my second window doesn't popup. Did I put my action handler in the wrong class? Or am I just totally off here?
I am sorry for asking such a stupid question, but I am really just not getting it which is weird considering how fast I picked up c++ and Java (witout any wizards).
Feeling Stupid,
Brandy
|
|
|
|
|
Don't be discouraged by the wizards. They are a great help once you understand what they are doing for you (this is where most people get choked up with MFC, and why they think it is a horrible library ... it is actually quite good if you understand what is under the hood).
Now, looking at your code, nothing glaring stands out (other than not making your dialog IDs all caps and not checking the return value of DoModal ... but I can forgive those
Open the "Main" dialog in the resource editor and make sure that the dialog's settings match that of your "Log in" dialog (basically, you want it to be a popup with a frame).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I am not sure where the problem lies still, but I found other problems as well.
I tried just to see if I could get the text out of the Password textbox stored as C_Password, defined in the file ECODlg.h. I included ECODlg.h, but when I tried this code:
void CMyLogOnDialog::OnBnClickedButton()
{
CString password;
c_Password.getWindowText(password);
CMyMainDialog dlg;
dlg.DoModal();
}
it will not compile. I get the error:
error C2065: 'c_Password' : undeclared identifier
|
|
|
|
|
whats type c_Password?
whitesky
|
|
|
|