|
Thanks for the tip Cedric. I tried it, and got the following error:
c:\documents and settings\michael hwang\my documents\visual studio 2005\projects\directinput\directinput\main.cpp(24) : error C2664: 'CSerial::Open' : cannot convert parameter 1 from 'const char *' to 'LPCTSTR'
Maybe I need to make it 'const wchar *' because of UNICODE? How would I do that?
|
|
|
|
|
The _T() macro is intended for use only with constant strings:
_T("Constant string")
#define ConstantString "Constant string"
_T(ConstantString) It's used when your application needs to be compiled for either MBCS (multi-byte character set) or UNICODE. MBCS is the fancy name for ASCII/ANSI applications. UNICODE is useful for when you need to handle Japanese/Chinese text, for example, which requires two bytes per character.
A string of the form "string" is compiled as a MBCS string, and L"string" as a UNICODE string. The _T(arg) is defined as simply arg in the MBCS case and as L##arg in the UNICODE case.
More than you ever wanted to know, I'm sure .
Software Zen: delete this;
|
|
|
|
|
I have three USB devices programmed at the same time. One of them finishes programming first and two of them are still programming. The three device has the same GUID with different addresses (if using devcon find command). the requirement is that to safely remove the one which is already finished programming and leave the rest of two continue to program until finished
fuxiangwu
|
|
|
|
|
Hi,
I'm learning MFC, with prior experience in java, so I have a little bit of understanding about the general concept of a document and a view (I hope).
I'm trying to figure out some missing knowledge I don't have about the concept of Document/View in MFC when using a splitter window.
I have two questions. The first question, I will explain something I did and ask your advice. I think I did it the "right" way, but I'm not 100%. By the right way, I am meaning, the way that makes the most sense and uses MFC as properly as possible. I know there are lots of ways to do the same thing, I am just hoping I did it the most appropriate way.
My second question points out that I am missing something major. I know I did it the wrong way. Could you point me towards the proper way?
All this was done in Visual Studio 2005.
Question 1:
I have a MainFrame and the App Wizard added a window splitter for me. I made the splitter static with one row, two columns. The left pane has a CTreeView subclass. The right pane displays one of two CFormViews, call them info_pane_1 and info_pane_2 (imagine a project settings kind of situation). There are two items in the left CTreeView pane, clicking on the first item causes info_pane_1 to appear in the right pane. Similarly, clicking on the second item causes info_pane_2 to appear in the right pane.
I didn't implement any of the fancy splitter stuff myself, I used "CUsefulSplitterWnd" on this website. The only code I needed to add was a message handler, OnTvnSelchanged(...) to my CTreeView subclass. In this function, I figure out which item was clicked on in the tree view, then I get a pointer to the parent frame (MainFrame). I call a new member I added to MainFrm.cpp called ChangeDialog(int which). The variable "which" is either 1 for info_pane_1 or 2 for info_pane_2. The function ChangeDialog(...) in MainFrm.cpp is just:
(paraphrasing)
switch(which)
case 1:
m_wndSplitter.ReplaceView(0,1,RUNTIME_CLASS(info_pane_1),...)
or
case 2:
m_wndSplitter.ReplaceView(0,1,RUNTIME_CLASS(info_pane_2)
Everything works exactly as I had hoped; Clicking in the tree (in the left pane) dynamically changes what appears in the right pane.
Did I do this the right way?
Question 2:
Here is where I'm confused about how to properly use the Doc/View architecture. What I need to do is simple: The user clicks on the various checkboxes and radio-boxes in info_pane_1, and I have an "Apply" button. When the user clicks "Apply", the state of the controls in info_pane_1 need to be saved. I want to save all this information into the CDocument so that I can use the serialize functions to save all the settings for all the controls. The first thing I did, which I think is correct, is to add control member variables to my classes info_pane_1 and _2. When the user clicks "Apply", I just call UpdateData. So it looks like this:
info_pane_1::OnBnClickedApplybutton()
{
UpdateData(TRUE);
}
This works correctly.
However, now I notice an issue. Whenever I call replaceview in the UsefulSplitterWnd class, it gets rid of the old view that was in the right pane of the splitter (including the class!) (the class is deleted?) and makes a brand new one to put into the right pane. I know this for sure because I can just put a breakpoint in the constructor for whatever class is put into the right pane. So, I've lost all the control settings the user has chosen. But I think this is ok and kind of the right behavior; I should be storing this data into the CDocument not really the pane. So what I do is the following:
First I add a "BOOL checkboxstate" to the CDocument subclass that the App Wizard made for me. Then I change OnBnClickedApply:
void info_pane_1::OnBnClickedApplybutton()
{
UpdateData(TRUE);
CCodeBuilderDoc *p_Doc = (CCodeBuilderDoc *) GetDocument();
ASSERT_VALID(p_Doc);
p_Doc->state_InsertionSortCheck = state_InsertionSortCheck;
}
Maybe this is not the most correct way to do it? It seems like I've missed something.
In any case, now that I've saved the information into the CDocument, I now need to get it when the new view is inserted into the right-hand splitter pane by UsefulSplitterWnd. So what I did was:
void info_pane_1::OnDraw(CDC *pDC)
{
CCodeBuilderDoc *p_Doc = (CCodeBuilderDoc *) GetDocument();
ASSERT_VALID(p_Doc);
state_InsertionSortCheck = p_Doc->state_InsertionSortCheck;
UpdateData(FALSE);
}
This seems to me to be obviously wrong.
I am pretty sure the following things are either broken or confused as a result:
1. I bet CDocument::UpdateAllViews doesn't work.
2. I don't understand why my project/solution has a CMyAppView descended from CView in MyAppView.cpp/.h. I haven't done anything to this class. Is it being used?
I think my question 2 is, how should I have done this? I've clearly done it the wrong way.
Thanks gurus for your comments and help. I am new to MFC, only about 5 days into learning it/working with it. I think I've learned a lot, but I think I don't have a good understanding of what to do with this Document/View architecture.
Thank you so much for any help. I hope to type up a little tutorial on this, as I've seen a number of questions on split windows and Doc/View. I'll add your credits to the tutorial. I hope that perhaps it will be accepted as a tutorial on codeproject.
|
|
|
|
|
maxmaven wrote: think I don't have a good understanding of what to do with this Document/View architecture
Don't feel bad; document/view isn't the easiest thing in the world, which may explain why it's not very popular.
maxmaven wrote:
void info_pane_1::OnDraw(CDC *pDC)
{ CCodeBuilderDoc *p_Doc = (CCodeBuilderDoc *) GetDocument();
ASSERT_VALID(p_Doc);
state_InsertionSortCheck = p_Doc->state_InsertionSortCheck;
UpdateData(FALSE);
}
Instead of getting the check state from your document and initializing the view in your OnDraw override, you should do it in either your OnInitialUpdate() or OnUpdate() override.
maxmaven wrote: I don't understand why my project/solution has a CMyAppView descended from CView in MyAppView.cpp/.h. I haven't done anything to this class. Is it being used?
If you aren't referencing it and haven't implemented it, you can probably remove it. As a suggestion, save a copy of your project and its source files in another folder, so that if you need to revert back to its current state, you can.
Software Zen: delete this;
|
|
|
|
|
This is why I'm confused. So just to recall, I have UsefulSplitterWnd and two child views of the split. The left one is a CTreeView and the right one is a CFormView. Each of the CFormViews has an associated dialog that it displays.
Here's what I've tried with these CFormViews. First, I tried overriding OnCreate(...). But this function is never called at any time during execution of my application.
Next, I tried overriding OnUpdate(...) and OnInitialUpdate(...). I put breakpoints in these functions and found that they are only executed once, at the start up of the application. They are never called again, even when CUsefulSplitterWnd::replaceview(...) is called.
There are basically two important functions that CUsefulSplitterWnd::replaceview(...) calls. They are:
((CView *) GetPane(row,col))->DestroyWindow();
This destroys the window associated with the CFormView. However, in searching the MSDN help docs, it says that this function doesn't destroy the CFormView class object. So my class must be around somewhere (?).
The second important function is:
context.m_pNewViewClass=pViewClass;
context.m_pCurrentDoc=pDoc;
context.m_pNewDocTemplate=NULL;
context.m_pLastView=NULL;
context.m_pCurrentFrame=NULL;
CreateView(row,col,pViewClass,size, &context);
This should be telling me what function I need to override so that the dialog is initialized to the saved values in my CDocument subclass. But, I tried all the sensible functions. They are either never called in the app, or only called once at app startup.
I'm pretty lost.
Max
|
|
|
|
|
Hello,
is it possible to load the windows default color scheme for a dialog and discard the settings of the current scheme?
I dont want to do it by hand.
|
|
|
|
|
hey there fellow cpians.. Hope all is good. I wonder if anyone can help me with
my right-click context menu problem.
my problem is that when i display my menu it is displayed at the top-left of my application
and no where near where the mouse icon is, when the right button was clicked!
here is the code i am using in my function: OnContextMenu
<br />
CMenu menu;<br />
<br />
if (menu.LoadMenu(IDR_MENU1))<br />
{<br />
ClientToScreen(&point);<br />
CMenu *pContextMenu = menu.GetSubMenu(0);<br />
pContextMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);<br />
}<br />
I think my issue has something to do with ClientToScreen or i need to call ScreenToClient maybe.. If i leave out the call to ClientToScreen then the menu is displayed at the top-left of the screen.
thanks in advance.
|
|
|
|
|
dont worry about this one guys..
i have replaced ClientToScreen with the function GetCursorPos and all is rosey!!
|
|
|
|
|
Hi all,
I want to know how much memory is allocated by SafeArrayCreate()
Is there any std. functons?
Thanks,
Gan
|
|
|
|
|
I guess you have not checked SAFEARRAY documentation.
|
|
|
|
|
Hi guys,
We have a string table in a lib file(a.lib)
We are linking that a.lib file to a comdll (b.dll) and try to get the strings from a.lib 's string table. I got the string no probs.
When I changed the string table in the lib (a.lib), like altering the strings, adding new string items, I can see the changes in the string table
But I can't get the changed strings or newly added strings.With changed strings, Changes are not reflected ; With newly added string the fn. returned false and I got the error 1814.
And I can see the updated strings, when I open the a.lib in text mode.(vc++6.0 editor)
(when I updated the string table using resource editor I got error RC2104. Then I updated that .rc file by opened it in text mode and updated the string table. By this only I was able to update the string table)
Anybody knows the reason?
thanks,
Gan
|
|
|
|
|
Hi GANsJob,
I think your b.dll is still loaded. Check this.
Greetings
Ralph
|
|
|
|
|
hi, i have created a program that uses several different header files and to make it easy for all header files to access stuff i had all my cpp files just reference 1 file that includes all my header files. all of the files compile fine except 1 which complains about a undeclared variable that is part of one of my classes but what makes no sense is that that source file sees my class with that variable in it just fine and intellisense shows the class variable that is supposedly undeclared. thanks in advance for any advice anyone can give me.
|
|
|
|
|
Sounds like we need to see the code.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
here is the function that has the problem:
typedef void (*MYPROC)(LPTSTR);<br />
MYPROC ProcAdd;<br />
BOOL fRunTimeLinkSuccess;<br />
Load *a;<br />
Loader *b;<br />
<br />
a->Hide(load_window);<br />
b->Hide(loader_window);<br />
<br />
hinstLib = LoadLibrary(program);<br />
if(hinstLib != NULL)<br />
{<br />
ProcAdd = (MYPROC)GetProcAddress(hinstLib, "?prog_start@@YAHXZ");<br />
if(fRunTimeLinkSuccess = (ProcAdd != NULL))<br />
{<br />
(ProcAdd)("?prog_start@@YAHXZ");<br />
}<br />
else{<br />
MessageBox(m_hWnd, "Program Failed to Load", "Fail", MB_ICONSTOP);<br />
<br />
EndDialog(m_hWnd, IDOK);<br />
}<br />
}<br />
else{<br />
MessageBox(m_hWnd, "Loader Failed to open program", "Fail", MB_ICONSTOP);<br />
reportError();<br />
}<br />
fFreeResult = FreeLibrary(hinstLib);<br />
<br />
b->Show(loader_window);<br />
a->Show(load_window);
not exactly the best way to load a dll file but it works for what i was doing right now to test stuff with. loader_window is the one that can not be seen, it is a hwnd variable to one of the windows in my program.
and here is the code where i have everything being included:
#ifndef MAIN_H<br />
#define MAIN_H<br />
<br />
#include <windows.h><br />
#include <sstream><br />
#include "..\common\win32.h"<br />
#include "resource.h"<br />
#include "loader.h"<br />
#include "load.h"<br />
#include "help.h"<br />
#include "version.h"<br />
<br />
#endif
|
|
|
|
|
You probably need to understand the difference between declared and defined.
declaring a variable tells the compiler that such a variable exists somewhere [else].
defining a variable causes the variable to exist.
This is somewhat of a simplification for the sake of a quick answer
You may be seeing an undefined variable error for a variable that is declared in your header file; that is, you told the compiler that the variable exists but it doesn't exist. Compilers (and linkers) don't like being lied to.
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
|
|
|
|
|
where this "loader_window" is declared?
It should be declared as a global variable, if you want to use it in the code you posted.
Check the variable's scope.
|
|
|
|
|
well i had it as global but because of how my code is set up, i can not really compile the program very easily without having to force the program to be compiled because it will get included more than once and the 15+ warnings it gives got annoying to look at and unless i do force it to compile than it will register as errors instead.
|
|
|
|
|
just paste the code of the headers in which you have declared th variables.
|
|
|
|
|
I've created a class which loads a dialogue box, from a resource created in Visual Studio 2003.
I need to run some intialization code, so set labels corrected basied upon some paramters passed in. I've tried catching WM_CREATE in the DlgProc method, however the WM_CREATE message is never passed into the methods.
How would I be able to run some code when the dialog starts up?
|
|
|
|
|
|
OnInitDialog() [^] is the appropriate place to put dialog initialization code.
/ravi
|
|
|
|
|
It doesn't sound as if he's using MFC. He needs to handle WM_INITDIALOG, which is (roughly) the dialog equivalent of WM_CREATE.
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
|
|
|
|
|
I am looking for software to tune my accoustic piano. I have found free software that does that for guitars but, obviously, doesn't go low enough or high enough in frequencies to do my piano. The same holds true for my son's electronic guitar tuner.
If anyone knows of "open source" software (preferably Visual C++ / MFC) that for guitars that I could mofify to extend wide enough to do pianos would be greatly appreciated. If I am able to convert it into a useful application, I will gladly post it here.
Thank you in advance
Pierre
|
|
|
|
|