Resources .rc question
-
Hi, I know that I can include in my resources, Bitmaps, Icons, even Metafiles or AVI files... But... I need to include something... just pieces of text ( something like pages of text), I would like to include that on the resources ( to have it then inside my exe file), and load it from there into an CString object, is that possible ? For me it would be easier to put that ASCCI formatted text into a resource entry, than having const strings and all that things... How can I do that ?, thanks greetings Braulio
-
Hi, I know that I can include in my resources, Bitmaps, Icons, even Metafiles or AVI files... But... I need to include something... just pieces of text ( something like pages of text), I would like to include that on the resources ( to have it then inside my exe file), and load it from there into an CString object, is that possible ? For me it would be easier to put that ASCCI formatted text into a resource entry, than having const strings and all that things... How can I do that ?, thanks greetings Braulio
I'm not sure about the maximum size of characters in the string table, but maybe you could use it for the purpose! Then you can load it into a CString like: CString rr; rr.LoadString(IDS_STRING); hope this helps
-
Hi, I know that I can include in my resources, Bitmaps, Icons, even Metafiles or AVI files... But... I need to include something... just pieces of text ( something like pages of text), I would like to include that on the resources ( to have it then inside my exe file), and load it from there into an CString object, is that possible ? For me it would be easier to put that ASCCI formatted text into a resource entry, than having const strings and all that things... How can I do that ?, thanks greetings Braulio
You can definitely do it, just insert the text file as custom give it a name. I don't know how you will load it in MFC but here is what I did for Win32: static char *pText; HGLOBAL hResource; switch(message) { case WM_INITDIALOG: hResource = LoadResource (hInst, FindResource (hInst, TEXT ("README"), TEXT("TEXT"))); pText = (char *) LockResource(hResource); return TRUE; this is from a dialog of mine. The Resource was given a name of "README" and the custom resource type "TEXT"; Then all you have to do is find/load and lock. That's it. Hope this helped.
-
You can definitely do it, just insert the text file as custom give it a name. I don't know how you will load it in MFC but here is what I did for Win32: static char *pText; HGLOBAL hResource; switch(message) { case WM_INITDIALOG: hResource = LoadResource (hInst, FindResource (hInst, TEXT ("README"), TEXT("TEXT"))); pText = (char *) LockResource(hResource); return TRUE; this is from a dialog of mine. The Resource was given a name of "README" and the custom resource type "TEXT"; Then all you have to do is find/load and lock. That's it. Hope this helped.
Just what I was looking for !, Thanks a lot ! So long Braulio
-
You can definitely do it, just insert the text file as custom give it a name. I don't know how you will load it in MFC but here is what I did for Win32: static char *pText; HGLOBAL hResource; switch(message) { case WM_INITDIALOG: hResource = LoadResource (hInst, FindResource (hInst, TEXT ("README"), TEXT("TEXT"))); pText = (char *) LockResource(hResource); return TRUE; this is from a dialog of mine. The Resource was given a name of "README" and the custom resource type "TEXT"; Then all you have to do is find/load and lock. That's it. Hope this helped.
Thanks for the tip !!! Finally I decide to use Win32, to make an screen saver ( from the sample ballFusion). Just two more questions, after using the Text ( in the resource), should I free that ? ( I've seen LockResource but donno if it's neccessary to make a call to free that). And another question... How can I get the handle of the instance in my application, hInst doesn't work because the thing of the screen saver seems to be special, in MFC it was easy something like "AfxGetApp" or other Afx call. Sorry... I'm novice in Win32.. without sugar ( MFC or ATL) :-) thanks for your help, greetings Braulio
-
Thanks for the tip !!! Finally I decide to use Win32, to make an screen saver ( from the sample ballFusion). Just two more questions, after using the Text ( in the resource), should I free that ? ( I've seen LockResource but donno if it's neccessary to make a call to free that). And another question... How can I get the handle of the instance in my application, hInst doesn't work because the thing of the screen saver seems to be special, in MFC it was easy something like "AfxGetApp" or other Afx call. Sorry... I'm novice in Win32.. without sugar ( MFC or ATL) :-) thanks for your help, greetings Braulio
Well, to tell you the truth, I am just a novice myself. I just did these thing recently so I know about them...If you do not need the text resource anymore then you should call FreeResource. My book says that even if you don't call FreeResource then it will be freed when the program terminates but I think that it's always a good idea to get rid of them when you are done with them. I think you also found a memory leak in my program since I was loading the resource every time I started the dialog and wasn't freeing it so thanks! About the the handle of the instance, there are many ways. What I use a global HINSTANCE hInst for example. In WinMain I set hInst = hInstance but you must set the global handle hInst to hInstance before CreateWindow in WinMain or else it won't work. I also found that out a couple of weeks ago. Other ways are in WM_CREATE you can declare a local HINSTANCE hInst and set it to hInst = ((LPCREATESTRUCT) lParam)->hInstance. Yet another way is GetWindowLong(hwnd, GWL_HINSTANCE). This also straight out of Charles Petzold's Programming Windows, in my opinion a book that everyone should have. Taught me everything I know! Good luck with your program.
-
Well, to tell you the truth, I am just a novice myself. I just did these thing recently so I know about them...If you do not need the text resource anymore then you should call FreeResource. My book says that even if you don't call FreeResource then it will be freed when the program terminates but I think that it's always a good idea to get rid of them when you are done with them. I think you also found a memory leak in my program since I was loading the resource every time I started the dialog and wasn't freeing it so thanks! About the the handle of the instance, there are many ways. What I use a global HINSTANCE hInst for example. In WinMain I set hInst = hInstance but you must set the global handle hInst to hInstance before CreateWindow in WinMain or else it won't work. I also found that out a couple of weeks ago. Other ways are in WM_CREATE you can declare a local HINSTANCE hInst and set it to hInst = ((LPCREATESTRUCT) lParam)->hInstance. Yet another way is GetWindowLong(hwnd, GWL_HINSTANCE). This also straight out of Charles Petzold's Programming Windows, in my opinion a book that everyone should have. Taught me everything I know! Good luck with your program.
Thanks a lot ! All this will help me a lot. In my former Jo I had that Petzold book, I think it's quite quite good ( I used it when MFC was not so good and I had to do some API stuff :-) ), but in my current job I don't have it X| what a pity ! Thanks for the info, greetings Braulio