|
Here's some code I use to avoid using a UNICODE file in a non-unicode build (gpfs the kernel):
#if !defined(_UNICODE)
DWORD dwBytesRead;
ReadFile(hFile, szBuf, 4096*sizeof(TCHAR), &dwBytesRead, NULL);
if(dwBytesRead > 7) {
DWORD dwUnicode = IsTextUnicode(szBuf, dwBytesRead, NULL);
if(dwUnicode) {
m_bStringsLoaded = FALSE;
retval = MD_UNICODE_ERROR;
}
}
#endif
Not guaranteed to work for small strings - hence the '> 7' check (as if thats gonna help me!). Check the docs for IsTextUnicode - interesting stuff.
|
|
|
|
|
Thanks. It works For me.
Cheers
Kannan
|
|
|
|
|
I'm trying to use the windows media player active-x control in my app but i can't seem to load a file. This is what i have:
CString Movie = "C:\mymovie.avi";
m_cPlayer.SetFileName(Movie);
m_cPlayer.Play();
i tried to put "file:///" before the path because some web related stuff needs it, but that didn't work either.
How do i load the file?
Thanks
Kuniva
|
|
|
|
|
The backslash should be typed twice:
CString Movie="C:\\mymovie.avi";
...
|
|
|
|
|
In msdn ,in "Recordset: Locking Records (ODBC)",It
said "Relatively few ODBC drivers currently support pessimistic locking."
How can I know my ODBC driver support pessimistic locking?
|
|
|
|
|
SQLGetInfo should do it.
Regards,
Alvaro
|
|
|
|
|
- How to change the size of a toolbar?
- How to add/remove a image of a toolbar?
- Can you help?
- Regards,
BigMouth
|
|
|
|
|
Use SetSizes() to change the size of toolbar buttons.
The height of a toolbar will be the height of the buttons.
And the width will be the width of the containing window
For images use an image list and send a TB_SETIMAGELIST message. If you want to change the images, change the image list and send the TB_SETIMAGELIST message again
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
- Thanks pal!
- I still have a question. Can you show me an example about the usage of TB_SETIMAGELIST message?
- Have a nice day,
BigMouth
|
|
|
|
|
You can actually modify the imagelist directly - m_wndToolbar.GetToolbarCtrl().GetImageList() returns a pointer to the image list, and you can then use ExtractIcon to pull an image out, or Add or Replace to add an image or replace one respectively.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
- Thanks pal!
- I use the following codes, but it seems that it does not work.
void CMainFrame::OnEditCopy()
{
// TODO: Add your command handler code here
CImageList* list1=this->m_wndToolBar.GetToolBarCtrl().GetImageList();
list1->Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
}
- Can you help me out?
- Regards,
Maer
|
|
|
|
|
I did this
m_wndToolBar.GetToolBarCtrl().GetImageList()->Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
CWindowDC w(NULL);
w.DrawIcon(0, 0, m_wndToolBar.GetToolBarCtrl().GetImageList()->ExtractIcon(list1->GetImageCount()-1));
AfxMessageBox("");
in OnCreate on a vanilla SDI app, and the icon is there, plain as day. You didn't expect to see it in the toolbar, did you ? It's in the image list, but you need to create a new button or change the image index of an existing button for the toolbar to show it.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
- Thanks pal!
- I use the following codes. But it has no effect.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
CImageList* list1=this->m_wndToolBar.GetToolBarCtrl().GetImageList();
m_wndToolBar.GetToolBarCtrl().GetImageList()->Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
CWindowDC w(NULL);
w.DrawIcon(0, 0, m_wndToolBar.GetToolBarCtrl().GetImageList()->ExtractIcon(list1->GetImageCount()-1));
AfxMessageBox("");
return 0;
}
- Can you help?
- Have a nice weekend,
BigMouth
|
|
|
|
|
What do you mean by no effect ? Like I said, this will add the image to the imagelist, and draw it on the top left of your screen in order to prove that it's there. But you've still not added a button with this image, so it's still not going to be on the toolbar. You need to fill a TBBUTTON structure with info including the index of this image, then call AddButton to add that button to the toolbar.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
- Thanks, Christian pal!
- Sorry, I have misunderstood your meaning before. I am a newbie of CToolBar. I have never modified it before. Now I find it is a hard work for me. So, if it does not take very much of your time, could you show me a simple example of your method?
- Have a nice weekend,
BigMouth
|
|
|
|
|
Sure - this is how you'd add a button with the bitmap we've been putting into the image list, which calls OnFileNew:
int index = m_wndToolBar.GetToolBarCtrl().GetImageList()->Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
TBBUTTON btn;
btn.fsStyle = TBBUTTON;
btn.fsState = TBSTATE_ENABLED;
btn.idCommand = ID_FILE_NEW;
btn.iBitmap = index;
m_wndToolbar.GetToolBarCtrl().AddButtons(1, &btn);
Note we store the index of the image and pass it to the button, and we pass in the ID of the command we want the button to execute.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
- Thanks, Christian pal!
- I think the statement 'btn.fsStyle = TBBUTTON;' should be written like this 'btn.fsStyle = TBSTYLE_BUTTON;'. IMHO
- And there is still a trouble. When I am testing your codes, the new toolbar button has no image attached to it.
- Can you help?
- Regards,
BigMouth
|
|
|
|
|
1. Absolutely correct, I posted in a hurry.
2. Then you've not set the image index to be the index of your new image in the image list.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
- Thanks, warm-hearted Christian pal!
- Can you tell me how to set the image index to be the index of my new image in the image list? I find the work is easy to think, but it is hard to implement for a newbie, like me.
- Can you help?
- Regards,
BigMouth
|
|
|
|
|
OK - the line:
m_wndToolBar.GetToolBarCtrl().GetImageList()->Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
returns the index of the new image, and so that is the index iBitmap needs to be set to when creating the new button. The code I posted previously actually did that, you're saying it's not working ?
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
- Thanks, Christian!
- The method still has a problem. The newly added toolbar button has no image on it.
- Such are my codes: (OnCreate())
int index = m_wndToolBar.GetToolBarCtrl().GetImageList()->Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
TBBUTTON btn;
btn.fsStyle = TBSTYLE_BUTTON;
btn.fsState = TBSTATE_ENABLED;
btn.idCommand = ID_FILE_NEW;
btn.iBitmap = index;
m_wndToolBar.GetToolBarCtrl().AddButtons(index, &btn);
m_wndToolBar.GetToolBarCtrl().GetImageList()->Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
- Can you help me out?
- Regards,
BigMouth
|
|
|
|
|
I don't understand what the last line is for, why add the icon again ?
I also don't get why you need to do it this way, given that GetImageList returns a pointer, but here is what you need:
CImageList * pList = m_wndToolBar.GetToolBarCtrl().GetImageList();
int index = pList->Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
m_wndToolBar.GetToolBarCtrl().SetImageList(pList);
TBBUTTON btn;
btn.fsStyle = TBSTYLE_BUTTON;
btn.fsState = TBSTATE_ENABLED;
btn.idCommand = ID_FILE_NEW;
btn.iBitmap = index;
m_wndToolBar.GetToolBarCtrl().AddButtons(1, &btn);
Note that you pass the number of buttons to add to addbuttons, not the index ( which is not even necessarily the index of the button you're adding ).
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
- Thanks Christian!
- I tried your codes in the OnCreate function of an MDI app. It does not have the desired effect.
- Such is the effect:
1) It removes the 'help' toolbar button.
2) No new toolbar button appears.
3) All the toolbar button becomes a bit bigger.
- I do not know why? Have you tried your codes?
- Can you help, pal?
- Best regards and Merry Christmas to you,
BigMouth
|
|
|
|
|
I tested this code on an app at work, and again now on another app at home. It works fine.
Try it again, and try also to take the time top understand *why* it works. That is the path to not having to ask next time, and also to being able to figure stuff out for yourself.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
- Thanks, Christian pal!
- Today, I run the app again. I find everything is Ok. But I never change the code!!! Just like yesterday!!!
- Ok, I am puzzled.
- Best regards,
BigMouth
|
|
|
|