App_
Posts
-
Restore folder to previous version? -
SetTimerA Universal TCP Socket Class for Non-blocking Server/Clients Single Threaded The function PumpMessages() processes all Windows messages which arrive in the application so the GUI stays responsive although the code runs an endless loop:
// Set Timeout 50 ms
mi_Socket.Listen(0, ms32_Port, 50);while (...) // This loop runs in the GUI thread
{
PumpMessages(); // process Windows messagesDWORD u32\_Event; SOCKET h\_Socket; // ProcessEvents() returns after 50 ms or after an event was received DWORD u32\_Error = mi\_Socket.ProcessEvents(&u32\_Event, &h\_Socket, ....); if (u32\_Error == ERROR\_TIMEOUT) continue; if (u32\_Event & FD\_ACCEPT) { /\* A new client has connected \*/ } if (u32\_Event & FD\_READ) { /\* Data has been received \*/ } if (u32\_Event & FD\_CLOSE) { /\* A socket has closed \*/ } if (u32\_Error) { /\* handle error \*/ }
};
-
How to copy One XMLdocument to another?XmlDocument::ImportNode does the job, It states and i quote: "The
ImportNode
method is the mechanism by which a node or entire node subtree is copied from one XmlDocument to another. The node returned from the call is a copy of the node from the source document, including attribute values, the node name, node type, and all namespace-related attributes such as the prefix, local name, and namespace Uniform Resource Identifier (URI). The source document is not changed. " more from MSDN.. Code from MSDN:#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{//Create the XmlDocument.
XmlDocument^ doc = gcnew XmlDocument;
doc->LoadXml( "<bookstore><book genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book></bookstore>" );//Create another XmlDocument which holds a list of books.
XmlDocument^ doc2 = gcnew XmlDocument;
doc2->Load( "books.xml" );//Import the last book node from doc2 into the original document.
XmlNode^ newBook = doc->ImportNode( doc2->DocumentElement->LastChild, true );
doc->DocumentElement->AppendChild( newBook );
Console::WriteLine( "Display the modified XML..." );
doc->Save( Console::Out );
} -
How to extract Visio XML files properties -
How to refresh folderuh huh, I ripped that code from there :cool:
-
How to refresh folderHere you go.
// Call for each explorer window
HWND hExplorer = FindWindowEx(GetDesktopWindow(), NULL, L"ExploreWClass", NULL); while(hExplorer != NULL) { EnumChildWindows(hExplorer, RefreshFolderSelectionCB, (LPARAM)&packet); hExplorer = FindWindowEx(GetDesktopWindow(), hExplorer, L"ExploreWClass", NULL); }
...
...
...BOOL CALLBACK RefreshFolderSelectionCB(HWND hWnd, LPARAM lParam)
{
WCHAR sBuffer[MAX_PATH] = {0};::GetClassName(hWnd, sBuffer, MAX\_PATH); if (wcscmp(L"SysTreeView32", sBuffer) == 0) { RefreshFolderSelectionPacket\* pPacket = (RefreshFolderSelectionPacket\*)lParam; // Refreshes the tree nodes that match the contained full paths, and all their open descendants // Paths are updated by calling UpdateItem (below) // Cache is used across explorer instances to ensure no path is updated twice. RefreshSelection(pPacket); } return TRUE;
}
...
...
static void UpdateItem(IShellFolder* pDesktop, const std::wstring& rsFullPath)
{
PIDLIST_RELATIVE pIDL;if (SUCCEEDED(pDesktop->ParseDisplayName(NULL, NULL, (LPWSTR)rsFullPath.c\_str(), NULL, &pIDL, NULL))) { SHChangeNotify(SHCNE\_UPDATEITEM, SHCNF\_IDLIST|SHCNF\_NOTIFYRECURSIVE|SHCNF\_FLUSH, pIDL, NULL); ILFree(pIDL); }
}
-
Splitter with fixed size -
how to Add the help file in SDI ApplicationMSDN says: The following example calls the HH_DISPLAY_TOPIC command to open the help file named Help.chm and display its default topic in the help window named
Mainwin
. Generally, the help window specified in this command is a standard HTML Help Viewer. MSDN ExampleHWND hwnd =
HtmlHelp(
GetDesktopWindow(),
"c:\\Help.chm::/Intro.htm>Mainwin",
HH_DISPLAY_TOPIC,
NULL) ; -
SetCurrentDirectory#include <windows.h>
#include <stdio.h>
#define BUFFER_SIZE 200int main()
{
TCHAR infoBuf[BUFFER_SIZE];// Change accordingly to other path of your machine
TCHAR lpPathName[200] = "c:\\";// get the current working directory
if(!GetCurrentDirectory(BUFFER_SIZE, infoBuf)) printf("GetCurrentDirectory() failed!\n");printf("Your current directory is: %s\n", infoBuf); printf("Changing directory...\n");
// set to current working directory
if(!SetCurrentDirectory(lpPathName)) printf("SetCurrentDirectory() failed!\n");// do some verification...
if(!GetCurrentDirectory(BUFFER_SIZE, infoBuf)) printf("GetCurrentDirectory() failed!\n");printf("Your current directory is: %s\n", infoBuf);
// get and display the Windows directory.
if(!GetWindowsDirectory(infoBuf, BUFFER_SIZE)) printf("GetWindowsDirectory() failed!\n");printf("Your Windows directory is: %s\n", infoBuf);
// get and display the system directory.
if(!GetSystemDirectory(infoBuf, BUFFER_SIZE)) printf("GetSystemDirectory() failed!\n");printf("Your system directory is: %s\n", infoBuf);
return 0;
} -
working with byte arraysis done like this:
#include <iostream>
using namespace std;void charray(char test[]) {
strncpy(test,"test",sizeof(test));
}int main() {
char test[256]={' '};
charray(test);
printf("Text in %s!\n", test);
return 0;
} -
working with byte arrays:thumbsup:
-
Function pointer point to a object member function in C++?Class Math <--- error
{
public float add(float a, float b)
{
return a+b;
}
}<--- errorFirstly , lowercase.
Class Math
should beclass Math
secondly , semicolon -
TCP Communicationsource code here
-
Suggest a fast way to do? -
setting form element values using ie TCppWebBrowser controlWhat you are likely seeing is a call to
MessageBox()
before the exception is thrown. To turn that off, you can go into the Project Options and addNO_PROMPT_ON_HRCHECK_FAILURE
to the Conditionals list. The exception will then be thrown without any prompting. If you are still using theTComInterface
wrapper, the '->' operator validates whether the interface pointer is available or not. If it is not, an ASSERT is thrown. To disable the prompt on that error, you can defineNO_PROMPT_ON_ASSERTE_FAILURE
in the Project Options. If you implement a try..catch block, it will catch errors normally without messagebox prompt interruptions. (sample try catch)try {
buf = new char[512];
if( buf == 0 ) throw "Memory allocation failure!";
}
catch( char * str ) {
cout << "Exception raised: " << str << '\n';
} -
setting form element values using ie TCppWebBrowser controlChange this line:
HRESULT __fastcall GetHTMLItem(ParentIntf *CollectionOrElement, const WideString &name, ItemIntf** ppIntf)
To this:
HRESULT __fastcall GetHTMLItem(TComInterface<ParentIntf> &CollectionOrElement, const WideString &name, ItemIntf** ppIntf)
-
setting form element values using ie TCppWebBrowser controlI hope this Boland C++ Builder 6 code might work..
#include utilcls.h
#include Mshtml.htemplate<class ParentIntf, class ItemIntf>
HRESULT __fastcall GetHTMLItem(ParentIntf *CollectionOrElement, const
WideString &name, ItemIntf** ppIntf)
{
TVariant vName = name;
TVariant vIndex = 0;
TComInterface disp;HRESULT hRes = CollectionOrElement->item(vName, vIndex, &disp); if( SUCCEEDED(hRes) ) hRes = disp->QueryInterface(\_\_uuidof(ItemIntf),(LPVOID\*)ppIntf); return hRes;
}
void __fastcall TForm1::CppWebBrowser1DocumentComplete (TObject*
Sender, LPDISPATCH pDisp, TVariant *URL)
{
if( CppWebBrowser->Document )
{
TComInterface HTMLDoc;
if(SUCCEEDED(CppWebBrowser->Document->QueryInterface(
IID_IHTMLDocument2,(LPVOID*)&HTMLDoc) ) )
{
TComInterface forms;
if( SUCCEEDED(HTMLDoc->get_forms(&forms)) )
{
TComInterface form;
if( SUCCEEDED(GetHTMLItem(forms, "loginform", &form)) )
{
TComInterface userid;
TComInterface password;GetHTMLItem(form, "userid", &userid); GetHTMLItem(form, "password", &password); if( userid ) userid->put\_value(WideString("username")); if( password ) password->put\_value(WideString("password")); } } } }
}
I hope this Boland C++ Builder 6 code might work too..
bool TForm1::Login(char* inputname, const AnsiString& text)
{
bool done = false;IHTMLDocument2* HTMLDoc = NULL;
if(SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&HTMLDoc)))
{
IHTMLElementCollection* pAll = NULL;
if(SUCCEEDED(HTMLDoc->get_all(&pAll)))
{
//Variant name = inputname;
Variant index = 0;IDispatch* pDisp = NULL;
if(SUCCEEDED(pAll->item(name, index, &pDisp)))
{
if ( pDisp )
{
// IHTMLInputFileElement* pInput = NULL; // mshtml.h
IHTMLInputElement* pInput = NULL; // mshtml.h
// IHTMLFormElement* pForm = NULL; // mshtml.hpDisp->QueryInterface(IID\_IHTMLInputElement, (LPVOID\*)&pInput); pDisp->Release(); if(pInput) { pInput->put\_value(WideString(text)); done = true; /\* WideString mybuffer; pInput->get\_value ( &mybuffer ); ShowMessage ( mybuffer ); \*/ pInput->Release(); } }
}
pAll->Release();
}HTMLDoc->Release();
}
return done;
} -
Suggest a third party library for MFC applicationsYes QtGui on Linux. I's so easy to learn , like so:
#include int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel label("Hello, world!");
label.show();
return app.exec();
}more here Why even use windows? Wall street trading systems all use Red Hat/SUSE. Windows is mostly relegated to the back office, Windows typically has larger latency times than that of Linux.
-
MFC - how to get an edit box text from another dialog?? (Constructor) -
How to get list of COM Ports in Win32Have a look there