|
The CString provides operator LPCTSTR to perform the conversion to const char*.
This conversion is implicit if you call a method taking a const char * with a CString.
I find this a bit clunky, but you can use it explicitly and cast away the const like so:
(LPTSTR)(LPCTSTR)str
|
|
|
|
|
CString str = _T("fluff");
LPTSTR psz = str.GetBuffer(0);
str.ReleaseBuffer();
|
|
|
|
|
Worked great. Thanks Mike.
|
|
|
|
|
Have you tried this:
CString str;
(char*)(LPCTSTR)str
|
|
|
|
|
str.GetBuffer(0) does the work. Don't forget to call str.ReleaseBuffer
Also (LPSTR)(LPCSTR)str will be ok in the case you don't plan to play with the buffer
|
|
|
|
|
hi,
I currently tried to add a CMenu menu to a CDialogBar which is docked in a CReBar. My CMenu initialization and ressource loading work fine with a CDialog based dialog window, but it do not load any menu in a CDialogBar ...
(ie5 and most of the win2k dialog does this ...)
ex:
(just after my CDialogBar creation)
m_MyMenu = new CMenu();
m_MyMenu->LoadMenu(IDR_DLGBAR_PRODUCT_EDITOR)
ASSERT_VALID(m_MyMenu);
m_wndDlgBar.SetMenu(m_MyMenu);
m_MyMenu->Detach();
(m_wndDlgBar is correctly docked in my ReBar)
---> no assertion, but no menu displayed !
(this code work if you do a CDialog::SetMenu(m_MyMenu)
I see plenty application doing this, can someone help me ?
thanks in advance,
Benoit
email: authem_b@epita.fr
|
|
|
|
|
The menu bar in IE isn't a menu. It's a toolbar where the buttons have no images, just text.
I have seen an article on how to duplicate the menu bar, but it was a while ago I can't remember where the article was. Probably an issue of MSDN mag (or the old MSJ).
|
|
|
|
|
For anyone interested, the article is on MS's site here and in the VC help under \Periodicals\Periodicals 1999\MSJ\January\Q&A C++
|
|
|
|
|
Does anyone know how to hide Close button from the system menu of a modeless dialog box?
I am able to disable it.
|
|
|
|
|
Hi,
I currently have a Dialog based application written in Visual C++ 6.0 SP2 using MFC 6.0 in the Visual Studio 6.0. I am currently on Windows 98 but the app needs to work under Windows NT 4+, and Windows 2000 as well.
On the dialog box I have implemented 'F1' help. I did override OnHelpInfo() so that I could specify which control to get help for (standard windows operation is to get help on the 'dialog', not each control).
Now I am trying to implement 'Shift+F1' help. When the user clicks on the '?' in the title bar, or presses 'Shift+F1' the cursor changes to the 'Help cursor' and they should get help for the next item they click. In this app the cursor does change properly, but I am having trouble catching the info about the control they click.
If I go to my override of OnHelpInfo(), this function does get run but the dwContextId member of the HELPINFO structure is NULL.
I checked out the MSDN help and according to technical note 028, the application should post a message WM_HELPHITTEST, when the user clicks the control with the 'Help Cursor', to the CWnd which was clicked, and then to its parent, etc.
I have included that message in my Message Map and it does not appear to have been posted because my dialog box is not catching that message.
Any thoughts on how I can identify on which control the user wants help?
Any info will be appreciated
Jeff
|
|
|
|
|
I had to hack on the fnction to get at the control identifier. Also the data means different things at different times. I tried to accomodate all the cases I have observed in my dialog based programs.
I use tabs instead of spaces, so deal with it...
Here is code snippet from function:
//- -----------------------------------------------------------------
//- help file functions
BOOL CGCDialog::OnHelpInfo(
HELPINFO* pHelpInfo
){
// pretend we handled request if help file does not exist
if( !DoesAppHelpFileExist() ){
return TRUE;
}
if( pHelpInfo && (pHelpInfo->cbSize >= sizeof(HELPINFO)) ){
switch( pHelpInfo->iContextType ){
// menu item handlers
case HELPINFO_MENUITEM:{
// menu item help
LPARAM lParam = HID_BASE_COMMAND + pHelpInfo->iCtrlId;
AfxGetApp()->WinHelp(lParam);
return TRUE;
}break;
// most all other windows
case HELPINFO_WINDOW:{
if( -1 == pHelpInfo->iCtrlId ){
// clicked somewhere in dialog box client area
CDialog::OnHelpInfo(pHelpInfo);
} else if( this != GetActiveWindow() ){
// probably invoke help topic for dialog
// or help context for message box, if set
CDialog::OnHelpInfo(pHelpInfo);
} else if( IsControlWithoutHelp(pHelpInfo->iCtrlId) ){
pHelpInfo->iCtrlId = -1;
CDialog::OnHelpInfo(pHelpInfo);
} else {
// avoid trying to get context sensitive help on
// controls with values less than 100, since they
// are probably generic controls like OK and Cancel anyway.
// talk about them in dialog's main help instead
if( pHelpInfo->iCtrlId >= 100 ){
LPARAM lParam = HID_BASE_CONTROL + pHelpInfo->iCtrlId;
AfxGetApp()->WinHelp(lParam);
return TRUE;
}
// probably invoke help topic for dialog
return CDialog::OnHelpInfo(pHelpInfo);
}
}break;
// not menu or window, though I rarely ever see this...
default:{
// probably invoke help topic for dialog
return CDialog::OnHelpInfo(pHelpInfo);
}break;
}
}
// pass it on if all else fails
// probably invoke help topic for dialog
return CDialog::OnHelpInfo(pHelpInfo);
}
|
|
|
|
|
Thanks Blake,
I have no idea why I didn't think of looking at all the members of HELPINFO to find the iCtrlId item. That is exactly what I need, and it works for F1 help as well, so I can trash my previous work around.
Just in case anyone is interested, Brad Robinson replied to my post in the CodeGuru Visual C++ forum with a different solution, he suggested grabbing the Window Handle member of HELPINFO (hItemHandle) and then translating that to a Control ID. That works as well.
Thanks for the assist
Jeff
|
|
|
|
|
Help!!!
I'm tring to create a dialog with the following two lines:
I am string Number 1
I am string number 2
Now, depending on what the user selected beforehand is dependant on which of the above strings is dispplayed on the dialog.
But how do you do it? This is a prelude to more sophisticated dialog, but I need to know how I can change the content of an individual dialog that is dependant on the users selection.
Any help would be great.
Regards
John
|
|
|
|
|
Hi John,
I'm going to guess that you are using the Microsoft Foundation Classes (MFC 6) in the Visual Studio IDE, if this is not true, please specify your environment.
If you go to the 'resources' tab in the 'workspace' you can add a new dialog by right-clicking on the 'dialog' folder in that area and selected 'Insert Dialog'.
By right clicking on the new dialog box you can fill in the 'properties' of this dialog box. Name it something useful such as 'IDD_MAIN_DIALOG' that you will understand later. (using the IDD_ prefix will come in handy later if and when you want to create context sensitive help).
On the dialog put two edit box controls (drag them from the 'controls' tool bar. In the property for each control, fill in the 'id' as something useful like IDC_FIRST_MESSAGE and IDC_SECOND_MESSAGE. (using the prefix of IDC_ comes in handy when you want to have context sensitive help).
You can leave the OK and Cancel buttons there or remove them as necessary.
Now that these edit boxes exist, Save the whole thing. Right click on the dialog box and selected 'Class Wizard'. It will ask you if you want to create a new class, say yes. You will inherit from CDialogBox. Name it something appropriate.
Now when you go back to your 'Class View' tab in the Workspace, you will see that newly added class. You can add a function called OnInitDialog. When the dialog opens, after it is created, but before it is displayed it will run the OnInitDialog() function. You can check parameters here and use the commands 'SetWindowText()' to set up the values in each of the edit boxes before the window opens.
I know this is a quick overview, but it should help to get you started, and as you have more specific questions you should be able to find what you are looking for in the documentation or by posting more specific questions out here.
Hope this helps
Jeff
|
|
|
|
|
Hi all,
been looking at the DIBsection wrapper class of Chris Maunder. Good code but one thing i need is missing: transparent drawing. Anybody have some code (does not have to be usable with the DIBsection wrapper class) that does a fast dib transparent transfer?
Also, from what i read in MSDN, seems there is some support for png files. Anybody have code that loads such a file?
Seems to me (if i read ok) that for fast drawing, working internally with dib is best. Anyone can confirm this?
Thanx a lot in advance
|
|
|
|
|
Made a small class that manages the png (and internally dib) file format.
Also has ability to display png files transparently.
It's all that i wanted so don't bother anymore.
Thanx.
|
|
|
|
|
The following code will give me a dialog box that will allow
a user to choose a directroy.
It does return me the directory name, but I also need the full path to the directory.
How do I get the full path to the directory??????
Thanks in advance.
void CSwapObjectsView::DoDirectoryDialog(CString& strDir)
{
char szDisplayName[MAX_PATH] = "";
char szTitle[] = "Choose a directory";
BROWSEINFO x;
memset(&x, NULL, sizeof(BROWSEINFO));
x.hwndOwner = this->m_hWnd;
x.pszDisplayName = szDisplayName;
x.lpszTitle = szTitle;
x.ulFlags = BIF_RETURNONLYFSDIRS ;
SHBrowseForFolder(&x);
|
|
|
|
|
Here's the bare-bones code to do it. Adding error handling is left as an exercise to the reader.
LPITEMIDLIST pidl;
LPMALLOC pMalloc;
TCHAR szDir[MAX_PATH];
pidl = SHBrowseForFolder(&x);
SHGetPathFromIDList ( pidl, szDir );
SHGetMalloc(&pMalloc);
pMalloc->Free(pidl);
pMalloc->Release();
|
|
|
|
|
I have been trying to display a bitmap on a button when the button is disabled but this does not seem to work. The bitmap is a gray and black image only when the button is disabled. What special things have to be done in order to display a bitmap on a disabled button.
|
|
|
|
|
Somebody knows how to access bits directly in the bitmap without calling GetBitmapBits(GetDIBits) and SetBitmapBits(SetDIBits).
Thanks
|
|
|
|
|
Hi,
I have a dialog with a Slider control that will show the user the number which has been randomly generated. I need to keep generating such value as long as the user doesn't click a button mouse.
I tried to use
// inside my CDialog-derived::OnStart()
MSG msg;
while (!::PeekMessage(&msg,HWND(this),WM_LBUTTONDOWN,WM_MBUTTONUP,PN_NOREMOVE))
{
value = rand() % range;
m_SliderCtrl.SetPost(value);
}
// return from member function
but it didn't work, i can't get the mouse LButtonDown message to stop cycling. Does anyone have a solution?
|
|
|
|
|
How do you make a combo box and list contain the drives and files on the system? Visual Basic has the controls predfined but is there a way to do it in VC with MFC? Thanks in advance.
|
|
|
|
|
I don't use VB, so I don't know what the VB controls look like, but from your description it sounds like you want to use the DlgDirList, DlgDirSelectEx, DlgDirListComboBox, and DlgDirSelectComboBoxEx APIs to fill the controls.
|
|
|
|
|
If I create several modeless dialogs, how do I keep track of what happens in each one of them?
I couldn't find much information on this subject, so I'd really appreciate any help! Does anyone
know some good links or samples on modeless dialogs?
Thanks in advance!
|
|
|
|
|
Could you give a little more info on what you are trying to do ? The message handling routines work the same, whether
in Modal or Modeless. Are you having problems communicating
data between the various modeless dialogs that you have
set up ?
|
|
|
|