|
The registry is good for that - as long as you don't put too much in it. Usually you'll see code in InitInstance (after the call to SetRegistryKey) that calls GetProfileInt (or whatever) to retrieve settings (which can then be set to the dialogs members), and WriteProfileInt calls in ExitInstance that store tham back.
Or you could use an .ini file, or persist to file. There may be religious opinions about this!
|
|
|
|
|
I also store simple state data in the registry even though I do not like the way MS implemented the registry. (Concept is good, implementation is bad). The most important thing to consider when storing data to the registry is the probability that the user may want or need to edit that data. It is generally a VERY bad idea to store user configurable data in the registry. If they accidentally edit/delete the wrong thing they will hate you forever. Use an ini file for user editable configuration data.
|
|
|
|
|
John
the following code works if you are using a dialog based application, place the SetWindowPos() function in OnInitDialog() and GetWindowRect() function in OnOK or another function that gets called before the dialog closes. You would then need to read/write the values to the registry or ini file.
CRect rect;
GetWindowRect(&rect);
int nLeft = rect.left;
int nTop = rect.top;
SetWindowPos(&wndTop, nLeft, nTop, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
I have a doc / view project with a container. I load a word object (I use automation for msword9.dll).
whenever escape is pressed the object disappears.
I searched in the msdn and found nothing,
so I implemented a WH_KEYBOARD_LL hook, that catches all VK_ESCAPE messages,
the problem is that this kind of hook can be only globally set, so I can't use it anywhere else.
anyone has an idea?
Omri W.
|
|
|
|
|
I have an application that is a system service (Windows 2000). Among other things, I want it to set a system hook to trap WH_KEYBOARD_LL messages. However, my message handler does not seem to get called. The same code works fine when it is not running as a system service. Is it impossible for a service to set such hooks?
Any help is greatly appreciated!
|
|
|
|
|
Is your service logging in as the system account? If so, change it to log in as you and see if it then works. If that fixes it, then the reason you're not getting called when logged in as the system is a security restriction.
--Mike--
http://home.inreach.com/mdunn/
Sometimes, arming yourself with a big pointy stake just won't do you any good.
|
|
|
|
|
Hi,
I am trying to link to a dll at runtime. My DLL is definitely okay, it has a functon :
_declspec(dllexport) int increment(int val)
The client to the DLL executes the following code:
typedef int(*lpf_increment)(int);
HINSTANCE plugin;
plugin = LoadLibrary("c:\\plugin.dll");
if (plugin != NULL)
{
lpf_increment testcall;
testcall = (lpf_increment) GetProcAddress(plugin, _T("increment"));
int val=99;
int res = (testcall)(val);
char dump[60];
wsprintf(dump,"%i",res);
MessageBox("dump");
}
The GetProcAddress returns null, anyone any clues what's wrong?
Cheers
Richard
|
|
|
|
|
Run Dependency Viewer on your DLL - chances are the exported function is name-mangled, and not actually exported as "increment".
--Mike--
http://home.inreach.com/mdunn/
Sometimes, arming yourself with a big pointy stake just won't do you any good.
|
|
|
|
|
make sure that the function is being export correctly.
if it is C++ the export name will be name-mangaled
to view the exports from any dll use the dumpbin or depends utility from VC++
dumpbin /exports mydll.dll | more
When you build your DLL put this in the header file
this assumes that your Function/method to be exported is called int foo(int);
// exporting dll header file
#ifdef __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C
#endif
EXTERN_C int foo(int);
|
|
|
|
|
make sure that the function is being export correctly.
if it is C++ the export name will be name-mangaled
to view the exports from any dll use the dumpbin or depends utility from VC++
dumpbin /exports mydll.dll | more
When you build your DLL put this in the header file
this assumes that your Function/method to be exported is called int foo(int);
// exporting dll header file
#ifdef __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C
#endif
EXTERN_C __declspec(dllexport) int foo(int);
|
|
|
|
|
Thanks That Was Really Appreciated! Everythings clear now.
|
|
|
|
|
I try to acted this func from my main dialog in dialog project.
but I dont know what to give to its first parameter.
please help !
|
|
|
|
|
try:
this->m_hWnd
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
GetSafeHwnd() is the proper way to do this.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
I've found that using CDC.SelectObject() on a locally created object causes a massive drain on system resources, especially if you use it during an intensive screen update (OnDraw of a CScrollView, for example).
CScrollView::drawSomething() //called from OnDraw
{
CClientDC cdc(this);
CPen lightBluePen(PS_SOLID, 1, 0x00FFFFCC);
cdc.SelectObject(lightBluePen);
// blah blah
}
Apart from declaring lightBluePen as a modular variable which seems to stop this, is there a better way, ie some way of freeing this resource?
Thanks in advance!
|
|
|
|
|
Well, this was a problem I had, also, a time ago and I found the solution in this forum:
I have this in a header file:
class CSaveDC {
public:
CSaveDC(CDC * dc) { sdc = dc; saved = dc->SaveDC(); }
virtual ~CSaveDC() { sdc->RestoreDC(saved); }
protected:
CDC * sdc;
int saved;
};
And in the code file in my OnDraw function:
CPen m_pPincelR, m_pPincelN, m_pPincelA, m_pPincelM, m_pPincelV;
CFont m_pLetraP, m_pLetraG;
m_pLetraG.CreateFont(16,0,0,0,FW_SEMIBOLD,FALSE,FALSE,FALSE,
DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
18,"Times New Roman");
m_pLetraP.CreateFont(15,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,
DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
18,"Times New Roman");
m_pPincelR.CreatePen(PS_SOLID,2,RGB(255,0,0));
m_pPincelN.CreatePen(PS_SOLID,2,RGB(255,96,0));
m_pPincelA.CreatePen(PS_SOLID,2,RGB(0,255,255));
m_pPincelM.CreatePen(PS_SOLID,2,RGB(255,0,255));
m_pPincelV.CreatePen(PS_SOLID,2,RGB(0,255,0));
{
CSaveDC sdc (pDC);
pDC->SelectObject(m_pLetraG);
pDC->TextOut(25,-2,actual);
pDC->SelectObject(m_pLetraP);
..more TextOut...
pDC->SelectObject(m_pPincelR);
...drawing functions...
pDC->SelectObject(m_pPincelN);
...drawing functions...
pDC->SelectObject(m_pPincelA);
...drawing functions...
pDC->SelectObject(m_pPincelM);
...drawing functions...
pDC->SelectObject(m_pPincelV);
...drawing functions...
}
... OnDraw follows...
And it works fine, I've tried to redraw many times and there is not memory consumption.
The { and } are very important, when it finishes, the selections are automatic deleted.
|
|
|
|
|
Its just a guess, but could it be because your not releasing the object you select into the DC(the blue pen) when your done.
I think it should look more like this;
CScrollView::drawSomething()
{ <br />
<br />
CClientDC cdc(this); <br />
<br />
CPen lightBluePen(PS_SOLID, 1, 0x00FFFFCC); <br />
<br />
CPen * pOldPen = cdc.SelectObject(lightBluePen); <br />
<br />
<br />
cdc.SelectObject(pOldPen); <br />
<br />
}
Just my 2 cents.
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
How would i find the max index of an array? For example:
long myarray[10];
the function should return 10
any ideas?
|
|
|
|
|
You can try this:
int maxArray = sizeof(myarray)/sizeof(long);
later
...er - well I guess the max index would be that - 1 ...
|
|
|
|
|
Why don't you use STL vector instead of "plain" array?
I vote pro drink
|
|
|
|
|
How do I sort DaoRecordsets on a numeric field?
m_pSet->m_strSort="[My long Field]"; gives a sort, but it appears to alpha-numeric, not numeric.
All help apperciated!
Richard
|
|
|
|
|
The problem is that m_strSort only returns the name of the fields or fields that were includes in the Order By if you opened the recordset with a Query.
For example if you open de recordset with some like this:
Select * from table Order by field1, field2
The m_strSort will return you 'field1, field2'.
For make a order in a table you will need to use CDaoRecordset::SetCurrentIndex but the problem is that the field must be a index.
Did you Understand?
Cheers.
Carlos Antollini.
|
|
|
|
|
Suppose I have 2 pens created like these:
CPen m_pPenR, m_pPenN;
m_pPenR.CreatePen(PS_SOLID,3,RGB(255,0,0));
m_pPenN.CreatePen(PS_SOLID,3,RGB(255,150,0));
...
more code
...
pDC->SelectObject(m_pPenR);
myGraphic (a,b,pDC);
...
more code
...
pDC->SelectObject(m_pPenN);
myGraphic (c,d,pDC);
...
And into myGraphic(...) function I want to use the selected pens, drawing some lines but changing sometimes one or two of pens parameters (for example I want it with PS_DOT and width=1pixel, but remaining the color) and sometimes don´t.
How can I do it?
Thank you.
|
|
|
|
|
Hi all,
Does anyone know how to transfer the unsigned char to char AND how to transfer the char to unsigned char???
I know it is stupid......;P
Thanks
|
|
|
|
|
Do you just want to assign between two variables? Then use casts:
signed char ch = -1;
unsigned char uch = (unsigned char) ch;
--Mike--
http://home.inreach.com/mdunn/
Sometimes, arming yourself with a big pointy stake just won't do you any good.
|
|
|
|
|