|
Maybe this is what you are looking for:
Assuming your dialog is myDlg:
Remove OnOK and OnCancel handlers from the dialog class.
Remove OK and Cancel buttons
Include in CMainFrame::OnCreate(), the lines (or variations of it):
myDlg.Create(IDD_MYDIALOG);
myDlg.SetWindowPos(&wndTopMost,0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
Include in CMainFrame::OnActivateApp(), the line
myDlg.ShowWindow(SW_SHOW);
You can show or hide the dialog by using SW_SHOW or SW_HIDE
as and when you need.
|
|
|
|
|
I can't seem to find any clear-cut example to enumerating the catalogs (databases) in my SQL server datasource using OLEDB. Does anyone have an example of this?
Paul Jahans
|
|
|
|
|
Use SQL DMO - There are various methods that allow you to do this
e.g. GetDatabaseByOrd
|
|
|
|
|
Thanks for your quick response. I'll try that.
Paul Jahans
|
|
|
|
|
i'm trying to load a .scr file thats in my resource file with LoadResource(). All i have is this:
HGLOBAL myhand;
HRSRC ResInfo = FindResource(GetModuleHandle(NULL),"IDR_SCREENSAVER1",RT_RCDATA);
myhand = LoadResource(GetModuleHandle(NULL),ResInfo);
if(myhand==NULL)
{
MessageBox("Load failed, exiting...","darn",MB_OK);
return;
}
But it always return NULL. Can anyone explain?
Thanks
Kuniva
|
|
|
|
|
Hi,
first of all, to be on the safe side, you should test the Handle returned by ResInfo
by inserting a line like
if(! ResInfo)
{
MessageBox("Could not find thingy in the resource, exiting...","Dear me",MB_EXCLAMATION);
return;
}
before calling LoadResource()
Then, you should also try using the MAKEINTRESOURCE() Macro to pass the Resource Id
i.e. your call to FindResource should now be:
HRSRC = FindResource(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_SCREENSAVER1),RT_RCDATA);
Let me know if this helps.
Cheers
Pierre Heler-Caruel
|
|
|
|
|
Well i tried both your suggestions. First i added the code to check if ResInfo was valid and then i tried using MAKEINTRESOURCE() but that didn't work. So i tossed that and i tried renaming my resource stringwise with the "" , that didn't work either. I tried all combinations. It can't seem to find the resource(allthough its there). I also tried going to the resource, clicking right>properties and unchecking the "external file" checkbox but that didn't help either.
Any suggestions?
Kuniva
|
|
|
|
|
Hi,
sorry to hear it didn't work.
Normally, you should name your Resource Ids as usual (i.e. no quotes) and use MAKEINTRESOURCE(ResourceId) as this is the usual way.
Having said that, there are two things you can try:
1) Ensure the Type of Resource for the file matches the type you use in FindResource(). My recommendation would be to define your own resource-type (for instance "SCREEN_SAVER") when you import the file in your project. Then use that name (note the quotes) as the Resource-type
2) Visual Studio has a funny way of not rebuilding correctly if you have changed the resource (this doesn't happen all the time though... I guess it's a "feature";)
So instead of just doing a compile (F7) do a clean then rebuild all of your project and try again.
BTW if you send me your .rc file and the associated file to import, I can give it a shot for you.
Let me know.
Cheers,
Pierre Heler-Caruel
|
|
|
|
|
First of all thanks a lot for your help, I kind of got the resource to load and stuff anyways i got a handle to it with the method Derek described (thanks). BUT so i have a handle, one of my following questions is: "what is LockResource() for exactly?"
my second and perhaps most important question is: "How do i get the data from the file and write it to a file on disk so i have an exact replica of it?? What kind of variable do i use? How do i even get the data with the handle? I mean.. I have a handle, so what? I dont know how to use a handle... *blush* lolz"
Kuniva
Want, take, have.
(oh btw, best way of learning some language is by looking at examples, start large!) :p
|
|
|
|
|
LockResource ... locks the resource, I think the names says it all ...
Seriously, once you've locked the resource, you can manipulate it.
With the handle, you could do things like this to write it to a file (let's assume hYourApp is a Handle to your Application):
first retrieve its size
DWORD dwDataSize = SizeofResource((HMODULE)hYourApplication,ResInfo)
if(dwDataSize == 0)
{
// Failed to retrieve the Size
MessageBox("Ooops","Dear me...",MB_ICONEXCLAMATION);
return;
}
Then, you can create a file and dump the content of the Resource into it
FILE * pfResourceData = NULL,
BYTE * pData = NULL;
pfResourceData = fopen("SomeFileName","wb+");
if(pfResourceData)
{
if(! fwrite(pData,dwDataSize,1,pfResourceData))
{
fclose(Result);
DeleteFile("SomeFileName");
MessageBox("Failed to write Data",
"Oh Dear!",
MB_ICONEXCLAMATION);
return;
}
else
{
// Wrote all the Data so close the File
fclose(pfResourceData);
}
}
There you have it. The Resource Data should now be stored in "SomeFileName"
HTH
Cheers,
Pierre
P.S. I've used the "C" way of writing files to keep as generic as possible but of course you're free to use the
MFC way with CFile or File-handles, etc...
|
|
|
|
|
yeehaa!!! i got it to work, thanks to you!
Thanks sooooooooooo much!!!
Kun
|
|
|
|
|
Could it be that you have named your resource with a numeric identifier? Go to the resource editor, change the identifier from IDR_SCREENSAVER1 (numeric ID) to "IDR_SCREEN_SAVER1" (string ID), and try your program again.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Well i tried both your suggestions. First i added the code to check if ResInfo was valid and then i tried using MAKEINTRESOURCE() but that didn't work. So i tossed that and i tried renaming my resource stringwise with the "" , that didn't work either. I tried all combinations. It can't seem to find the resource(allthough its there). I also tried going to the resource, clicking right>properties and unchecking the "external file" checkbox but that didn't help either.
Any suggestions?
Kuniva
|
|
|
|
|
Hi Kuniva,
I don't know what Resource Type you're resource is, but that could be the problem. The RT_RCDATA thing is for a generic data resource. I've included some code that does just this (the resource is actually another .exe file for a self-extracting setup program). In the resource editor, what treeview heading does your resource appear under? In the example below, my resource has a type of "BIN" (which is what appears in the resource editor).
vhRsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_DATA), _T("BIN"));
if (vhRsrc != NULL)
{
vhGlobal = LoadResource(NULL, vhRsrc);
if (vhGlobal != NULL)
{
vdwLen = SizeofResource(NULL, vhRsrc);
vpBuffer = (BYTE *)LockResource(vhGlobal);
}
}
Hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
First of all thanks a lot for your help, I kind of got the resource to load and stuff anyways i got a handle to it with the method Derek described (thanks). BUT so i have a handle, one of my following questions is: "what is LockResource() for exactly?"
my second and perhaps most important question is: "How do i get the data from the file and write it to a file on disk so i have an exact replica of it?? What kind of variable do i use? How do i even get the data with the handle? I mean.. I have a handle, so what? I dont know how to use a handle... *blush* lolz"
Kuniva
|
|
|
|
|
Hi Kuniva,
Sorry about not replying earlier - I've been away on holidays.
LockResource() returns an LPVOID, ie a void pointer. This points at a block of memory that contains the raw resource data. You can get the length of this block of data using the function SizeofResource. Then you just need to open a file and write this block of data to disk. For example (no error checking):
HRSRC vhRsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_MY_DATA), _T("DATA"));
HGLOBAL vhData = LoadResource(NULL, vhRsrc);
void *vpbData = LockResource(vhData);
DWORD vdwLen = SizeofResource(NULL, vhRsrc);
HANDLE vhMyFile = CreateFile(_T("D:\blah.dat"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(vhMyFile, vpbData, vdwLen, &vdwWritten, NULL);
CloseHandle(vhMyFile);
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
Thanks for your answer Derek allthough i had already got it to work.
Kuniva
|
|
|
|
|
Hello
is there a similiar "with" statement in c++ like in delphi?
for example I can do a lot of drawing stuff with this procedure:
with Foo do
begin
Rectangle...
LineTo...
MoveTo...
end
this way I don't need to put "Foo" before each function
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Could you please explain a bit what namespaces do and how to use them?
I never used them
regards
Gregor
modified 12-Sep-18 21:01pm.
|
|
|
|
|
a namespace is a way of encapsulating a set of classes (or functions, or variables, etc).
you can do something like this:
namespace fred
{
class myClass
{
...
};
}
now, if you want to create an object of type myClass, you have to tell the compiler to look in the "fred" namespace, like this:
fred::myClass var;
or, you can use the "using" keyword, like this:
using namespace fred;
myClass var;
"using" just tells the compiler that it's OK to search the namespace "fred" for any object definitions that it might need.
-c
Smaller Animals Software, Inc.
|
|
|
|
|
Thanks a lot!
But actually they're not a real substitute for the "with"-statement
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
Chris Losinger wrote:
"With" is a Pascal thing
Yes. It is also present in VB. Quite a nice feature, I think.
I vote pro drink
|
|
|
|
|
There's no equivalent of "with" in C/C++ but if you wanna avoid is typing a large name over and over again, you can create a short-name version of it using a reference variable:
CSomeType& t = thisReallyLongAndHorribleVariable;
t.Rectangle(...);
t.LineTo(...);
t.MoveTo(...);
Regards,
Alvaro
|
|
|
|
|
What's wrong with this piece of code?
The destructor of Class Value is never been called!
If I try to set a breakpoint there, the compiler immediately
disables it.
What am I doing here that's against the rules?
.h file
class Value
{
public:
unsigned char *pvalue;
Value(int size)
{
pvalue=new unsigned char(size);
}
~Value()
{
delete [] pvalue; <-- No break point here
}
};
class Parameter
{
public:
CString Name;
CString MenuItem;
void *pValue;
void *ValueText;
Parameter *next;
Parameter()
{
pValue = NULL;
next = NULL;
}
~Parameter()
{
if(pValue)
delete pValue;
}
};
.cpp file
Parameter* Parm = new Parameter();
Parm->pValue = new Value(4);
delete Parm;
Thanks, Arjan
|
|
|
|
|