IntToStr
#pragma once#include <stdio.h>#include <tchar.h>#include <malloc.h>static TCHAR __intBuff[64];#define IntToStr1(i) (const TCHAR*)__IntToStr1(i,__intBuff,sizeof(__intBuff)/sizeof(__intBuff[0]))#define IntToStr2(i) (const TCHAR*)__IntToStr2(i,__intBuff,sizeof(__intBuff)/sizeof(__intBuff[0]))const TCHAR* __IntToStr1(int& i,TCHAR* buff,const unsigned int blen){ _itot_s(i,buff,blen,10); i = 0;// <--- parameter 'i' may be lost or nulled by malfunction return buff;}const TCHAR* __IntToStr2(int& i,TCHAR* buff,const unsigned int blen){ i = 0;// <--- parameter 'i' may be lost or nulled by malfunction _itot_s(i,buff,blen,10); return buff;}int _tmain(int argc, _TCHAR* argv[]){ int counter = 0; int dest_pos = 20; _tprintf(__T("loop IntToStr1\r\n")); for (int z = 0; z < 1000; z++) { /***2***/ int y = z; /***3***/ if(counter++ == dest_pos) { /***1***/ _tprintf(__T("y = %s (OP says here comes z unchanged)\r\n"),IntToStr1(y)); _tprintf(__T("z = %s (OP says here comes 0)\r\n"),IntToStr1(z)); //if reach dest position - than would set new value for dest_pos dest_pos = 56; } } _tprintf(__T("loop IntToStr2\r\n")); counter = 0; dest_pos = 20; for (int z = 0; z < 1000; z++) { /***2***/ int y = z; /***3***/ if(counter++ == dest_pos) { /***1***/ _tprintf(__T("y = %s (OP says here comes z unchanged)\r\n"),IntToStr2(y)); _tprintf(__T("z = %s (OP says here comes 0)\r\n"),IntToStr2(z)); //if reach dest position - than would set new value for dest_pos dest_pos = 56; } } _tprintf(__T("<key> ")); _gettch(); return 0;}
loop IntToStr1y = 20 (OP says here comes z unchanged)z = 20 (OP says here comes 0)y = 36 (OP says here comes z unchanged)z = 36 (OP says here comes 0)loop IntToStr2y = 0 (OP says here comes z unchanged)z = 0 (OP says here comes 0)y = 0 (OP says here comes z unchanged)z = 0 (OP says here comes 0)
#define WM_QUIT_ON_THREAD_OK ( WM_APP + 3 )////////////////////////////// main window proccase WM_CLOSE: if(IsWindow(hDlg)) { PostMessage(hDlg,WM_QUIT_ON_THREAD_OK); } else { DestroyWindow(hWnd); }return 0;////////////////////////////// dialog window proccase WM_QUIT_ON_THREAD_OK: if(IsThreadRunning()) { QuitOnThreadOk = 1; ReflectQuit(hwnd); } else { DestroyWindow(hwnd); PostMessage(hWndFrame,WM_CLOSE,0,0); }return 0;case WM_THREAD_OK: // thread sent this if( IsThreadRunning() ) // just wait until it fully exits { PostMessage(hwnd,WM_THREAD_OK,0,0); // thread is already running post the message again // alternative: use a timer to check the threads state } else { ThreadFinished(hwnd); if( QuitOnThreadOk ) { DestroyWindow(hwnd); PostMessage(hWndFrame,WM_CLOSE,0,0); } }return TRUE;////////////////////////////// helper functionvoid ReflectQuit(HWND hDlg){ HWND hbtn = GetDlgItem( hDlg, IDC_BUTTON1 ); // show the user whats going on SetWindowText(hbtn,__TEXT("application will close on finish thread"));}
case WM_THREAD_OK: // thread sent this if( IsThreadRunning() ) // just wait until it fully exits { PostMessage(hwnd,WM_THREAD_OK,0,0); // thread is already running post the message again // alternative: use a timer to check the threads state } else { ThreadFinished(hwnd); } return TRUE; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_BUTTON1: StartThread(hwnd); return 0; } break;
int IsThreadRunning(){ if(threadHandle) { if(WAIT_TIMEOUT==WaitForSingleObject( threadHandle, 1 )) return 1; CloseHandle( threadHandle ); threadHandle = NULL; } return 0;}void ThreadFinished(HWND hDlg){ HWND hbtn = GetDlgItem( hDlg, IDC_BUTTON1 ); // show the user whats going on EnableWindow( hbtn, 1 ); SetWindowText(hbtn,__TEXT("start thread"));}void ThreadStarted(HWND hDlg){ HWND hbtn = GetDlgItem( hDlg, IDC_BUTTON1 ); // show the user whats going on EnableWindow( hbtn, 0 ); SetWindowText(hbtn,__TEXT("thread running"));}void StartThread(HWND hDlg){ if(!IsThreadRunning()) { DWORD threadID; td.hwnd = hDlg; td.PrimaryKey = primaryKey; threadHandle = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)MyThread, (void*)&td, 0, &threadID ); if( !threadHandle ) { MessageBox( hDlg, L"Error", L"Error", MB_ICONERROR ); DestroyWindow(hDlg); } else { ThreadStarted(hDlg); } }}
float** alloc2D(const unsigned int x,const unsigned int y){ unsigned char* buff; unsigned int need,ix; float** ax; float* ay; ASSERT(0<x); ASSERT(0<y); need = (x * sizeof(float*)) + ((x*y) * sizeof(float)); buff = (unsigned char*)malloc(need); ax = (float**)buff; ay = (float*)(ax+x); for(ix=0;ix<x;ix++) { ax[ix] = ay; ay += y; } return ax;}
head->next
if(head) head->next=newContact;
WaitForSingleObject(mainHandle,INFINITE)
#pragma once#define WIN32_LEAN_AND_MEAN#include <windows.h>// multibyte or unicode#include <tchar.h>// needed libraries#pragma comment (lib,"user32.lib")#pragma comment (lib,"gdi32.lib")// 32 vs. 64 bit#ifdef _WIN64 #define SET_DWL_USER(H,P) SetWindowLongPtr(H,DWLP_USER,(LONG_PTR)P) #define GET_DWL_USER(H) GetWindowLongPtr(H,DWLP_USER)#else #define SET_DWL_USER(H,P) SetWindowLong(H,DWL_USER,(long)P) #define GET_DWL_USER(H) GetWindowLong(H,DWL_USER)#endif/////////// simple dialog classclass CMyDlg{public: CMyDlg(HINSTANCE h); ~CMyDlg(); int DoModal(const int idd);private: static INT_PTR FAR PASCAL __dlg(HWND h,unsigned int m,WPARAM w,LPARAM l); HINSTANCE _hinst; HBITMAP _hbmp;};// dialog message handlerINT_PTR FAR PASCAL CMyDlg::__dlg(HWND h,unsigned int m,WPARAM w,LPARAM l){ CMyDlg* This = (CMyDlg*)GET_DWL_USER(h); switch(m) { case WM_INITDIALOG: { // attach my this pointer to the dialog This = (CMyDlg*)l; SET_DWL_USER(h,This); // delete if already loaded if(This->_hbmp) DeleteObject(This->_hbmp); // load the image from file This->_hbmp = (HBITMAP)LoadImage(0,__T("myimage.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE); if(This->_hbmp) { HWND hctrl; hctrl = GetDlgItem(h,101); if(IsWindow(hctrl)) { // attach image to the control SendMessage(hctrl,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)This->_hbmp); } hctrl = GetDlgItem(h,102); if(IsWindow(hctrl)) { // attach image to another control SendMessage(hctrl,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)This->_hbmp); } } } break; case WM_COMMAND: switch(LOWORD(w)) { // end the dialog and quit case IDOK: EndDialog(h,LOWORD(w)); break; case IDCANCEL: EndDialog(h,LOWORD(w)); break; } break; } return 0;}CMyDlg::CMyDlg(HINSTANCE h){ _hinst = h; _hbmp = 0;}CMyDlg::~CMyDlg(){ // finally delete object if(_hbmp) DeleteObject(_hbmp);}int CMyDlg::DoModal(const int idd){ HRSRC hres = FindResource(_hinst,MAKEINTRESOURCE(idd),RT_DIALOG); HGLOBAL hdlg = hres ? LoadResource(_hinst,hres):0; // find resource handle and show dialog here return hdlg?(int)DialogBoxIndirectParam(_hinst,(LPCDLGTEMPLATE)LockResource(hdlg),(HWND)0,__dlg,(LONG_PTR)this):0;}/////////// program starts hereint FAR PASCAL _tWinMain(HINSTANCE h,HINSTANCE p,LPTSTR c,int sw){ CMyDlg dlg(h); return dlg.DoModal(100);}
Minor
Determinant
double** tempMtx=new double*[rows-1];for (int i=0;i<rows-1;i++) tempMtx[i]=new double[cols-1];
static const GUID CLSID_ThisIsMyInterface = { 0x85d8c4a1, 0xb644, 0x4cf2, { 0xb7, 0x72, 0xb2, 0x7e, 0xb2, 0x27, 0x1, 0x3d } };HRESULT iDummy::QueryInterface(REFIID riid,void** ppv){ if(CLSID_ThisIsMyInterface==riid) return *(iDummy**)ppv=this,AddRef(),S_OK; // the other interfaces}// hook the old handlerstatic HRESULT iDummy::HookTheHandler(IDispatch* pOld,IDispatch** ppNew){ iDummy* isme; if(S_OK==pOld->QueryInterface(CLSID_ThisIsMyInterface,(void**)&isme)) { isme->Release(); return E_FAIL; } *ppNew = new iDummy(pOld); return (*ppNew)?S_OK:E_OUTOFMEMORY;}iDummy::iDummy(IDispatch* pOld){ oldhandler = 0; if(S_OK!=pOld->QueryInterface(IID_IDispatchEx,(void**)&oldhandler)) { oldhandler = 0; }}iDummy::~iDummy(){ if(oldhandler) oldhandler->Release();}HRESULT iDummy::InvokeEx(DISPID id,LCID lcid,WORD wFlags,DISPPARAMS *pdp,VARIANT *pvarRes,EXCEPINFO *pei,IServiceProvider *pspCaller){ // forward the old handler HRESULT hr = oldhandler ? oldhandler->InvokeEx(id,lcid,wFlags,pdp,pvarRes,pei,pspCaller):E_FAIL; Beep(3000,100); // i am alive return hr;}
if(S_OK!=handler->QueryInterface(IID_IDispatchEx,(void**)&oldhandler)) oldhandler=0;
if(oldhandler) oldhandler->Release();
LinkClick
submit
IActiveScriptParse
ShellExecute
color
class CColor{public: CColor() { _c = _d = 0; } CColor(CColor& c) { _c = c._c; _d = c._d; } operator COLORREF& (){ return _c; } template <class C> CColor& operator = (C c) { _d = c; return *this; } template <class C> CColor(C c) { _c=0; _d=c; } template <class C> CColor& operator , (C c) { _d = _d<<8|(c&0xFF); return *this; } operator bool () { return _c==_d; }private: COLORREF _c; COLORREF _d;};void GetPixel(int x,int y,COLORREF& c){ c = RGB(0,128,255); }int FAR PASCAL _tWinMain(HINSTANCE h,HINSTANCE p,LPTSTR c,int sw){ CColor col; GetPixel(0,0,col); if(col = 255,255,255) { Beep(3000,100); } else { Beep(1000,100); } return 0;}
ShellExecuteEx
template <class TSET>int GetCodes( TSET& codes,const TSET set ){ return 0;}template <class TSET>int GetCodes0( TSET& codes,const TSET set ){ _tprintf(__T(" set\r\n")); codes = set; return 0;}template <class TARR,class TSET>int GetCodes0( TARR& codes,const TSET set ){ return 0;}template <class TARR,class TSET>int GetCodes( TARR& codes, const TSET set ){ size_t i; int dim = 0; _tprintf(__T(" elem: %i\r\n"),(int)(sizeof(codes)/sizeof(codes[0]))); for(i=0;i<(sizeof(codes)/sizeof(codes[0]));i++) { dim = GetCodes(codes[i],set); if(0==dim) GetCodes0(codes[i],set); } return 1+dim;}
m_output->write((char*)data, pcm_datalength+phase);
m_output->write((char*)data, sizeof(short)*(pcm_datalength+phase));
void fn(Vector2D& x){}
void fn(){ Vector2D x; fn(x); }
constructorx: 0.000000, y: 0.000000destructor
int sum = pcm_databuffer[i] +(int)((double)pcm_databuffer[j]*damping);sum = min(sum,35535);sum = max(sum,-35535);
Vector2D()
result = 2<argc?atoi(argv[2]):0;
WM_COMMAND
tracker.Draw
DrawFocusRect
xor
SetBrushOrg
#ifdef _DEBUG#define LOG __loggi#else#define LOG #endif
printf
(const T&)key
(T&)key
const T&
char *buffer = (char*)malloc(strlen(BODY) + strlen(HEADERS) + 256);//...closesocket(s);
v1.bstrVal = SysAllocString(L"111");
SetThink ( &CBaseEntity::SUB_Remove );
// old compilerclass A{public: void Do(){} void worker(void (A::*fn)()) { (this->*fn)(); }};void main(){ A a; a.worker(A::Do);}
// new compilervoid main(){ A a; a.worker(&A::Do);}
TranslateAccelerator
CreateAcceleratorTable
class A{public: int i;};class B : public A{public: int i; void set(int i) { A::i = i; B::i = i; }};
LRESULT WndProc(HWND h,int m,WPARAM w,LPARAM l){ switch(m) { case WM_ACTIVATE: if(w) SetFocus(GetWindow(h,GW_HWNDCHILD)); return 0; } return DefWindowProc(h,m,w,l);}
HDC hdc = GetDC(hDlg);HBRUSH hbr = (HBRUSH)SendMessage(hDlg,WM_CTLCOLORDLG,(WPARAM)hdc,(LPARAM)hDlg);LOGBRUSH logb;ReleaseDC(hDlg,hdc);if(GetObject(hbr,sizeof(logb),&logb)){ logb.lbColor; // <- here is the color}
IExtractImage
DWORD *a;//unsigned char *a;//pointer to the key value
int main(){ { x o; o.show(); } // <-- destructor called getch(); return 0;}
el
unsigned int findtwice(int* array,const unsigned int count){ enum{ NOTFOUND=-1 }; typedef struct { static int cmpi(void* a,void* b){ return *(int*)a-*(int*)b; } }_; unsigned int i; qsort(array,count,sizeof(int),_::cmpi); for(i=1;(i<count)&&(array[i-1]!=array[i]);i++); return i<count?i-1:NOTFOUND;}
SendMessage(EM_SETSEL,0,0);
CTreeCtrl
lpd += bpld * (cyDest-cySource/2)/2;
sConnect
sConnect = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
CoTaskMemAlloc
CoTaskMemFree
htir = (HTREEITEM)::SendMessage(htree,TVM_GETNEXTITEM,TVGN_ROOT,0);htis = (HTREEITEM)::SendMessage(htree,TVM_GETNEXTITEM,TVGN_CARET,0);htic = (HTREEITEM)::SendMessage(htree,TVM_GETNEXTITEM,TVGN_CHILD,(LPARAM)htir);for(count=pos=0;htic;htic=(HTREEITEM)::SendMessage(htree,TVM_GETNEXTITEM,TVGN_NEXTVISIBLE,(LPARAM)htic),count++){ if(htis==htic) pos=count; }
PostMessage
::PostMessage
#include <commctrl.h>
6==ERROR_INVALID_HANDLE
#include <tchar.h>#include <conio.h></conio.h></tchar.h>
66716671
SetFocus(hwnd)
SendMessage(hwnd,WM_SETFOCUS,...)
CWnd::OnSetFocus
WM_SETFOCUS
SetFocus(hChild)
CYourView::OnSettingFocus()
lpc[0] = __alphatable_value(lpbits[0],0/*color of the back plane*/,lpbits[3]);lpc[1] = __alphatable_value(lpbits[1],0/*color of the back plane*/,lpbits[3]);lpc[2] = __alphatable_value(lpbits[2],0/*color of the back plane*/,lpbits[3]);
BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255/*blend alpha*/, AC_SRC_ALPHA };
if(pBuffer) pBuffer->Release(); pBuffer=0;
typedef int I5x6[5][6];void func(I5x6& z){ unsigned int i,j; for(i=0;i<5;i++) { for(j=0;j<6;j++) { TRACE(__TEXT("%i\r\n"),z[i][j]); } }}void main(){ I5x6 ip; unsigned int i,j; for(i=0;i<5;i++) { for(j=0;j<6;j++) { ip[i][j] = i+j; } } func(ip);}
Release()
AddRef()
QueryInterface()
#pragma pack(push)#pragma pack(2)typedef struct{ BYTE bWidth; // Width, in pixels, of the image BYTE bHeight; // Height, in pixels, of the image BYTE bColorCount; // Number of colors in image (0 if >=8bpp) BYTE bReserved; // Reserved ( must be 0) WORD wPlanes; // Color Planes WORD wBitCount; // Bits per pixel DWORD dwBytesInRes; // How many bytes in this resource? DWORD dwImageOffset; // Where in the file is this image? } ICONDIRENTRY, *LPICONDIRENTRY;typedef struct{ WORD idReserved; // Reserved (must be 0) WORD idType; // Resource Type (1 for icons) WORD idCount; // How many images? // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em)} ICONDIR;typedef struct{ BITMAPINFOHEADER icHeader; // DIB header // RGBQUAD icColors[1]; // Color table // BYTE icXOR[1]; // DIB bits for XOR mask // BYTE icAND[1]; // DIB bits for AND mask} ICONIMAGE;#pragma pack(pop)
GetClassName