Getting windows caption from process ID - c

I have a process ID, what I want to do is return the class. If it is the desired class then return the caption, how do I do that?
C Visual Studio 2008, XP SP3

Use EnumWindows with GetWindowThreadProcessID to find the HWND with the matching process ID that you're looking for.
Once you have the HWND you can use GetClassName to get the class name.
Once you have the HWND with the class you want you can use either:
SendMessage to send a WM_GETTEXT.
Or GetWindowText
Read Raymond Chen's post here on the differences.

Related

How do I replace MFC CDailog::OnTimer with ATL CAxDialogImpl method?

I had wrote a CMyDailog with MFC based on CDialog. And there is a OnTimer method override the CDialog one.
CMyDailog : public CDialog
{
afx_msg void OnTimer(UINT_PTR nIDEvent)
}
Now, we are migrating our MFC code to ATL. I have to make CMyDailog inherited from CAxDialogImpl<CMyDailog>.
CMyDailog : public CAxDialogImpl<CMyDailog>
{}
I didn't find an equivalent of CDialog::OnTimer in the ATL side. Do I have to use the Windows API ::SetTimer(GolbalTimerFunction) to achive that? In that case, I have to move my original member variable values into the globe scope -- I don't like that.
I find this maybe help:
https://www.codeproject.com/Messages/2870588/what-is-the-event-i-should-use.aspx
I found the equivalent one.
LRESULT OnTimer(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
For more detail

Design a receipt and print it in wpf?

I want to print a receipt in wpf with out using report viewer or crystal report. I want to use only print dialog box in wpf.
Here's a snippet of code showing very simple usage of crystal. This has a reportviewer involved, but that is optional as I explained in comments.
ReportDocument rpt = new CrystalReport1();
Person person = new Person
{
JobTitle="Director",
Gender="M",
HireDate = new DateTime(2015,1,1)
};
List<Person> OnePerson = new List<Person>();
OnePerson.Add(person);
rpt.SetDataSource(OnePerson);
crystalReportViewer1.ReportSource = rpt;
crystalReportViewer1.Refresh();
Here CrystalReport1 is in my solution like any class or window and I've designed it there.
That can be built against any table stored procedure view or class. If you work vs a database then you could use odbc to read from there but this is rarely a good idea and you're best getting the data externally.
So long as you present data to the report which has the same fields with matching types in it then it'll take a List even if you design against a database. This means you can easy set up a dummy table with data in it and prototype quickly. Then later switch over to an entirely different source.

How to create Visual Studio 2012 WPF custom designer/editor [duplicate]

Im trying to write a editor extension for Visual Studio. I have the downloaded VS SDK and created a new Visual Studio Package project. But the dummy control created for me is a Windows Forms control and not a WPF control. I'm trying to replace it with a WPF-control but not doing so well. Is this possible anyhow?
Another related question: Is it only possible to write text-editors? What I really want is a editor that looks more like a form with many different fields. But it doesn't seem to be what this is made for? There are a lot of interfaces on the EditorPane that imply a text-editor model only.
Ideally I want a editor much like the resx-editor where the file being edited has xml-content and the editor-ui is not a single textbox and where a generated cs-file is being outputted as a sub-file. Is this possible to do with editor extensions?
This is explained in detail here: WPF in Visual Studio 2010 – Part 4 : Direct Hosting of WPF content
So, if you use the standard Extensibility / Custom Editor sample that comes with the Visual Studio SDK, what you can do to test it is this:
1) Modify the provided EditorFactory.cs file like this:
// Create the Document (editor)
//EditorPane NewEditor = new EditorPane(editorPackage); // comment this line
WpfEditorPane NewEditor = new WpfEditorPane(); // add this line
2) create for example a WpfEditorPane.cs file like this:
[ComVisible(true)]
public class WpfEditorPane : WindowPane, IVsPersistDocData
{
private TextBox _text;
public WpfEditorPane()
: base(null)
{
_text = new TextBox(); // Note this is the standard WPF thingy, not the Winforms one
_text.Text = "hello world";
Content = _text; // use any FrameworkElement-based class here.
}
#region IVsPersistDocData Members
// NOTE: these need to be implemented properly! following is just a sample
public int Close()
{
return VSConstants.S_OK;
}
public int GetGuidEditorType(out Guid pClassID)
{
pClassID = Guid.Empty;
return VSConstants.S_OK;
}
public int IsDocDataDirty(out int pfDirty)
{
pfDirty = 0;
return VSConstants.S_OK;
}
public int IsDocDataReloadable(out int pfReloadable)
{
pfReloadable = 0;
return VSConstants.S_OK;
}
public int LoadDocData(string pszMkDocument)
{
return VSConstants.S_OK;
}
public int OnRegisterDocData(uint docCookie, IVsHierarchy pHierNew, uint itemidNew)
{
return VSConstants.S_OK;
}
public int ReloadDocData(uint grfFlags)
{
return VSConstants.S_OK;
}
public int RenameDocData(uint grfAttribs, IVsHierarchy pHierNew, uint itemidNew, string pszMkDocumentNew)
{
return VSConstants.S_OK;
}
public int SaveDocData(VSSAVEFLAGS dwSave, out string pbstrMkDocumentNew, out int pfSaveCanceled)
{
pbstrMkDocumentNew = null;
pfSaveCanceled = 0;
return VSConstants.S_OK;
}
public int SetUntitledDocPath(string pszDocDataPath)
{
return VSConstants.S_OK;
}
#endregion
}
Of course, you will have to implement all the editor logic (add interfaces, etc.) to mimic what's done in the Winforms sample, as what I provide here is really the minimal stuff for pure demonstration purposes.
NOTE: this whole "Content" thing only works starting with Visual Studio 2010 (so you need to make sure your project references Visual Studio 2010 assemblies, which should be the case if you start a project from scratch using Visual Studio 2010). Hosting WPF editors within Visual Studio 2008 is possible using System.Windows.Forms.Integration.ElementHost.
I'm not sure if the above is possible but a quick search did turn up this:
http://karlshifflett.wordpress.com/2010/03/21/visual-studio-2010-xaml-editor-intellisense-presenter-extension/
and this:
http://blogs.msdn.com/b/visualstudio/archive/2009/12/09/building-and-publishing-an-extension-for-visual-studio-2010.aspx
Failing that, could you not host a WPF control inside the winforms control using ElementHost? I know its a lame workaround but might allow you to develop in your favourite toolkit while you find a more permanent solution.
Best regards,
There is a sample VS Extension Package application source code on MSDN: Designer View Over XML Editor.
Description from site:
This Sample demonstrates how to create an extension with a WPF-based Visual Designer for editing XML files with a specific schema (XSD) in coordination with the Visual Studio XML Editor.
Admittedly solution is dedicated for VS2010 Extension Package, however it can be simply converted and attuned to VS2012 format - Target platform should be change to .NET 4.5, thereafter some references to VS2012 assemblies (v.11.0) should be added to build and run startup project:
Microsoft.VisualStudio.Shell.11.0.dll
Microsoft.VisualStudio.Shell.Immutable.11.0.dll
Microsoft.VisualStudio.Shell.Interop.11.0
In case of problems, please visit Q & A section of the site.

How can I reuse one ReportViewer control for many reports with EF data sources?

I would like to stick with one single form and ReportViewer control, and at runtime assign various reports and data sources. The diverse and complex solutions to this revealed by a quick google check prompted me to rather ask here. How can I achieve this?
You'll need a form featuring a ReportViewer control, RDLC reports, and data sources; there are possibly several ways of implementing this, but you can have a "report manager" class exposing methods that each display a specific report (ex. ShowOrdersReport(), ShowTimeSheetReport(), etc.) - or you could define a base ReportBase class with a Show() method implementation that prompts for parameters when needed... whatever works, it will essentially boil down to this:
var reportForm = new ReportViewerForm(); // instantiate the form
// load the report definition into the viewer:
reportForm.reportViewer1.LocalReport.ReportEmbeddedResource = "Namespace.Report.rdlc";
// loading the data works great with a DataSet:
var data = _reportingDataSet.Tables[0];
// create the ReportDataSource with the report data:
var reportDataSource = new ReportDataSource("rdsReportDataSource", data);
reportForm.ShowReport(new[] { reportDataSource });
Here you'll want to inject the _reportingDataSet dependency; if you're using parameterized stored procedures, you'll want to prompt for the report parameters before you populate the DataSet.
The ShowReport() method adds the data sources to LocalReport.DataSources, and then calls RefreshReport() which displays the report you've specified.
public void ShowReport(IEnumerable<ReportDataSource> dataSources)
{
foreach (var dataSource in dataSources)
reportViewer1.LocalReport.DataSources.Add(dataSource);
reportViewer1.RefreshReport();
}
If you are using Crystal report then use this on click of load report button
CrystalReportViewer.ReportSource = ReportName
If you are using MS ReportViewer control then it needs two important steps to show the reports
Assign the report file path to the ReportViewer
Set the data source
So for example a ReportViewer control named reportViewer1 needs to display a SomeReport.rdlc file then following code is required (let's say on click of a button)
this.reportViewer1.LocalReport.ReportPath = #"Add absolute path of rdlc file"//e.g. #"C:\SomeReport.rdlc" ;
this.reportViewer1.RefreshReport();
This is just a simple example and for simplicity i have used static report if you need to display data from database just assign datasource property before call to RefreshReport
e.g.
this.reportViewer1.LocalReport.DataSources.Add(MyreportDataSource);
where MyreportDataSource is object of type ReportDataSource, you can easily convert any ADO.net DataTable to ReportDataSource object.
I hope this much info will do for you, in case you want to see more details you may refer a very good article at this location
http://www.c-sharpcorner.com/UploadFile/robo60/StandaloneRDLCReports11142007183516PM/StandaloneRDLCReports.aspx

Visual Studio: How to write Editor Extensions with WPF

Im trying to write a editor extension for Visual Studio. I have the downloaded VS SDK and created a new Visual Studio Package project. But the dummy control created for me is a Windows Forms control and not a WPF control. I'm trying to replace it with a WPF-control but not doing so well. Is this possible anyhow?
Another related question: Is it only possible to write text-editors? What I really want is a editor that looks more like a form with many different fields. But it doesn't seem to be what this is made for? There are a lot of interfaces on the EditorPane that imply a text-editor model only.
Ideally I want a editor much like the resx-editor where the file being edited has xml-content and the editor-ui is not a single textbox and where a generated cs-file is being outputted as a sub-file. Is this possible to do with editor extensions?
This is explained in detail here: WPF in Visual Studio 2010 – Part 4 : Direct Hosting of WPF content
So, if you use the standard Extensibility / Custom Editor sample that comes with the Visual Studio SDK, what you can do to test it is this:
1) Modify the provided EditorFactory.cs file like this:
// Create the Document (editor)
//EditorPane NewEditor = new EditorPane(editorPackage); // comment this line
WpfEditorPane NewEditor = new WpfEditorPane(); // add this line
2) create for example a WpfEditorPane.cs file like this:
[ComVisible(true)]
public class WpfEditorPane : WindowPane, IVsPersistDocData
{
private TextBox _text;
public WpfEditorPane()
: base(null)
{
_text = new TextBox(); // Note this is the standard WPF thingy, not the Winforms one
_text.Text = "hello world";
Content = _text; // use any FrameworkElement-based class here.
}
#region IVsPersistDocData Members
// NOTE: these need to be implemented properly! following is just a sample
public int Close()
{
return VSConstants.S_OK;
}
public int GetGuidEditorType(out Guid pClassID)
{
pClassID = Guid.Empty;
return VSConstants.S_OK;
}
public int IsDocDataDirty(out int pfDirty)
{
pfDirty = 0;
return VSConstants.S_OK;
}
public int IsDocDataReloadable(out int pfReloadable)
{
pfReloadable = 0;
return VSConstants.S_OK;
}
public int LoadDocData(string pszMkDocument)
{
return VSConstants.S_OK;
}
public int OnRegisterDocData(uint docCookie, IVsHierarchy pHierNew, uint itemidNew)
{
return VSConstants.S_OK;
}
public int ReloadDocData(uint grfFlags)
{
return VSConstants.S_OK;
}
public int RenameDocData(uint grfAttribs, IVsHierarchy pHierNew, uint itemidNew, string pszMkDocumentNew)
{
return VSConstants.S_OK;
}
public int SaveDocData(VSSAVEFLAGS dwSave, out string pbstrMkDocumentNew, out int pfSaveCanceled)
{
pbstrMkDocumentNew = null;
pfSaveCanceled = 0;
return VSConstants.S_OK;
}
public int SetUntitledDocPath(string pszDocDataPath)
{
return VSConstants.S_OK;
}
#endregion
}
Of course, you will have to implement all the editor logic (add interfaces, etc.) to mimic what's done in the Winforms sample, as what I provide here is really the minimal stuff for pure demonstration purposes.
NOTE: this whole "Content" thing only works starting with Visual Studio 2010 (so you need to make sure your project references Visual Studio 2010 assemblies, which should be the case if you start a project from scratch using Visual Studio 2010). Hosting WPF editors within Visual Studio 2008 is possible using System.Windows.Forms.Integration.ElementHost.
I'm not sure if the above is possible but a quick search did turn up this:
http://karlshifflett.wordpress.com/2010/03/21/visual-studio-2010-xaml-editor-intellisense-presenter-extension/
and this:
http://blogs.msdn.com/b/visualstudio/archive/2009/12/09/building-and-publishing-an-extension-for-visual-studio-2010.aspx
Failing that, could you not host a WPF control inside the winforms control using ElementHost? I know its a lame workaround but might allow you to develop in your favourite toolkit while you find a more permanent solution.
Best regards,
There is a sample VS Extension Package application source code on MSDN: Designer View Over XML Editor.
Description from site:
This Sample demonstrates how to create an extension with a WPF-based Visual Designer for editing XML files with a specific schema (XSD) in coordination with the Visual Studio XML Editor.
Admittedly solution is dedicated for VS2010 Extension Package, however it can be simply converted and attuned to VS2012 format - Target platform should be change to .NET 4.5, thereafter some references to VS2012 assemblies (v.11.0) should be added to build and run startup project:
Microsoft.VisualStudio.Shell.11.0.dll
Microsoft.VisualStudio.Shell.Immutable.11.0.dll
Microsoft.VisualStudio.Shell.Interop.11.0
In case of problems, please visit Q & A section of the site.

Resources