|
I think you need to extract the string using some delimiter. If you have the strings or the key-value pair on separate lines you can read the full line and then extract the key and the value based on "=" delimiter.
A proper way of writing down the entries, would be a XML file. You can find that lot of applications do use the XML file in the config format.
If you have lesser number of entries and you are allowed to read/write from registry you can also go for this easier option, but this depends on the privileges you have as a developer.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
That looks like old .INI file format - you can use the
WritePrivateProfileString()/GetPrivateProfileString()
functions to work with INI files.
Using XML is a more modern and flexible approach.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
pl_kode wrote: Please someone tell me how to use properties file in my program.
That's up to you and your program. It matters not that you call it a properties file, an initialization file, or an options file. What's in it is only relevant to your application.
Now, what exactly are you wanting to do with this file (i.e., what purpose does it serve)?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Ok. I was given
ULONG dwToken;
Gdiplus::GdiplusStartupInput input;
Gdiplus::GdiplusStartupOutput output;
Gdiplus::Status status = Gdiplus::GdiplusStartup(&dwToken, &input, &output);
if(status == Gdiplus::Ok)
{
Gdiplus::Bitmap srcBitmap(L"betty.PNG", FALSE);
Gdiplus::Graphics wndGraphics(staticwindow);
wndGraphics.DrawImage(&srcBitmap, 0, 0);
//Gdiplus::GdiplusShutdown(dwToken);
}
to draw pictures on a static control. I used ResEdit to create my window and I placed a Picture Control on the box. Turns out it seems to be a static control with a specific style to do this.
Now I am creating a dialog box and trying to draw the image again. I used Visual Studio's editor (no choice atm) to create my child window with the picture control called IDC_STATIC.
For some reason the above code no longer works. I step through it with no errors. So what could be wrong? well I looked into the .rc file and it is using some strange class for my picture control and not the static control like resedit's was.
Bwa?
If I use resedit's picture control it works. If I do not, I get no picture.
Any ideas?
|
|
|
|
|
Seems I am being silly today.
That code can't be run in WM_INITDIALOG.
What's the first message I *could* run it in?
|
|
|
|
|
May be wait for the first WM_PAINT message and do your stuff there?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
I had problems in using the WM_INITDIALOG as well, and I solved it using a "bypass". I just used a bool bFirst setting it to TRUE in WM_INITDIALOG. Then in WM_PAINT took a look into, when true do some staff and putting it to false.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
As with most drawing, you should be doing it whenever the control receives a
WM_PAINT message
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for all the suggestions so far. I've tried doing it in WM_PAINT with just a little success.
Code is at end of post. I have a picture box control with type Bitmap on my control as position 0,0. I basically want a window where it just displays an image.
However with the current code below, I am unable to get the image to not "be covered up". If I take another window and cover up MY window and then move away, I can then see the image as I desire.
However this is not desired behavior. I have a function commented out called RepaintWindow. It's one of my custom functions. It gets the client rect of the window and calls invalidaterect for that section. A shortcut.
When that is not commented out, I get to see my image (again when moving another window onto MY window) for a brief second then it gets covered by up by gray again.
I am missing a small detail here and by god if I can't see what that is! Thanks for the help.
<br />
case WM_PAINT:<br />
{<br />
<br />
if(firstTime)<br />
{<br />
<br />
<br />
if(status == Gdiplus::Ok)<br />
{<br />
HWND staticwindow = GetDlgItem(hwnd,IDC_STATIC);<br />
HDC dc = GetDC(staticwindow);<br />
<br />
const int size = ad.message.size();<br />
char* placeholder = new char[size+1];<br />
strcpy(placeholder,ad.message.c_str());<br />
<br />
placeholder[size+1] = '\0';<br />
<br />
WCHAR temp[100];<br />
mbstowcs(temp, placeholder, size+1);<br />
<br />
Gdiplus::Bitmap srcBitmap(temp, FALSE);<br />
Gdiplus::Graphics wndGraphics(dc);<br />
<br />
Gdiplus::SizeF SIZE;<br />
srcBitmap.GetPhysicalDimension(&SIZE);<br />
<br />
int height = SIZE.Height;<br />
int width = SIZE.Width;<br />
<br />
wndGraphics.DrawImage(&srcBitmap, 0, 0);<br />
<br />
SetWindowPos(hwnd,HWND_BOTTOM,0,0,width,height,SWP_NOMOVE |SWP_NOZORDER );<br />
SetWindowPos(staticwindow,HWND_BOTTOM,0,0,width,height,SWP_NOMOVE );<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
firstTime = true;<br />
<br />
<br />
}
<br />
}<br />
|
|
|
|
|
Do you want to show image on the static control?do you have problem in this section? and also you can use of CImage class for load images.
|
|
|
|
|
Edit. sorry for double posting. seems I posted my reply in the wrong spot.
Thanks for all the suggestions so far. I've tried doing it in WM_PAINT with just a little success.
Code is at end of post. I have a picture box control with type Bitmap on my control as position 0,0. I basically want a window where it just displays an image.
However with the current code below, I am unable to get the image to not "be covered up". If I take another window and cover up MY window and then move away, I can then see the image as I desire.
However this is not desired behavior. I have a function commented out called RepaintWindow. It's one of my custom functions. It gets the client rect of the window and calls invalidaterect for that section. A shortcut.
When that is not commented out, I get to see my image (again when moving another window onto MY window) for a brief second then it gets covered by up by gray again.
I am missing a small detail here and by god if I can't see what that is! Thanks for the help.
<br />
case WM_PAINT:<br />
{<br />
<br />
if(firstTime)<br />
{<br />
<br />
<br />
if(status == Gdiplus::Ok)<br />
{<br />
HWND staticwindow = GetDlgItem(hwnd,IDC_STATIC);<br />
HDC dc = GetDC(staticwindow);<br />
<br />
const int size = ad.message.size();<br />
char* placeholder = new char[size+1];<br />
strcpy(placeholder,ad.message.c_str());<br />
<br />
placeholder[size+1] = '\0';<br />
<br />
WCHAR temp[100];<br />
mbstowcs(temp, placeholder, size+1);<br />
<br />
Gdiplus::Bitmap srcBitmap(temp, FALSE);<br />
Gdiplus::Graphics wndGraphics(dc);<br />
<br />
Gdiplus::SizeF SIZE;<br />
srcBitmap.GetPhysicalDimension(&SIZE);<br />
<br />
int height = SIZE.Height;<br />
int width = SIZE.Width;<br />
<br />
wndGraphics.DrawImage(&srcBitmap, 0, 0);<br />
<br />
SetWindowPos(hwnd,HWND_BOTTOM,0,0,width,height,SWP_NOMOVE |SWP_NOZORDER );<br />
SetWindowPos(staticwindow,HWND_BOTTOM,0,0,width,height,SWP_NOMOVE );<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
firstTime = true;<br />
<br />
<br />
}
<br />
}<br />
|
|
|
|
|
What in the world could cause me to be unable to draw to a blood PICTURE CONTROL?
|
|
|
|
|
Since you are drawing in the dialog windows WM_PAINT handler, when the child window (picture control) gets its WM_ERASEBKGND and WM_PAINT message later causes it to erase the image drawn.
you can do,
1. Why don't you set the Bitmap for the picture control at the time of resource editing or dynamically SetBitmap() and allow the picture control to draw in its way.
2. you may subclass the picture control and draw on its paint handler.
3. you actually don't need a picture control if you are drawing the image, remove the picture control and draw the image on the WM_PAINT handler of the dialog as you are doing now, only difference is you don't want to acquire the DC of Picture control but use the dialogs DC and draw where you want in the dialog (where the picture control is supposed to place)
4. Try set the Transparent style to the picture control in the resource editor
|
|
|
|
|
What does the transparent property do?
I can't do it by resource editing. Whenever I draw on a picture control I never see anything.
I will try SetBitmap tomorrow.
Is there a tutorial on doing the subclassing on the picture control?
|
|
|
|
|
There's not really a "picture control" - it's just a static control
with the SS_BITMAP style. If you're ok with the way the static control
draws its bitmap then you should just be using the static control that way
instead of doing the drawing yourself.
If you need to draw yourself, then you should be doing so in the control's
WM_PAINT handler. The symptoms seem to indicate you're drawing a bitmap
"underneath" (in the z-order) another control - that means you've got the
wrong HWND
Also make sure you handle WM_PAINT properly (for any window). If the invalid
region of the window being painted isn't marked valid after painting, then you get
recurring calls to WM_PAINT - bad for performance! Use BeginPaint() and EndPaint()
in your WM_PAINT handlers (and the DC it provides) and the invalid region updating
will be taken care of by the system.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I know I can use a SendMessage command to a static control to tell it to change its bitmap.
But how do I load a bitmap from a file that's a gif or jpeg or png? Or just from a file in general.
Is there a way to use GDI+ to do this? I can create a bitmap with gdi plus (that's what I'm doing now) but I don't know how to use that in
for SendMessage().
Edit I've tried setting the image with
<br />
SendMessage(GetDlgItem(hwnd,IDC_PICTURE),STM_SETIMAGE,IMAGE_BITMAP, (LPARAM)&srcBitmap);<br />
The srcBitmap variable is a valid bitmap object. Is that not the correct way to do it?
Because at the moment, whenever I set it by clicking on the control, it erases itself and it still gray.
modified on Saturday, May 3, 2008 1:54 PM
|
|
|
|
|
You can't send a Gdiplus::Bitmap to the control....you need to use Bitmap::GetHBITMAP() to
create an HBITMAP to send to the static control.
HBITMAP hbm;<br />
srcBitmap.GetHBITMAP(Color::Black, &hbm);<br />
SendMessage(GetDlgItem(hwnd,IDC_PICTURE), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbm);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
modified on Saturday, May 3, 2008 2:24 PM
|
|
|
|
|
Hi,
Actually i reading one file and list all file details in TreeCtrl and finally i select one thing from the list.
The file contains two details as Name and Category,the file looks like
Name Category
DT002 UNIT OPERATIONS
IND01 CUSTOMS
CRD01 UNIT OPERATIONS
ECH01 CUSTOMS
So, I have to list the details as follow
UNIT OPERATIONS (Parent)
DT001 (child of UNIT OPERATIONS)
CRD01 (child of UNIT OPERATIONS)
CUSTOMS (Parent)
IND01 (child of CUSTOMS )
ECH01 (child of CUSTOMS )
When i made TreeCtrl, what it displays like...
all the things displayed as in file.
UNIT OPERATIONS
DT001
CUSTOMS
IND01
UNIT OPERATIONS
CRD01
CUSTOMS
ECH01
So pls help me.
I have to find the parent items in TreeCtrl and i have to add appropriate name (child) to that
category. Pls help me to sort out the problem????
Anu
|
|
|
|
|
Do you have a problem reading from the file or constructing the tree control or populating it?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
I read from file and made the Treectrl. But i have to populate it na good manner.
In a single parent i have to place three or four child item.
But now i got tree list as
THree child item have the seperate parent item,but all this parent item are same.
Anu
|
|
|
|
|
Anu_Bala wrote: THree child item have the seperate parent item,but all this parent item are same.
What could that possibly mean? Can you just show your code?
While posting a query, please keep the scope narrow as possible and explain *only* the part where you face a problem, along with relevant source code, if any. This would help you get an accurate and fast answer. You've been long enough here to know it though.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
for(int k=0 ; k<pCustInfo->oCustDet.iNoOfModels;k++)
{
HTREEITEM hTree, hModel;
oModel = new SModelInfo;
pCustInfoFile->Read(oModel,sizeof(SModelInfo));
hTree = m_ModelTree.InsertItem(oModel->stModels, TVI_ROOT); ///THIS IS PARENT ITEM
hModel = m_ModelTree.InsertItem(oModel->stModelName, hTree); //THIS IS CHILD ITEM
}
By this coding, i add every same parent and child item in line by line.
But i need all child items from the samr parent in single list.
In codeproject, is any provision to add some image, then i will add screenshot of my treectrl dialog.
Anu
|
|
|
|
|
This code works for me to get two root items with two branch items for each root:
HTREEITEM hRoot, hBranch;
hRoot = m_Tree.InsertItem("Root item 1", TVI_ROOT);
hBranch = m_Tree.InsertItem("Branch of Root 1", hRoot, TVI_LAST);
hBranch = m_Tree.InsertItem("Branch of Root 1", hRoot, TVI_LAST);
hRoot = m_Tree.InsertItem("Root item 2", TVI_ROOT);
hBranch = m_Tree.InsertItem("Branch of Root 2", hRoot, TVI_LAST);
hBranch = m_Tree.InsertItem("Branch of Root 2", hRoot, TVI_LAST);
Note: Please enable the following from the Tree Control properties: Has buttons, Has lines, Lines as root.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Hello,
i created a shell extension for my program but i cannot delete them? Whats going wrong there? Hope someone can help me. Thanks !
<br />
HKEY key;<br />
DWORD res;<br />
<br />
<br />
RegCreateKeyEx(HKEY_CLASSES_ROOT,L"CPACK\\shell\\Extract with CPACK\\command",0,NULL,REG_OPTION_NON_VOLATILE,0xF003F,NULL,&key,&res);<br />
wchar_t *data = L"C:\\cpack.exe e %1";<br />
RegSetValueEx(key,L"",0,REG_SZ,(LPBYTE)data,(DWORD)(lstrlen(data)+1)*sizeof(TCHAR));<br />
RegCloseKey(key);<br />
<br />
RegCreateKeyEx(HKEY_CLASSES_ROOT,L".cpack",0,NULL,REG_OPTION_NON_VOLATILE,0xF003F,NULL,&key,&res);<br />
data = L"CPACK";<br />
RegSetValueEx(key,L"",0,REG_SZ,(LPBYTE)data,(DWORD)(lstrlen(data)+1)*sizeof(TCHAR));<br />
RegCloseKey(key);<br />
<br />
<br />
RegDeleteKey(HKEY_CLASSES_ROOT,L"CPACK");<br />
bye,
gabbana
|
|
|
|
|
You cannot delete a registry key if subkeys exist.
If you were successful with creating the key and subkeys then you should be able to delete them as well. RegDeleteKey will fail with ERROR_ACCESS_DENIED if a subkey exists. You need to implement a recursive deletion[^].
Best Wishes,
-David Delaune
|
|
|
|
|