|
If you are using MFC, take a look at CStdioFile class. You can use its member ReadString to read a line of text into CString, and than you can parse the information you want from here.
I vote pro drink
|
|
|
|
|
meirav wrote:
from some reason there is a conflict in my programm with the lib files and i can't use the fscanf
This seems to be indicative of a larger problem. fscanf() is present in msvcrtl.dll and should be available for use. However, if you don't want to use it because you're not doing standard C file I/O, you could use MFC's file read functions and sscanf() to parse the data.
/ravi
"There is always one more bug..."
ravib@ravib.com
http://www.ravib.com
|
|
|
|
|
In MFC you have the CStdioFile or the CFile Classes...
Best Regrards....
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
How can i create a modeless dialog that cant be closed. I am using it as a compulsary advertisment window and currently all my attemts at making it non-closable have failed.
I would apreciate any help u can give!
|
|
|
|
|
if its modeless and purely win32 without MFC (allthough u could do the same if its MFC) try putting something like this in the WM_CLOSE handler:
WinExec("myapp.exe");
in which myapp.exe is the current application. This way it'll just restart everytime it is shut down.
or if you really want the user not to be able to close it you could just disable their system keys, mwehe, but thats pretty gwiffy, i dont think they'd like that. U can use the following code for this:
PUINT fuiState;
SystemParametersInfo(97, TRUE, fuiState, 0);
that'll disable ctrl-alt-del and other system keys.
Kuniva
Want, take, have.
(oh btw, best way of learning some language is by looking at examples, start large!) :p
|
|
|
|
|
Write do-nothing handlers for WM_CLOSE and WM_SYSCOMMAND (SC_CLOSE).
A somewhat more annoying thing to do is to hide the dialog when the user tries to close it, create an n-second timer, then show the window (and kill the timer) when the timer fires.
/ravi
"There is always one more bug..."
ravib@ravib.com
http://www.ravib.com
|
|
|
|
|
if you use this method you can still close the dialog with the task manager, but if thats all you want then this is advisable yea, dont use my method it'll freak 'em out lol
Kuniva
Want, take, have.
(oh btw, best way of learning some language is by looking at examples, start large!) :p
|
|
|
|
|
the WM_CLOSE thingy didnt work. this is a modeless dialog as part of a larger app so the other technique of getting it to restart the app afterwards wont be suitable. is their a way of simply re-opening the dialog when it is closed. To start the dialog at the start of the app I am using the following in the CMainFrame::OnCreate function:
OnStartModeless()
this calls the function
void CMainFrame::OnStartModeless()
{
if(!g_pDlgModeless)
g_pDlgModeless = new CModeless(this);
}
Any ideas?
Fave Quote. Made this one myself feel free to use it in any argument u like where some idiot takes the piss outta your computer!
"No just cos i like my computer more than you doesnt make me pathetic. Quite Frankly i find a tic-tac a more interesting companion than u."
|
|
|
|
|
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
|
|
|
|
|