MainWindow::MainWindow(Client *chat,
			LPCTSTR windowName, HINSTANCE hInst, int cmdShow,
			LRESULT (WINAPI *pWndProc)(HWND,UINT,WPARAM,LPARAM),
			LPCTSTR menuName, int x, int y, int width, int height,
			UINT classStyle, DWORD windowStyle, HWND hParent)

			: _chat(chat),
			 _windowName(windowName), _hInst(hInst), _cmdShow(cmdShow), 
			 _menuName(menuName), _x(x), _y(y), _width(width), _height(height),
			 _classStyle(classStyle), _windowStyle(windowStyle), _hParent(hParent)
{
	_szClassName = "KWndClass";
	
	Init(pWndProc);
	CreateWnd();
	
	SendMessage(hMainWnd, WM_COMMAND, IDM_AUTHDLG, 0); //Why is it not running??
	
	if (!hMainWnd) {
		char text[100] = "Cannot create window: ";
		strcat(text, windowName);
		MessageBox(NULL, text, "Error", MB_OK);
		return;
	}

	ShowWindow(hMainWnd, cmdShow); 
}
Пример #2
0
/*
*--------------------------------------------------------------------------------
*  函数名	: CFloatDibWnd
*  功能		: 构造函数
*  参数		: HWND hParentWnd			- 父窗口句柄
*			  const CRect& rect			- 被选取区域,相对于父窗口坐标
*  算法		: 将父窗口指定区域内的图像复制到浮动窗口中
*  说明		: 为选取区域浮动窗口而设
*--------------------------------------------------------------------------------
*/
CFloatDibWnd::CFloatDibWnd(HWND hParentWnd, const CRect& rect,INT curDrawSize/*=55*/)
{
	m_curDrawSize = curDrawSize;
	m_hParentWnd = hParentWnd; 
	m_ChangeType = CT_MOVE;
	m_bCartoonWnd = FALSE;
	m_pHistoryDib = NULL;
	m_dblPreRotateAngle = 0.0;
	// 调整坐标,以确定左上角和右下角坐标正确	
	m_rcWndRect.left = rect.left <= rect.right ? rect.left : rect.right;
	m_rcWndRect.right = rect.left <= rect.right ? rect.right : rect.left;
	m_rcWndRect.top = rect.top <= rect.bottom ? rect.top : rect.bottom;
	m_rcWndRect.bottom = rect.top <= rect.bottom ? rect.bottom : rect.top;	

	// 从指定窗口上抓取指定区域的图像到窗口图像中
	m_pDib = new CDib();	
	m_pDib->Create(m_hParentWnd, m_rcWndRect);

	// 保存原始图像
	m_pSrcDib = m_pDib->Clone();
	
    CheckShowBtn();
	// 创建窗口
	CreateWnd();
}
Пример #3
0
static int Main(const Options *options)
{
	if(!CreateWnd(options->showWindow))
		return 1;

	NotifyCtl(NIM_ADD,L"",0);

	UpdateToolTip(FALSE);

	if(options->pLayoutToSet)
	{
		HKL hkl=FindLayoutHandleForDisplayName(options->pLayoutToSet);
		SetLayoutByHandle(hkl,FALSE);
	}

	for(;;)
	{
		int r;
		MSG msg;

		r=GetMessage(&msg,NULL,0,0);
		if(r==0||r==-1)
			break;

		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	NotifyCtl(NIM_DELETE,NULL,0);

	return 0;
}
Пример #4
0
bool iocp_server::Init(HINSTANCE hInstance)
{
	m_hInstance = hInstance;
	CreateWnd();
	open();
	return true;
}
Пример #5
0
/*
*--------------------------------------------------------------------------------
*  函数名	: CFloatDibWnd
*  功能		: 构造函数
*  参数		: HWND hParentWnd	- 父窗口句柄
*			  CDib* pDib		- DIB图像指针
*  算法		: 新建浮动窗口,并居中显示,窗口内容为指定的DIB图像
*  说明     : 为粘贴图像功能而设
*--------------------------------------------------------------------------------
*/
CFloatDibWnd::CFloatDibWnd(HWND hParentWnd, CDib* pDib,INT curDrawSize/*=55*/)
{
	ASSERT(pDib);
	m_curDrawSize = curDrawSize;
	m_hParentWnd = hParentWnd; 
	m_ChangeType = CT_MOVE;
	m_pHistoryDib = NULL;
	m_bCartoonWnd = FALSE;
	m_dblPreRotateAngle = 0.0;
	m_pDib = pDib->Clone();
	ASSERT(m_pDib);

	// 保存原始图像
	m_pSrcDib = m_pDib->Clone();
	ASSERT(m_pSrcDib);


	// 将窗口位置设为居中
	long nWidth = m_pDib->GetWidth();
	long nHeight = m_pDib->GetHeight();

	CRect rcWnd;
	::GetWindowRect(m_hParentWnd, &rcWnd);
	
	m_rcWndRect.left = rcWnd.Width() / 2 - nWidth / 2;
	m_rcWndRect.right = rcWnd.Width() / 2 + nWidth / 2;
	m_rcWndRect.top = rcWnd.Height() / 2 - nHeight / 2;
	m_rcWndRect.bottom = rcWnd.Height() / 2 + nHeight / 2;

    CheckShowBtn();

	//创建窗口
	CreateWnd();
}
Пример #6
0
BOOL FAdWindow::LoadAd(FAdItem& pItem)
{
	//If this is the currently displayed ad, see if 
	//it has been hidden long enough

	if (m_CurrentItem.m_dwAdID == pItem.m_dwAdID && m_bAdInProgress)
		return FALSE; 

	if (m_CurrentItem.m_dwAdID == pItem.m_dwAdID && !m_bAdInProgress)
	{
		DWORD dwTimeout = MIN_AD_REDISPLAY_TIMEOUT; 
		if (IsAdShowing() || GetTickCount() - m_CurrentItem.m_LastDisplay < dwTimeout)
			return FALSE; 
	}


	m_CurrentItem = pItem; 
	m_bAdInProgress = TRUE; 
	m_bAdLoaded = FALSE; 
	
	if (m_hWnd == NULL && !CreateWnd())
		return FALSE; 
	
	return SUCCEEDED(Navigate(m_CurrentItem.m_URL));
}
Пример #7
0
HWND DialogWindow::CreateDialogWindow(HWND hWnd,wchar_t* Class){
	HWND res;
	RECT rc;
	HINSTANCE hInst=(HINSTANCE)GetWindowLongPtr(hWnd,GWLP_HINSTANCE);
	m_hParent=hWnd;
	GetWindowRect(m_hParent,&rc);

	RegisterWC(hInst,Class);
	res=CreateWnd(Class,WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_VISIBLE|WS_MINIMIZEBOX,rc.left,rc.top,0,0,NULL,NULL,hInst);
	m_hDlg=CreateDialogParam(hInst,Class,res,(DLGPROC)DlgCallProc,(LPARAM)this);
	SendMessage(res,WM_SIZE,NULL,NULL);
	ShowWindow(m_hParent,SW_HIDE);
	return res;
}
Пример #8
0
dlgWndPinpadInfo::dlgWndPinpadInfo( unsigned long ulHandle, DlgPinUsage PinPusage, 
		DlgPinOperation operation, const std::wstring & csReader, 
		const std::wstring & PinName, const std::wstring & Message, HWND Parent)
:Win32Dialog(L"WndPinpadInfo")

{
	m_szHeader=NULL;
	m_szMessage=NULL;

	m_ModalHold = false;
	m_szMessage = _wcsdup( Message.c_str() );

	m_ulHandle = ulHandle;

	std::wstring tmpTitle = L"";

	tmpTitle += GETSTRING_DLG(PinpadInfo);

	if (PinPusage == DLG_PIN_AUTH)
		m_szHeader = _wcsdup( L"Pin da Autenticação" );
	else
		m_szHeader = _wcsdup( PinName.c_str() );

	if(!csReader.empty())
	{
		tmpTitle += L" - ";
		tmpTitle += csReader;
	}
	

	if( CreateWnd( tmpTitle.c_str() , 420, 280, 0, Parent ) )
	{
		if( PinPusage == DLG_PIN_SIGN )
			ImagePIN = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_BITMAP2) );
		else
			ImagePIN = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_BITMAP1) );
		CreateBitapMask( ImagePIN, ImagePIN_Mask );

		TextFont = CreateFont( 16, 0, 0, 0, FW_DONTCARE, 0, 0, 0,
				DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
				DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Arial" );


		SendMessage( Parent, WM_SETFONT, (WPARAM)TextFont, 0 );

	}

}
Пример #9
0
CMapView::CMapView(HWND hWndparent,HINSTANCE hinst,Engine* pengine,Map* pmap,VSP* pvsp)
{
    hInst=hinst;
    pEngine=pengine;
    pMap=pmap;
    pVsp=pvsp;
    
    nLefttile=0;    nRighttile=0;
    nCurzone=0;        nCurlayer=0;
    cursormode=mode_normal;
    xwin=ywin=0;
    
    hWnd=CreateWnd(hWndparent);                        // create the window
    bLayertoggle.resize(10);                        // TEMP HACK
    
    pGraph=new CGraphView(hWnd,RenderCallback,(void*)this);
}
Пример #10
0
//コンストラクタ(簡易作成)
Window::Window(HINSTANCE hInstance, TCHAR *pCaption, TCHAR *pClassName, int Width, int Height)
{
	WNDCLASSEX wc;

	//ウィンドウクラスを定義する
	ZeroMemory(&wc, sizeof(WNDCLASSEX));
	wc.hInstance = hInstance;								//このインスタンスへのハンドル
	wc.lpszClassName = pClassName;							//ウィンドウクラス名
	wc.lpfnWndProc = Window::WndProc;						//ウィンドウプロシージャ関数
	wc.style = 0;											//ウィンドウスタイル(デフォルト)
	wc.cbSize = sizeof(WNDCLASSEX);							//WNDCLASSEX構造体のサイズを設定
	wc.hIcon = LoadIcon(hInstance, IDI_WINLOGO);			//ラージアイコン
	wc.hIconSm = LoadIcon(hInstance, IDI_WINLOGO);			//スモールアイコン
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);				//カーソルスタイル
	wc.lpszMenuName = NULL;									//メニュー
	wc.cbClsExtra = 0;										//エキストラ
	wc.cbWndExtra = 0;										//必要な情報
	wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);	//ウィンドウの背景

	RECT rect, rcDesktop;

	GetWindowRect(GetDesktopWindow(), &rcDesktop); //デスクトップの大きさを取得
	SetRect(&rect, 0, 0, Width, Height);
	AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, 0);

	CREATEWINDOWEX cw;

	ZeroMemory(&cw, sizeof(CREATEWINDOWEX));
	cw.dwExStyle = 0;								//拡張ウィンドウスタイル
	cw.lpClassName = wc.lpszClassName;				//ウィンドウクラスの名前
	cw.lpWindowName	= pCaption;						//ウィンドウタイトル
	cw.dwStyle = WS_OVERLAPPEDWINDOW;				//ウィンドウスタイル
	cw.x = (rcDesktop.right - rect.right) / 2;		// ウィンドウの左角X座標
	cw.y = (rcDesktop.bottom - rect.bottom) / 2;	// ウィンドウの左角Y座標
	cw.nWidth = rect.right - rect.left;				// ウィンドウの幅
	cw.nHeight = rect.bottom - rect.top;			// ウィンドウの高さ
	cw.hWndParent =	NULL;							//親ウィンドウ
	cw.hMenu = 	NULL;								//メニュー
	cw.hInstance = hInstance;						//このプログラムのインスタンスのハンドル
	cw.lpParam = NULL;								//追加引数	
			
	if (!CreateWnd(&wc, &cw, SW_SHOWNORMAL)) //ウィンドウ生成
	{
		//ウィンドウ生成に失敗した場合の処理を書く
	}
}
Пример #11
0
//выполнить инициализацию плеера
BOOL CDShowPlayer::Init()
{
	BOOL hr;
	HWND hwnd = CreateWnd(L"dshow_wnd");
	m_pPlayer = new DShowPlayer(hwnd);
	if (m_pPlayer == NULL)
	{
		return FALSE;
	}

	auto ansi_str = m_strFileName;
	const int size_of_ansi_str = 255;
	wchar_t ansi_wcstr[size_of_ansi_str];
	MultiByteToWideChar(CP_ACP, 0, ansi_str.c_str(), -1, ansi_wcstr, size_of_ansi_str);
	std::wstring ansi_wstr = std::wstring(ansi_wcstr);

	hr = m_pPlayer->OpenFile(ansi_wstr.c_str());
}
Пример #12
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    // 测试创建3个
    for(int n=0; n<3; ++n)
    {
        CreateWnd(QString("the number ") + QString::number(n));
    }



//    Toolbar* t = new Toolbar();
//    t->show();

//    BubbleGum* b = new BubbleGum();
//    b->show();

    return a.exec();
}
Пример #13
0
/**
 * The function that makes the window and the stuff
 */
HWND Win32Tools::InitWindow(HINSTANCE hinstance, WNDPROC WindowProc,
							  int width, int height, HBRUSH bgColor,
							  char Capitian[])
{
	if(!RegisterThisClass(hinstance, WindowProc, bgColor)) {
		MessageBoxA(0, "Register class failed!", "Error", MB_OK);
		exit(0);
	}

	HWND hwnd = CreateWnd(hinstance, Capitian);

	if(!hwnd) {
		MessageBoxA(0, "Create Window failed!", "Error", MB_OK);
		exit(0);
	}

	ShowWindow(hwnd, TRUE);
	UpdateWindow(hwnd);

	return hwnd;
}
Пример #14
0
/////////////////////////////////////////////////////////////////////////////
// CSettingsDialog::CreatePage(const PAGE_INFO *pInfo)
// Description: Create the Window of the page specified by the page info.
// Return value: TRUE if successful, or FALSE if failed
// 
BOOL CSettingsDialog::CreatePage(const PAGE_INFO *pInfo)
{
	BOOL bCode = FALSE;

	if (!pInfo || !pInfo->pWnd) return(FALSE);	// If no page is specified, return NULL
	if (!::IsWindow(pInfo->pWnd->m_hWnd))		// If the window has not yet been created,
	{
		if (pInfo->pWnd->IsKindOf(RUNTIME_CLASS(CDialog)))	// If the page indow is kind of dialog window
		{
			CDialog *pDlg = (CDialog*)pInfo->pWnd;
			bCode = pDlg->Create(pInfo->nID, this);
			pDlg->ModifyStyle(WS_CAPTION, 0);
		}
		else if (pInfo->pWnd->IsKindOf(RUNTIME_CLASS(CWnd)))	// generic CWnd derived Window
		{
			CWnd *pWnd = (CWnd*)pInfo->pWnd;
			bCode = CreateWnd(pInfo->pWnd);						// Create Window 
			pWnd->ModifyStyle(WS_BORDER|WS_THICKFRAME, 0);		// Remoce border and thick frame styles
		}
	}
	return(bCode);
}
Пример #15
0
bool iocp_server::Init(HINSTANCE hInstance)
{
	m_hInstance = hInstance;
	SetTitle("GameServer");
	CreateWnd();
	open();
	
		g_logger.fatal("读取数据库");
		CADO ado("felove");
		int ncount = ado.GetCount("MonsterTable");
		CRttiDbDataLoader::dbLoad<stMonsterData>(&ado,"select * from MonsterTable", ncount);
		if( ncount != stMonsterData::stdb.size())
		{
			g_logger.error("NPC数据库成功读取的条目与实际条目不符 期待值 %d 实际值 %d", ncount, stMonsterData::stdb.size());
		}
		g_logger.fatal("读取config");
		CXMLConfigParse conf;
		conf.InitConfig("gamesvr");
		int svrId = conf.readvalue("svrid",1);
		char svrname[30] = {0};
		conf.readstr("svrname",svrname, sizeof(svrname) - 1, "GameServer");
		g_logger.info("%s%d线启动...",svrname,svrId);
	return true;
}
Пример #16
0
dlgWndAskPIN::dlgWndAskPIN( DlgPinInfo pinInfo, DlgPinUsage PinPusage, std::wstring & Header, std::wstring & PINName, bool UseKeypad, HWND Parent )
:Win32Dialog(L"WndAskPIN")
{
	m_UseKeypad = UseKeypad;

	PinResult[0] = ' ';
	PinResult[1] = (char)0;

	std::wstring tmpTitle = L"";

	if( PinPusage == DLG_PIN_SIGN )
		tmpTitle += GETSTRING_DLG(SigningWith);
	else
		tmpTitle += GETSTRING_DLG(Asking);

	tmpTitle += L" ";
	tmpTitle += PINName;

	m_ulPinMinLen = pinInfo.ulMinLen;
	m_ulPinMaxLen = pinInfo.ulMaxLen;

	szHeader = Header.c_str();
	szPIN = PINName.c_str();

	int Height = 280;
	if( m_UseKeypad )
		Height = 480;

	if( CreateWnd( tmpTitle.c_str() , 480, Height, 0, Parent ) )
	{
		RECT clientRect;
		GetClientRect( m_hWnd, &clientRect );

		TextFont = CreateFont( 16, 0, 0, 0, FW_DONTCARE, 0, 0, 0,
				DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
				DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"MS Shell Dlg" );

		//OK Button
		HWND hOkButton = CreateWindow(
			L"BUTTON", GETSTRING_DLG(Ok), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON, 
			clientRect.right - 160, clientRect.bottom - 36, 72, 24, 
			m_hWnd, (HMENU)IDB_OK, m_hInstance, NULL );
		EnableWindow( hOkButton, false );

		//Cancel Button
		HWND hCancelButton = CreateWindow(
			L"BUTTON", GETSTRING_DLG(Cancel), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_TEXT, 
			clientRect.right - 80, clientRect.bottom - 36, 72, 24, 
			m_hWnd, (HMENU)IDB_CANCEL, m_hInstance, NULL );

		m_KeypadHeight=0;

		//Virtual Keypad
		if( m_UseKeypad )
		{
			int top = 60;
			int hMargin = 12;
			int vMargin = 12;
			int btnwidth = 48;
			int btnheight = 48;
			int totwidth = btnwidth*3 + 2*hMargin;
			int totheight = btnheight*4 +3*vMargin;
			int left = (clientRect.right - clientRect.left - totwidth)/2;
			m_KeypadHeight = top + totheight + 8;

			for( int i = 0; i < 4; i++ )
			{
				for( int  j = 0; j < 3; j++ )
				{
					if( i == 3 && j == 0 )
						continue;
					HWND hOkButton = CreateWindow(
						L"BUTTON", L"", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_OWNERDRAW, //BS_FLAT, 
						left + ( btnwidth + hMargin )* j, top + ( btnheight + vMargin ) * i, btnwidth, btnheight, 
						m_hWnd, (HMENU)(long long)(IDB_KeypadStart + 3*i + j ), m_hInstance, NULL );
				}
			}

			ImageKP_BTN[0] = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_KP_0) );
			ImageKP_BTN[1] = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_KP_1) );
			ImageKP_BTN[2] = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_KP_2) );
			ImageKP_BTN[3] = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_KP_3) );
			ImageKP_BTN[4] = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_KP_4) );
			ImageKP_BTN[5] = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_KP_5) );
			ImageKP_BTN[6] = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_KP_6) );
			ImageKP_BTN[7] = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_KP_7) );
			ImageKP_BTN[8] = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_KP_8) );
			ImageKP_BTN[9] = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_KP_9) );
			ImageKP_BTN[10] = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_KP_CE) );
			ImageKP_BTN[11] = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_KP_BTN) );

			CreateBitapMask( ImageKP_BTN[11], ImageKP_BTN_Mask );
			//MWLOG(LEV_DEBUG, MOD_DLG, L" dlgWndAskPIN : Virtual pinpad - LoadBitmap");
		}

		DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_PASSWORD;
		if( pinInfo.ulFlags & PIN_FLAG_DIGITS )
			dwStyle |= ES_NUMBER;

		LONG pinTop=0;
		LONG pinLeft=clientRect.right/2 - 100 + 40;

		if( m_UseKeypad )
			pinTop = clientRect.top + 20;
		else
			pinTop = clientRect.bottom - 80;

		HWND hTextEdit = CreateWindowEx( WS_EX_CLIENTEDGE,
			L"EDIT", L"", dwStyle, 
			pinLeft, pinTop, 160, 26, 
			m_hWnd, (HMENU)IDC_EDIT, m_hInstance, NULL );
		SendMessage( hTextEdit, EM_LIMITTEXT, m_ulPinMaxLen, 0 );

		HWND hStaticText = CreateWindow( 
			L"STATIC", szPIN, WS_CHILD | WS_VISIBLE | SS_RIGHT, 
			pinLeft-100, pinTop +4 , 96, 22, 
			m_hWnd, (HMENU)IDC_STATIC, m_hInstance, NULL );

		SendMessage( hStaticText, WM_SETFONT, (WPARAM)TextFont, 0 );

		SendMessage( hOkButton, WM_SETFONT, (WPARAM)TextFont, 0 );
		SendMessage( hCancelButton, WM_SETFONT, (WPARAM)TextFont, 0 );

		if( PinPusage == DLG_PIN_SIGN )
			ImagePIN = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_PINSIGN) );
		else
			ImagePIN = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_PIN) );
		CreateBitapMask( ImagePIN, ImagePIN_Mask );

		SetFocus(GetDlgItem( m_hWnd, IDC_EDIT ));
	}
}
Пример #17
0
// The main loop
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd)
{
	MSG msg;

	// Create a windows class for subsequently creating windows
	WNDCLASSEX ex;
	ex.cbSize = sizeof(WNDCLASSEX);
	ex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	ex.lpfnWndProc = WinProc;
	ex.cbClsExtra = 0;
	ex.cbWndExtra = 0;
	ex.hInstance = hinstance;
	ex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	ex.hCursor = LoadCursor(NULL, IDC_ARROW);
	ex.hbrBackground = NULL;
	ex.lpszMenuName = NULL;
	ex.lpszClassName = WNDCLASSNAME;
	ex.hIconSm = NULL;

	if (!RegisterClassEx(&ex))
	{
		MessageBox(NULL, "Failed to register the windows class", "Window Reg Error", MB_OK);
		return 1;
	}

	// Create the windows
	CreateWnd(hinstance, SCRWIDTH, SCRHEIGHT, SCRDEPTH);

	// Prompt the user for a filename and directory
	OPENFILENAME ofn;       // common dialog box structure
	ZeroMemory(&ofn, sizeof(ofn));
	char szFile[260];       // buffer for file name

	HWND hwndsave;

	// create the save as window
	hwndsave = CreateWindowEx(NULL,
		WNDCLASSNAME,
		WNDNAME,
		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
		100, 100,
		600, 600,
		NULL,
		NULL,
		hinstance,
		NULL);
	HANDLE hf;              // file handle

	szFile[0] = '\0';
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hwndsave;
	ofn.lpstrFilter = "Text\0*.TXT\0";
	ofn.lpstrFile = szFile;
	ofn.nMaxFile = sizeof(szFile) / sizeof(*szFile);
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = NULL;
	ofn.lpstrInitialDir = (LPSTR)NULL;
	ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
	ofn.lpstrTitle = "Specify the filename";
	ofn.lpstrDefExt = "txt";

	GetSaveFileName(&ofn);

	//Create a file to store the offset position at each point in time
	FILE *str;
	fopen_s(&str, ofn.lpstrFile, "w");

	//Set the filename for the DAQ data
	strncpy_s(syncfnamebuf, 100, ofn.lpstrFile, strlen(ofn.lpstrFile) - 4);
	strcat_s(syncfnamebuf, 100, "_SYNC.txt");
	syncfname = syncfnamebuf;

	// Print local time as a string.
	char s[30];
	size_t i;
	struct tm tim;
	time_t now;
	now = time(NULL);
	localtime_s(&tim, &now);
	i = strftime(s, 30, "%b %d, %Y; %H:%M:%S\n", &tim);
	fprintf(str, "Current date and time: %s\n", s);

	// Variables to store the treadmill update signal
	float dx0Now = 0.0f;
	float dx1Now = 0.0f;
	float dy0Now = 0.0f;
	float dy1Now = 0.0f;
	InitOffset();
	Sleep(1000);

	int cw = 1; // Move the open loop stripe in a clockwise direction
	int ccw = -1; // Move the open loop stripe in a counterclockwise direction
	int randomreset = 1;

	PFNWGLSWAPINTERVALEXTPROC       wglSwapIntervalEXT = NULL;
	PFNWGLGETSWAPINTERVALEXTPROC    wglGetSwapIntervalEXT = NULL;
	wglSwapIntervalEXT =
		(PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
	wglGetSwapIntervalEXT =
		(PFNWGLGETSWAPINTERVALEXTPROC)wglGetProcAddress("wglGetSwapIntervalEXT");

	// The main loop
	while (!quit)
	{
		if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
		{
			if (msg.message == WM_QUIT)
				quit = true;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}


		// Timestamp closed loop output in order to recreate later
		QueryPerformanceCounter(&li);
		float netTime = (li.QuadPart - CounterStart) / PCFreq;

		if (randomreset)
		{
			//Generate a random starting offset
			srand(time(0));
			io_mutex.lock();
			BallOffsetRot = fmod(rand(), 180) - 90;
			BallOffsetFor = 0.0f;//-dist2stripe*0.5;
			BallOffsetSide = 0.0f;
			io_mutex.unlock();
			randomreset = 0;
		}

		/////////////////////// EXPERIMENT SPECIFICS LIVE HERE /////////////////////////////
		if (netTime < 1)
		{
			closed = 1;
			olsdir = 0;
		}
		if (netTime > 1 && netTime < 0.5 * 60)
		{
			closed = 1;		
			olsdir = 0;
		}
		if (netTime > 0.5 * 60 && netTime < 4.5 * 60)
		{
			closed = 1;
			olsdir = 1;
		}
		if (netTime > 4.5 * 60 && netTime < 5 * 60)
		{
			closed = 1;
			olsdir = 0;
		}
		if (netTime > 5 * 60)
			break;
		////////////////////////////////////////////////////////////////////////////////////

		//Switch contexts and draw
		wglMakeCurrent(hdc1, hglrc);
		RenderFrame(olsdir);

		//Swapbuffers
		SwapBuffers(hdc1);

		// Note the time that's passed
		QueryPerformanceCounter(&li);
		netTime = (li.QuadPart - CounterStart) / PCFreq;

		// Pull out the relevant values
		io_mutex.lock();
		if (closed)
			BallOffsetRotNow = BallOffsetRot;
		BallOffsetForNow = BallOffsetFor;
		BallOffsetSideNow = BallOffsetSide;
		dx0Now = dx0;
		dx1Now = dx1;
		dy0Now = dy0;
		dy1Now = dy1;
		io_mutex.unlock();

		//Print the elapsed time
		fprintf(str, "Elapsed time:\t%f\t", netTime);
		//Print the offset to the log file
		fprintf(str, "Rotational Offset:\t%f\t", BallOffsetRotNow);
		fprintf(str, "Forward Offset:\t%f\t", BallOffsetForNow);
		fprintf(str, "Lateral Offset:\t%f\t", BallOffsetSideNow);
		fprintf(str, "dx0:\t%f\t", dx0Now);
		fprintf(str, "dx1:\t%f\t", dx1Now);
		fprintf(str, "dy0:\t%f\t", dy0Now);
		fprintf(str, "dy1:\t%f\t", dy1Now);
		fprintf(str, "closed:\t%d\t", closed);
		fprintf(str, "olsdir:\t%d\n", olsdir);

		if (GetAsyncKeyState(VK_ESCAPE) || (netTime > 30 * 60))
			SysShutdown();
	}
	GLShutdown();
	fclose(str);
	return msg.lParam;
}
Пример #18
0
bool AWinControlBase::Create()
{
	if( m_pWindow ) return true;
	
	InitControls();

	m_pWindow = CreateWnd();
	if( m_pWindow == NULL ) return false;
	m_pWindow->AddRef();

	HWND hParent = NULL;
	AControl* pParent = dynamic_cast<AControl*>( GetParent() );
	if( pParent ) hParent = pParent->GetUICore()->GetHandle();
	
	if( !m_pWindow->Create(hParent,m_WindowPos) ) 
	{
		m_pWindow->Release();
		m_pWindow = NULL;
		throw AException(_T("窗口创建失败!"));
		return false;
	}

	AContainer* pcParent = dynamic_cast<AContainer*>(GetParent());
	if( pcParent )
		pcParent->GetUICore()->AddWatcher(this);

	//再进行下面的处理
	if( m_WindowPos == wpDesign )
	{
		::SetWindowPos(GetHandle(),HWND_NOTOPMOST,GetLeft(),GetTop(),GetWidth(),GetHeight(),SWP_NOREDRAW|SWP_HIDEWINDOW);
	}
	else if( m_WindowPos == wpCenterScreen )
	{
		ARect rScreen;
		SystemParametersInfo(SPI_GETWORKAREA,0,&rScreen,0);
		int dw = (rScreen.right-rScreen.left-GetWidth())/2;
		int dh = (rScreen.bottom-rScreen.top-GetHeight())/2;
		m_iLeft = (rScreen.left+dw);
		m_iTop = (rScreen.top+dh);
		::SetWindowPos(GetHandle(),HWND_NOTOPMOST,GetLeft(),GetTop(),GetWidth(),GetHeight(),SWP_NOREDRAW|SWP_HIDEWINDOW);
	}
	else
	{
		ARect r;
		::GetWindowRect(GetHandle(),&r);
		//::SetWindowPos(GetHandle(),HWND_NOTOPMOST,r.left,r.top+1,r.GetWidth(),r.GetHeight(),0);
		m_iLeft = r.left;
		m_iTop = r.top;
		m_iWidth = r.GetWidth();
		m_iHeight = r.GetHeight();
		
	}
	//::SetWindowPos(GetHandle(),HWND_NOTOPMOST,GetLeft(),GetTop(),GetWidth(),GetHeight(),0);//SWP_NOREDRAW|SWP_HIDEWINDOW);
	//::SetWindowPos(GetHandle(),HWND_NOTOPMOST,GetLeft(),GetTop(),GetWidth(),GetHeight(),SWP_NOREDRAW|SWP_HIDEWINDOW);
	DoCreate();
	ConnectEvent();
	DoLayout();
	Refresh();


	//HRGN hRgn = ::CreateRoundRectRgn(0,0,GetWidth()+1,GetHeight()+1,5,5);
	//::SetWindowRgn(m_pWindow->GetHandle(),hRgn,FALSE);
	//::DeleteObject(hRgn);

	AEvent evt;
	OnCreate.Call(this,&evt);
	return true;
}
Пример #19
0
dlgWndBadPIN::dlgWndBadPIN( std::wstring & PINName, unsigned long RemainingTries, HWND Parent )
:Win32Dialog(L"WndBadPIN")
{
	std::wstring tmpTitle = L"";

	if(wcscmp(L"nl",langbad.c_str())==0)
		tmpTitle += (L"Atenção");
	else
		tmpTitle += GETSTRING_DLG(Notification);
	tmpTitle += L": ";
	tmpTitle += GETSTRING_DLG(Bad); 
	tmpTitle += L" ";

	if ( wcsstr(const_cast<wchar_t*>( PINName.c_str()), (L"PIN da Autentica")) != 0)
		tmpTitle += (L"Pin da Autenticação");
	else
		tmpTitle += PINName;

	wchar_t tmpBuf[128];
	std::wstring tmpStr = L"";
	_itow_s( RemainingTries, tmpBuf, 128, 10 ); 
	szHeader = new wchar_t[128];
	szBody = L"";

	tmpStr = GETSTRING_DLG(Bad);
	tmpStr += L" \""; 
	if ( wcsstr(const_cast<wchar_t*>( PINName.c_str()), (L"PIN da Autentica")) != 0)
		tmpStr += (L"Pin da Autenticação");
	else
		tmpStr += PINName;
	tmpStr += L"\": ";
	tmpStr += tmpBuf;
	tmpStr += L" "; 
	tmpStr += GETSTRING_DLG(RemainingAttempts); 
	wcscpy_s( szHeader, 128, tmpStr.c_str() );
	if( RemainingTries == 0 )
	{
		if ( wcsstr(const_cast<wchar_t*>( PINName.c_str()), (L"PIN da Autentica")) != 0)
			tmpTitle += (L"Pin da Autenticação");
		else
			tmpTitle += PINName;
		tmpStr += L" ";
		tmpStr = GETSTRING_DLG(PinBlocked);
		szBody = tmpStr.c_str();
	}
	else
	{
		szBody = GETSTRING_DLG(TryAgainOrCancel);
	}

	if( CreateWnd( tmpTitle.c_str() , 280, 230, 0,  Parent ) )
	{
		RECT clientRect;
		GetClientRect( m_hWnd, &clientRect );

		TextFont = CreateFont( 16, 0, 0, 0, FW_DONTCARE, 0, 0, 0,
				DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
				DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"MS Shell Dlg" );

		if( RemainingTries == 0 )
		{
			HWND hOkButton = CreateWindow(
				L"BUTTON", GETSTRING_DLG(Ok), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON, 
				clientRect.right - 160, clientRect.bottom - 36, 72, 24, 
				m_hWnd, (HMENU)IDB_OK, m_hInstance, NULL );
			SendMessage( hOkButton, WM_SETFONT, (WPARAM)TextFont, 0 );
		}
		else
		{
			HWND hRetryButton = CreateWindow(
				L"BUTTON", GETSTRING_DLG(Retry), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON, 
				clientRect.right - 160, clientRect.bottom - 36, 72, 24, 
				m_hWnd, (HMENU)IDB_RETRY, m_hInstance, NULL );
			SendMessage( hRetryButton, WM_SETFONT, (WPARAM)TextFont, 0 );

			HWND hCancelButton = CreateWindow(
				L"BUTTON", GETSTRING_DLG(Cancel), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_TEXT, 
				clientRect.right - 80, clientRect.bottom - 36, 72, 24, 
				m_hWnd, (HMENU)IDB_CANCEL, m_hInstance, NULL );
			SendMessage( hCancelButton, WM_SETFONT, (WPARAM)TextFont, 0 );
		}

		HWND hStaticText = CreateWindow( 
			L"STATIC", szBody, WS_CHILD | WS_VISIBLE | SS_CENTER, 
			0, clientRect.bottom - 76, clientRect.right, 22, 
			m_hWnd, (HMENU)IDC_STATIC, m_hInstance, NULL );
		SendMessage( hStaticText, WM_SETFONT, (WPARAM)TextFont, 0 );

		ImagePIN = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_PIN) );
		CreateBitapMask( ImagePIN, ImagePIN_Mask );
	}
}
Пример #20
0
void Entry(void)
{
	HHOOK hHook=NULL;
	HOOKPROC pfnHookProc;
	HWND hWnd=NULL;
	int result=1;

	g_controlMsg=RegisterWindowMessageA(CONTROL_MESSAGE_NAME);

	g_hDLL=LoadLibraryA(DLL_NAME);
	if(!g_hDLL)
	{
		DWORD err=GetLastError();
		char msg[500];

		FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,NULL,err,0,msg,sizeof msg,NULL);

		MessageBoxA(NULL,msg,DLL_NAME,MB_OK|MB_ICONERROR);
		goto done;
	}

	g_pfnSetKeyboardLayout=(SetKeyboardLayoutFn)FindProc("SetKeyboardLayout");
	if(!g_pfnSetKeyboardLayout)
		goto done;

	pfnHookProc=(HOOKPROC)FindProc(HOOKNAME("KBSwitchCBTHookProc"));
	if(!pfnHookProc)
		goto done;

	hHook=SetWindowsHookEx(WH_CBT,pfnHookProc,g_hDLL,0);
	if(!hHook)
		goto done;

	hWnd=CreateWnd();

	if(hWnd)
	{
		for(;;)
		{
			int r;
			MSG msg;

			r=GetMessage(&msg,NULL,0,0);
			if(r==0||r==-1)
				break;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		result=0;
	}

done:
	if(hWnd)
	{
		DestroyWindow(hWnd);
		hWnd=NULL;
	}

	if(hHook)
	{
		UnhookWindowsHookEx(hHook);
		hHook=NULL;
	}

	if(g_hDLL)
	{
		FreeLibrary(g_hDLL);
		g_hDLL=NULL;
	}

	ExitProcess(result);
}
Пример #21
0
HWND Window::AutoRegistCreateWnd(LPCTSTR Class,DWORD Style,int x,int y,int width,int height,HWND hParent,HMENU hMenu,HINSTANCE hInst){
	RegisterWC(hInst,Class);
	return CreateWnd(Class,Style,x,y,width,height,hParent,hMenu,hInst);
}
Пример #22
0
//コンストラクタ(詳細作成)
Window::Window(WNDCLASSEX *pWCE, CREATEWINDOWEX *pCWE) 
{
	CreateWnd(pWCE, pCWE, SW_SHOWNORMAL); //ウィンドウ生成
}
Пример #23
0
int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd )
{
	MSG msg;
	WNDCLASSEX ex;
	int argc;
	char cmdline[512];
	const char* argv[32];
	char* tok;

	// Convert command line into C-style argc & argv.
	strcpy( cmdline, lpcmdline );
	argv[0] = "cylindrix";
	argc = 1;
	tok = strtok( cmdline, " \t" );
	while ( tok )
	{
		argv[argc++] = tok;		
		tok = strtok( 0, " \t" );
	}

	ex.cbSize = sizeof(WNDCLASSEX);
	ex.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
	ex.lpfnWndProc = WinProc;
	ex.cbClsExtra = 0;
	ex.cbWndExtra = 0;
	ex.hInstance = hinstance;
	ex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	ex.hCursor = LoadCursor(NULL, IDC_ARROW);
	ex.hbrBackground = NULL;
	ex.lpszMenuName = NULL;
	ex.lpszClassName = WNDCLASSNAME;
	ex.hIconSm = NULL;

	if ( !RegisterClassEx( &ex ) )
	{
		MessageBox( NULL, "Failed to register the window class", "Window Reg Error", MB_OK );
		return 1;
	}

	// Create the window
	CreateWnd( hinstance, screenw, screenh, SCRDEPTH, WINDOWED );

	GameInit( argc, argv );

	// The message loop
	while ( !quit )
	{
		quit = GameLoop();

		// clear keys pressed.
		memset( keysPressed, 0, 255 );

		SwapBuffers( hdc );

		if ( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
		{
			if (msg.message == WM_QUIT)
				quit = TRUE;

			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
	}
	
	GameShutdown();
	SysShutdown();

	return msg.lParam;
}
Пример #24
0
/*
*--------------------------------------------------------------------------------
*  函数名	: SetCartoonDib
*  功能		: 设置卡通窗口的 Dib 图像
*  参数		: CString strDibFileName -	加载位图的文件名
*  算法		:
*  前置条件 : m_pDib 已初始化
*  后置条件 : 删除现存的位图,赋于新的位图,销毁现存窗口,新建一个窗口并居中显示
*--------------------------------------------------------------------------------
*/
void CFloatDibWnd::SetCartoonDib(CString strDibFileName)
{
    if(!FileExist(strDibFileName))
		return;

	DestroyWindow();

	if (m_pDib)
	{
		m_pDib->Destroy();
		delete m_pDib;
	}

//	Canvas * pWnd = (Canvas *)GetParent();
//	CRect wndRect = pWnd->GetCanvasWndRect();

	// 从文件中导入图片
	m_pDib = new CDib();
	m_pDib->Load(strDibFileName);
//	m_pDib->ChangeImageSize(nWidth, nHeight);

	CRect rcWnd;
	::GetWindowRect(m_hParentWnd, &rcWnd);

	// 初始化时的窗口大小
	long nWidth = m_pDib->GetWidth();
	long nHeight = m_pDib->GetHeight();

    double scaleXY = nWidth/nHeight;
    double scaleYX = nHeight/nWidth;
    double scaleDef = rcWnd.Width()/rcWnd.Height();

	if(scaleXY <= scaleDef)
	{
		if(nWidth > rcWnd.Width()-4)
		{

     			nWidth = rcWnd.Width()-20;
				nHeight = nWidth * scaleYX;
		}
	}
   else
   {
      if(nHeight > rcWnd.Height() - 4)
	  {
		  nHeight = rcWnd.Height() -4;
		  nWidth = nHeight * scaleXY;
	  }

   }
   
   //根据主窗口上滑块的位置计算图象加载的大小
    if(g_stuPaintSet.bCartoonOrgSize)
	{
		m_rcWndRect.left = rcWnd.Width() / 2 - nWidth / 2;
		m_rcWndRect.right = rcWnd.Width() / 2 + nWidth / 2;
		m_rcWndRect.top = rcWnd.Height() / 2 - nHeight / 2;
		m_rcWndRect.bottom = rcWnd.Height() / 2 + nHeight / 2;
	}
	else
	{
        DOUBLE scale =  m_curDrawSize/110.0;
	    m_rcWndRect.left = rcWnd.Width() / 2 - DOUBLE(nWidth / 2.0)*scale;
		m_rcWndRect.right = rcWnd.Width() / 2 + DOUBLE(nWidth / 2.0)*scale;
		m_rcWndRect.top = rcWnd.Height() / 2 - DOUBLE(nHeight / 2.0)*scale;
		m_rcWndRect.bottom = rcWnd.Height() / 2 + DOUBLE(nHeight / 2.0)*scale;      

	}

	// 保存原始图像
	if (m_pSrcDib)
		delete m_pSrcDib;
	m_pSrcDib = m_pDib->Clone();

   CheckShowBtn();

	// 创建窗口
	CreateWnd();
}