Exemple #1
0
LRESULT CALLBACK insert_dlg_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	static TABLE_WINDOW *win=0;
	static HWND hlistview=0,hgrippy=0,hedit=0;
	static HFONT hfont=0;
	static WNDPROC origlistview=0;
	if(FALSE)
	{
		static DWORD tick=0;
		if((GetTickCount()-tick)>500)
			printf("--\n");
		if(hwnd==hlistview)
			printf("-");
		print_msg(msg,lparam,wparam,hwnd);
		tick=GetTickCount();
	}
	if(origlistview!=0 && hwnd==hlistview){
		if(msg==WM_GETDLGCODE){
			return DLGC_WANTARROWS;
		}
		return CallWindowProc(origlistview,hwnd,msg,wparam,lparam);
	}
	switch(msg){
	case WM_INITDIALOG:
		if(lparam==0){
			EndDialog(hwnd,0);
			break;
		}
		hedit=0;
		win=lparam;
		hlistview=CreateWindow(WC_LISTVIEW,"",WS_TABSTOP|WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE|LVS_REPORT|LVS_SHOWSELALWAYS,
                                     0,0,
                                     0,0,
                                     hwnd,
                                     IDC_LIST1,
                                     ghinstance,
                                     NULL);
		if(hlistview!=0){
			ListView_SetExtendedListViewStyle(hlistview,LVS_EX_FULLROWSELECT);
			hfont=SendMessage(win->hlistview,WM_GETFONT,0,0);
			if(hfont!=0)
				SendMessage(hlistview,WM_SETFONT,hfont,0);
			populate_insert_dlg(hwnd,hlistview,win);
			ListView_SetItemState(hlistview,0,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
			origlistview=SetWindowLong(hlistview,GWL_WNDPROC,(LONG)insert_dlg_proc);
		}
		set_title(hwnd,win);
		hgrippy=create_grippy(hwnd);
		resize_insert_dlg(hwnd);
		break;
	case WM_NOTIFY:
		{
			NMHDR *nmhdr=lparam;
			if(nmhdr!=0){
				switch(nmhdr->code){
				case NM_DBLCLK:
					if(hedit==0 && nmhdr->hwndFrom==hlistview)
						SendMessage(hwnd,WM_COMMAND,IDOK,0);
					break;
				case  LVN_COLUMNCLICK:
					{
						static sort_dir=0;
						NMLISTVIEW *nmlv=lparam;
						if(nmlv!=0){
							sort_listview(hlistview,sort_dir,nmlv->iSubItem);
							sort_dir=!sort_dir;
						}
					}
					break;
				case LVN_KEYDOWN:
					if(nmhdr->hwndFrom==hlistview)
					{
						LV_KEYDOWN *key=lparam;
						switch(key->wVKey){
						case VK_DOWN:
						case VK_RIGHT:
						case VK_NEXT:
							{
								int count,row_sel;
								count=ListView_GetItemCount(hlistview);
								row_sel=ListView_GetSelectionMark(hlistview);
								if(count>0 && row_sel==count-1)
									SetFocus(GetDlgItem(hwnd,IDOK));
							}
							break;
						case VK_DELETE:
							clear_selected_items(hlistview);
							break;
						case VK_F5:
							if(task_insert_row(win,hlistview))
								SetWindowText(GetDlgItem(hwnd,IDOK),"Busy");
							break;
						case 'A':
							if(GetKeyState(VK_CONTROL)&0x8000){
								int i,count;
								count=ListView_GetItemCount(hlistview);
								for(i=0;i<count;i++){
									ListView_SetItemState(hlistview,i,LVIS_SELECTED,LVIS_SELECTED);
								}
								break;
							}
						default:
							{
								int ignore=FALSE;
								if(!is_entry_key(key->wVKey))
									ignore=TRUE;
								if(GetKeyState(VK_CONTROL)&0x8000)
									ignore=TRUE;
								if(ignore)
									return 1;
							}
						case ' ':
						case VK_F2:
						case VK_INSERT:
							{
								int row_sel=ListView_GetSelectionMark(hlistview);
								if(row_sel>=0 && hedit==0){
									hedit=CreateWindow("EDIT","",WS_THICKFRAME|WS_TABSTOP|WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE|
											ES_LEFT|ES_AUTOHSCROLL,
											0,0,
											0,0,
											hwnd,
											IDC_EDIT1,
											ghinstance,
											NULL);
									if(hedit!=0){
										RECT rect={0},crect={0};
										int x,y,w,h;
										ListView_GetItemRect(hlistview,row_sel,&rect,LVIR_BOUNDS);
										lv_get_col_rect(hlistview,DATA_POS,&crect);
										x=crect.left-2;
										y=rect.top-2;
										w=crect.right-crect.left+8;
										h=rect.bottom-rect.top+8;
										SetWindowPos(hedit,HWND_TOP,x,y,w,h,0);
										if(hfont!=0)
											SendMessage(hedit,WM_SETFONT,hfont,0);
										if(is_entry_key(key->wVKey)){
											char str[2];
											char c=tolower(key->wVKey);
											if((GetKeyState(VK_SHIFT)&0x8000) || (GetKeyState(VK_CAPITAL)&1))
												c=toupper(c);
											str[0]=c;
											str[1]=0;
											SetWindowText(hedit,str);
											SendMessage(hedit,EM_SETSEL,1,1);

										}else{
											populate_edit_control(hlistview,hedit,row_sel);
										}
										SetFocus(hedit);
										wporigtedit=SetWindowLong(hedit,GWL_WNDPROC,(LONG)sc_edit);
									}
								}
							}
							break;
						}

					}
					break;
				}

			}
		}
		break;
	case WM_HSCROLL:
		if(lparam==hgrippy)
			SetFocus(hlistview);
		break;
	case WM_USER:
		if(hedit!=0 && lparam==hedit){
			hedit=0;
			SetFocus(hlistview);
		}
		else if(lparam==hlistview){
			if(wparam==IDOK){
				add_row_tablewindow(win,hlistview);
			}
			else
				SetFocus(GetDlgItem(hwnd,IDCANCEL));

			SetWindowText(GetDlgItem(hwnd,IDOK),"OK");
		}
		break;
	case WM_SIZE:
		resize_insert_dlg(hwnd);
		grippy_move(hwnd,hgrippy);
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDOK:
			if(hedit!=0){
				if(GetFocus()==hedit){
					char str[80]={0};
					int count,row_sel=ListView_GetSelectionMark(hlistview);
					GetWindowText(hedit,str,sizeof(str));
					resize_column(hwnd,hlistview,str,1);
					lv_update_data(hlistview,row_sel,DATA_POS,str);
					SendMessage(hedit,WM_CLOSE,0,0);
					count=ListView_GetItemCount(hlistview);
					if(row_sel < (count-1)){
						ListView_SetItemState(hlistview,row_sel,0,LVIS_SELECTED|LVIS_FOCUSED);
						row_sel++;
						ListView_SetItemState(hlistview,row_sel,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
						ListView_SetSelectionMark(hlistview,row_sel);
					}
					hedit=0;
				}
				break;
			}
			else if(GetFocus()==hlistview){
				static LV_KEYDOWN lvk={0};
				lvk.hdr.hwndFrom=hlistview;
				lvk.hdr.code=LVN_KEYDOWN;
				lvk.wVKey=VK_INSERT;
				SendMessage(hwnd,WM_NOTIFY,0,&lvk);
				break;
			}
			else{
				if(task_insert_row(win,hlistview))
					SetWindowText(GetDlgItem(hwnd,IDOK),"Busy");

			}
			break;
		case IDCANCEL:
			if(hedit!=0){
				SendMessage(hedit,WM_CLOSE,0,0);
				hedit=0;
				break;
			}
			EndDialog(hwnd,0);
			break;
		}
		break;	
	}
	return 0;
}
Exemple #2
0
KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
                                    module_config_t *p_item,
                                    HWND parent, HINSTANCE hInst,
                                    int * py_pos )
  : ConfigControl( p_this, p_item, parent, hInst )
{
    // Number of keys descriptions
    unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);

    // Init the keys decriptions array
    if( m_keysList == NULL )
    {
        m_keysList = new string[i_keys];
        for( unsigned int i = 0; i < i_keys; i++ )
        {
            m_keysList[i] = vlc_keys[i].psz_key_string;
        }
    }

    label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
                WS_CHILD | WS_VISIBLE | SS_LEFT, 5, *py_pos, 200, 15,
                parent, NULL, hInst, NULL );

    *py_pos += 15 + 10;

    alt = CreateWindow( _T("BUTTON"), _T("Alt"),
                        WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                        20, *py_pos, 15, 15, parent, NULL, hInst, NULL );
    Button_SetCheck( alt, p_item->i_value & KEY_MODIFIER_ALT ? BST_CHECKED :
                     BST_UNCHECKED );

    alt_label = CreateWindow( _T("STATIC"), _T("Alt"),
                WS_CHILD | WS_VISIBLE | SS_LEFT, 20 + 15 + 5, *py_pos, 30, 15,
                parent, NULL, hInst, NULL );

    ctrl = CreateWindow( _T("BUTTON"), _T("Ctrl"),
                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                20 + 15 + 5 + 30 + 5, *py_pos, 15, 15,
                parent, NULL, hInst, NULL );
    Button_SetCheck( ctrl, p_item->i_value & KEY_MODIFIER_CTRL ? BST_CHECKED :
                     BST_UNCHECKED );

    ctrl_label = CreateWindow( _T("STATIC"), _T("Ctrl"),
                WS_CHILD | WS_VISIBLE | SS_LEFT,
                20 + 15 + 5 + 30 + 5 + 15 + 5, *py_pos, 30, 15,
                parent, NULL, hInst, NULL );

    shift = CreateWindow( _T("BUTTON"), _T("Shift"),
                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                20 + 15 + 5 + 2*(30 + 5) + 15 + 5, *py_pos, 15, 15,
                parent, NULL, hInst, NULL );
    Button_SetCheck( shift, p_item->i_value & KEY_MODIFIER_SHIFT ?
                     BST_CHECKED : BST_UNCHECKED );

    shift_label = CreateWindow( _T("STATIC"), _T("Shift"),
                WS_CHILD | WS_VISIBLE | SS_LEFT,
                20 + 15 + 5 + 2*(30 + 5) + 2*(15 + 5), *py_pos, 30, 15,
                parent, NULL, hInst, NULL );

    *py_pos += 15 + 10;

    combo = CreateWindow( _T("COMBOBOX"), _T(""),
                WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
                CBS_SORT | WS_VSCROLL, 20, *py_pos, 130, 5*15 + 6,
                parent, NULL, hInst, NULL );

    *py_pos += 15 + 10;

    for( unsigned int i = 0; i < i_keys ; i++ )
    {
        ComboBox_AddString( combo, _FROMMB(m_keysList[i].c_str()) );
        ComboBox_SetItemData( combo, i, (void*)vlc_keys[i].i_key_code );
        if( (unsigned int)vlc_keys[i].i_key_code ==
            ( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ) )
        {
            ComboBox_SetCurSel( combo, i );
            ComboBox_SetText( combo, _FROMMB(m_keysList[i].c_str()) );
        }
    }
}
Exemple #3
0
LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
	static string in_encr, in_decr, pb_key, pr_key, key, out;
	static RECT clientRect = { 0 };
	static RECT textRect1;
	static RECT textRect2;
	static RECT textRect3;
	static int xEncrypt, yEncrypt;
	static int xDecrypt, yDecrypt;
	static int xGenerate, yGenerate;
	static HWND EncryptButton = NULL;
	static HWND DecryptButton = NULL;
	static HWND GenerateButton = NULL;
	static HWND ChooseEncrButton = NULL;
	static HWND ChooseDecrButton = NULL;
	static HWND ChooseKeyButton = NULL;
	static HWND HelpWindow = NULL;
	static HWND EncryptTextField = NULL;
	static HWND DecryptTextField = NULL;
	static HWND KeyTextField = NULL;

	static HDC hDCScreen = GetDC(NULL);
	static int Horres = GetDeviceCaps(hDCScreen, HORZRES);
	static int Vertres = GetDeviceCaps(hDCScreen, VERTRES);

	HDC hdc = NULL;
	PAINTSTRUCT paintStruct; // A PAINTSTRUCT structure is something we need to paint (draw) when handling the WM_PAINT message.

	PAINTSTRUCT ps;
	OPENFILENAME open_params = { 0 }; // This structure is used by the either the
									  // GetOpenFileName() function (for opening files)
									  // or the GetSaveFileName() function (for saving files)
									  // We're going to use it for opening a file -- Info about
									  // the file we try to open WILL be stored in this struct

	char filter[BUFF_MAX] = { 0 }; // This will be filled in with a "filter", explained later :)
	char file_name[BUFF_MAX] = { 0 }; // This will be used as the "default filename" for the
									  // dialog box

	wchar_t  str[BUFF_MAX];

	switch (message)
	{

	case WM_CREATE: // This message is sent when the window is created.									
					// We would want to put our initialization code here...
		GetClientRect(hwnd, &clientRect);
		DragAcceptFiles(ChooseKeyButton, TRUE);

		EncryptButton = CreateWindow("Button", "Зашифровать", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
			CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			CW_USEDEFAULT, hwnd, (HMENU)ENCRYPT_BUTTON,
			((LPCREATESTRUCT)lparam)->hInstance, NULL);

		DecryptButton = CreateWindow("Button", "Расшифровать", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
			CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			CW_USEDEFAULT, hwnd, (HMENU)DECRYPT_BUTTON,
			((LPCREATESTRUCT)lparam)->hInstance, NULL);

		GenerateButton = CreateWindow("Button", "Сгенерировать", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
			CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			CW_USEDEFAULT, hwnd, (HMENU)GENERATE_BUTTON,
			((LPCREATESTRUCT)lparam)->hInstance, NULL);

		ChooseEncrButton = CreateWindow("Button", "Выбрать файл", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
			CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			CW_USEDEFAULT, hwnd, (HMENU)CHOOSE_ENCR_BUTTON,
			((LPCREATESTRUCT)lparam)->hInstance, NULL);

		ChooseDecrButton = CreateWindow("Button", "Выбрать файл", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
			CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			CW_USEDEFAULT, hwnd, (HMENU)CHOOSE_DECR_BUTTON,
			((LPCREATESTRUCT)lparam)->hInstance, NULL);

		ChooseKeyButton = CreateWindowEx(WS_EX_ACCEPTFILES, "Button", "Выбрать файл", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
			CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			CW_USEDEFAULT, hwnd, (HMENU)CHOOSE_KEY_BUTTON,
			((LPCREATESTRUCT)lparam)->hInstance, NULL);

		EncryptTextField = CreateWindow("Edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE | NULL | NULL,
			CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			CW_USEDEFAULT, hwnd, (HMENU)TEXT_FIELD,
			((LPCREATESTRUCT)lparam)->hInstance, NULL);

		KeyTextField = CreateWindow("Edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE | NULL | NULL,
			CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			CW_USEDEFAULT, hwnd, (HMENU)TEXT_FIELD,
			((LPCREATESTRUCT)lparam)->hInstance, NULL);

		DecryptTextField = CreateWindow("Edit", "", WS_BORDER | WS_CHILD | WS_VISIBLE | NULL | NULL,
			CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			CW_USEDEFAULT, hwnd, (HMENU)TEXT_FIELD,
			((LPCREATESTRUCT)lparam)->hInstance, NULL);
		break;


	case WM_GETMINMAXINFO:
	{
		MINMAXINFO *minmax = (MINMAXINFO *)lparam;
		minmax->ptMinTrackSize.x = WINDOW_WIDTH;
		minmax->ptMinTrackSize.y = WINDOW_HEIGHT;
		break;
	}

	case WM_PAINT: // This message is sent to the WndProc when the window needs to be repainted.  
				   // Put code here to paint what should be in the window.	

		hdc = BeginPaint(hwnd, &paintStruct);
		GetClientRect(hwnd, &clientRect);

		textRect1.left = clientRect.right * 3 / 16 - 67;
		textRect1.top = clientRect.bottom / 15;
		textRect2.left = clientRect.right * 8 / 16 - 78;
		textRect2.top = clientRect.bottom / 15;
		textRect3.left = clientRect.right * 13 / 16 - 68;
		textRect3.top = clientRect.bottom / 15;

		DrawText(hdc, "Выберите файл для\n     шифрования:", -1, &textRect1, DT_NOCLIP);
		DrawText(hdc, "Выберите файл ключа:", -1, &textRect2, DT_NOCLIP);
		DrawText(hdc, "Выберите файл для\n   расшифрования:", -1, &textRect3, DT_NOCLIP);

		MoveWindow(EncryptButton, clientRect.right * 1 / 16, clientRect.bottom * 9 / 11, clientRect.right / 4, clientRect.bottom / 7, true);
		MoveWindow(GenerateButton, clientRect.right * 6 / 16, clientRect.bottom * 9 / 11, clientRect.right / 4, clientRect.bottom / 7, true);
		MoveWindow(DecryptButton, clientRect.right * 11 / 16, clientRect.bottom * 9 / 11, clientRect.right / 4, clientRect.bottom / 7, true);
		MoveWindow(ChooseEncrButton, clientRect.right * 1 / 16, clientRect.bottom * 3 / 11, clientRect.right / 4, clientRect.bottom / 7, true);
		MoveWindow(ChooseDecrButton, clientRect.right * 11 / 16, clientRect.bottom * 3 / 11, clientRect.right / 4, clientRect.bottom / 7, true);
		MoveWindow(ChooseKeyButton, clientRect.right * 6 / 16, clientRect.bottom * 3 / 11, clientRect.right / 4, clientRect.bottom / 7, true);
		MoveWindow(EncryptTextField, clientRect.right * 1 / 16, clientRect.bottom * 6 / 11, clientRect.right / 4, clientRect.bottom / 7, true);
		MoveWindow(KeyTextField, clientRect.right * 6 / 16, clientRect.bottom * 6 / 11, clientRect.right / 4, clientRect.bottom / 7, true);
		MoveWindow(DecryptTextField, clientRect.right * 11 / 16, clientRect.bottom * 6 / 11, clientRect.right / 4, clientRect.bottom / 7, true);
		break;


	case WM_COMMAND:
		//MessageBox(NULL, (LPCSTR)L"Win Computer", (LPCSTR)L"Ok!", MB_OK);

		
		if (HIWORD(wparam) == BN_CLICKED)
		{
			/* 	But we have 3 buttons!  How do we know which one was clicked?
			The LOWORD(wparam) gets us the "button's ID" -- This was set as the 7th parameter
			in CreateWindow() when were making the buttons.
			So depending on the "button's ID" we know what button has been clicked
			*/
			if (LOWORD(wparam) == ENCRYPT_BUTTON)
			{
				/*
				encryptTxtFile(string in, string out, string pbkey);
				*/
				
				if ((in_encr.size() > 3) && (key.size() > 3))
				{
					out = in_encr;

					out.pop_back();
					out.pop_back();
					out.pop_back();
					out.pop_back();

					out = out + "-crypted.txt";

					rsa::encryptTxtFile(in_encr, out, key);

					string textMsg;
					textMsg = "Зашифрованный файл: \n" + out;
					MessageBox(NULL, textMsg.c_str(), "Уведомление", MB_OK | MB_ICONINFORMATION);

					return 0;
				}
				MessageBox(NULL, "Укажите файл для шифрования и публичный ключ!", "Ошибка!", MB_OK | MB_ICONERROR);
			}
			else if (LOWORD(wparam) == DECRYPT_BUTTON)
			{
				if ((in_decr.size() > 3) && (key.size() > 3))
				{
					string buff;
					out = in_decr;

					out.pop_back();
					out.pop_back();
					out.pop_back();
					out.pop_back();

					int sz = out.size();

					if (sz > 8)
					{
						for (int i = 8; i >= 1; i--)
						{
							buff.push_back(out[sz - i]);
						}

						if (buff == "-crypted")
						{

							for (int i = 8; i >= 1; i--)
							{
								out.pop_back();
							}
						}
					}

					out = out + "-decrypted.txt";
					rsa::decryptTxtFile(in_decr, out, key);

					string textMsg;
					textMsg = "Расшифрованный файл: \n" + out;
					MessageBox(NULL, textMsg.c_str(), "Уведомление", MB_OK | MB_ICONINFORMATION);

					return 0;
				}
				MessageBox(NULL, "Укажите файл для расшифрования и приватный ключ!", "Ошибка!", MB_OK | MB_ICONERROR);
			}
			else if (LOWORD(wparam) == GENERATE_BUTTON)
			{
				char Name[MAX_PATH];

				GetModuleFileNameA(NULL, Name, MAX_PATH);
				pb_key = Name;
				string buff;

				int lastSlash = pb_key.find_last_of('\\');
				for (int i = 0; i <= lastSlash; i++)
				{
					buff.push_back(pb_key[i]);
				}
				pb_key = buff + "pb_key.txt";
				pr_key = buff + "pr_key.txt";
				rsa::saveKeys(pb_key, pr_key);
				string textMsg;
				textMsg = "Публичный ключ находится по пути: \n" + pb_key + "\n\nПриватный ключ находится по пути: \n" + pr_key;
				MessageBox(NULL, textMsg.c_str(), "Уведомление", MB_OK | MB_ICONINFORMATION);

			}
			else if (LOWORD(wparam) == CHOOSE_ENCR_BUTTON)
			{
				strcat(filter, "TXT Files");

				int index = strlen(filter) + 1;

				filter[index++] = '*';
				filter[index++] = '.';
				filter[index++] = 't';
				filter[index++] = 'x';
				filter[index++] = 't';

				FillOpenParams(open_params, hwnd, filter, file_name);
				GetOpenFileName(&open_params);
				in_encr = file_name;
				SendMessage(EncryptTextField, WM_SETTEXT, 0, (LPARAM)in_encr.c_str()); //считали
			}
			else if (LOWORD(wparam) == CHOOSE_KEY_BUTTON)
			{
				strcat(filter, "TXT Files");

				int index = strlen(filter) + 1;

				filter[index++] = '*';
				filter[index++] = '.';
				filter[index++] = 't';
				filter[index++] = 'x';
				filter[index++] = 't';

				FillOpenParams(open_params, hwnd, filter, file_name);
				key = file_name;
				GetOpenFileName(&open_params);
				SendMessage(KeyTextField, WM_SETTEXT, 0, (LPARAM)file_name); //считали
				key = file_name;
			}
			else if (LOWORD(wparam) == CHOOSE_DECR_BUTTON)
			{
				strcat(filter, "TXT Files");

				int index = strlen(filter) + 1;

				filter[index++] = '*';
				filter[index++] = '.';
				filter[index++] = 't';
				filter[index++] = 'x';
				filter[index++] = 't';

				FillOpenParams(open_params, hwnd, filter, file_name);
				GetOpenFileName(&open_params);
				in_decr = file_name;
				SendMessage(DecryptTextField, WM_SETTEXT, 0, (LPARAM)file_name); //считали			}
			}

			// If the user selected "Quit" from the menu
			if (LOWORD(wparam) == IDHELP)
			{
				MessageBox(NULL, (LPCSTR)"С помощью кнопки <Сгенерировать> сгенерируйте пару ключей: публичный и приватный. Далее при помощи публичного ключа можно зашифровать файл, а с помощью приватного - расшифровать.", (LPCSTR)"Помощь", MB_OK | MB_ICONQUESTION);
			}
			//SendMessage(hwnd, WM_CLOSE, 0, 0); // We'll do as they ask and close the program


											   // If the user selected "Open" from the menu
			if (LOWORD(wparam) == VS_VERSION_INFO)
			{
				DisplayResourceNAMessageBox();
			}

			break;

	case WM_DROPFILES:
		SendMessage(ChooseKeyButton, WM_DROPFILES, wparam, 0);
		// Call our function we created to display all the files.
		// We pass the wParam because it's the HDROP handle.
		HandleFiles(wparam);
		break;
	case WM_DESTROY:

		PostQuitMessage(0);
		break;

	default:

		return DefWindowProc(hwnd, message, wparam, lparam);

		}

	}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
	int nItemCount;
	int nSelected;
	int *nIndexes;
	BOOL bFlag;
	WCHAR *pszFile;
	WCHAR *handle;
	WCHAR *token;
	Image *imgCurrent;
	Image out;

	switch (iMessage)
	{
		case WM_CREATE:
			HANDLE hToken;

			viewer.changeCaption(L"Preview");

			//Create Controls
			hListLayer = CreateWindow(L"ListBox", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_EXTENDEDSEL | LBS_HASSTRINGS | LBS_NOTIFY | LBS_MULTIPLESEL | LBS_NOINTEGRALHEIGHT, 0, 80, 240, 420, hWnd, (HMENU)ID_LAYER_LIST, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
			hButtonStart = CreateWindow(L"Button", L"Start", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 80, 40, hWnd, (HMENU)ID_START_BUTTON, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
			hButtonSave = CreateWindow(L"Button", L"Save Selected in merged file", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_MULTILINE, 80, 0, 80, 40, hWnd, (HMENU)ID_SAVE_BUTTON, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
			hButtonSaveAll = CreateWindow(L"Button", L"Save All in individual file", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_MULTILINE, 160, 0, 80, 40, hWnd, (HMENU)ID_SAVE_ALL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
			hButtonResetAll = CreateWindow(L"Button", L"Erase All", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_MULTILINE, 0, 40, 80, 40, hWnd, (HMENU)ID_RESET_ALL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
			hButtonResetSelected = CreateWindow(L"Button", L"Erase Selected", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_MULTILINE, 80, 40, 80, 40, hWnd, (HMENU)ID_RESET_SEL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
			hButtonResetUnselected = CreateWindow(L"Button", L"Erase Unelected", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_MULTILINE, 160, 40, 80, 40, hWnd, (HMENU)ID_RESET_UNSEL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

			hFont = CreateFont(16, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 3, 2, 1, FF_ROMAN, L"Segoe UI");

			SendMessage(hListLayer, WM_SETFONT, (WPARAM)hFont, TRUE);
			SendMessage(hButtonStart, WM_SETFONT, (WPARAM)hFont, TRUE);
			SendMessage(hButtonSave, WM_SETFONT, (WPARAM)hFont, TRUE);
			SendMessage(hButtonSaveAll, WM_SETFONT, (WPARAM)hFont, TRUE);
			SendMessage(hButtonResetAll, WM_SETFONT, (WPARAM)hFont, TRUE);
			SendMessage(hButtonResetSelected, WM_SETFONT, (WPARAM)hFont, TRUE);
			SendMessage(hButtonResetUnselected, WM_SETFONT, (WPARAM)hFont, TRUE);

			//Create Events
			hAttachSucceeded = CreateEvent(NULL, TRUE, FALSE, NULL);
			hDebugEnd = CreateEvent(NULL, TRUE, FALSE, NULL);
			hDebugInit = CreateEvent(NULL, TRUE, FALSE, NULL);

			//Adjust Privileges
			if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
			{
				if (SetPrivilege(hToken, SE_DEBUG_NAME, TRUE))
					return 0;
				else
					MessageBox(hWnd, L"Fail to get debug privilege!!", L"Error", MB_OK | MB_ICONERROR);
			}
			else
				MessageBox(hWnd, L"Fail to get process token!!", L"Error", MB_OK | MB_ICONERROR);

			SendMessage(hWnd, WM_DESTROY, 0, 0);

			return 0;
		case WM_ACTIVATE:
			if (wParam == WA_CLICKACTIVE)
			{
				viewer.foreground();
				SetForegroundWindow(hWnd);
				SetFocus(hListLayer);
			}
			return 0;
		case WM_COMMAND:
			switch (LOWORD(wParam))
			{
				case ID_START_BUTTON:
					if (!bStarted)
					{
						hAokanaWnd = FindAokana(&dwThreadID, &dwProcessID);

						if (dwThreadID != 0)
						{
							hDebugThread = CreateThread(NULL, 0, DebugThread, NULL, 0, NULL);

							WaitForSingleObject(hDebugInit, INFINITE);
							if (WaitForSingleObject(hAttachSucceeded, 0) != WAIT_OBJECT_0)
							{
								SetEvent(hDebugEnd);
								MessageBox(hWnd, L"Fail to attach process!!", L"Error", MB_OK | MB_ICONERROR);

								break;
							}

							SendMessage(hButtonStart, WM_SETTEXT, 0, (LPARAM)L"Stop");
							bStarted = TRUE;
						}
					}
					else
					{
						SetEvent(hDebugEnd);
						WaitForSingleObject(hDebugThread, INFINITE);

						ResetEvent(hDebugEnd);
						ResetEvent(hDebugInit);
						ResetEvent(hAttachSucceeded);
						CloseHandle(hDebugThread);

						SendMessage(hButtonStart, WM_SETTEXT, 0, (LPARAM)L"Start");
						bStarted = FALSE;
					}
					break;
				case ID_SAVE_BUTTON:
					nItemCount = SendMessage(hListLayer, LB_GETCOUNT, 0, 0);
					nSelected = SendMessage(hListLayer, LB_GETSELCOUNT, 0, 0);

					if (nSelected > 0)
					{
						nIndexes = (int *)calloc(nSelected, sizeof(int));

						SendMessage(hListLayer, LB_GETSELITEMS, nSelected, (LPARAM)nIndexes);

						memset(&out, 0, sizeof(Image));

						for (int i = nSelected - 1; i >= 0; i--)
						{
							imgCurrent = (Image *)SendMessage(hListLayer, LB_GETITEMDATA, nIndexes[i], 0);

							if (imgCurrent == NULL)
								continue;

							if (i == nSelected - 1)
							{
								out.data = (PIXEL *)calloc(imgCurrent->width * imgCurrent->height, sizeof(PIXEL));
								out.width = imgCurrent->width;
								out.height = imgCurrent->height;
							}

							if (imgCurrent->width == out.width && imgCurrent->height == out.height)
								pixeloverlay(out.width, out.height, out.data, imgCurrent->data, out.data);
						}

						saveDialog(hWnd, out);

						free(nIndexes);
						free(out.data);
					}
					break;
				case ID_SAVE_ALL:
					nItemCount = SendMessage(hListLayer, LB_GETCOUNT, 0, 0);

					if (nItemCount > 0)
					{
						if (selectFolder(hWnd, pszFolder))
						{
							pszFile = (WCHAR *)calloc(256, sizeof(WCHAR));

							for (int i = nItemCount - 1; i >= 0; i--)
							{
								imgCurrent = (Image *)SendMessage(hListLayer, LB_GETITEMDATA, i, 0);
								SendMessage(hListLayer, LB_GETTEXT, i, (LPARAM)pszFile);

								token = wcstok_s(pszFile, L" ", &handle);
								token = wcstok_s(NULL, L" ", &handle);

								if (pszFolder[wcslen(pszFolder) - 1] != '\\')
									wcscat_s(pszFolder, L"\\");

								nSelected = wcslen(pszFolder);	//Position of '\' + 1

								wcscat_s(pszFolder, token);
								wcscat_s(pszFolder, L".png");
								saveImage(*imgCurrent, pszFolder);

								pszFolder[nSelected] = 0;
							}

							free(pszFile);
						}
					}
					break;
				case ID_LAYER_LIST:
					if (HIWORD(wParam) == LBN_SELCHANGE)
					{
						nItemCount = SendMessage(hListLayer, LB_GETCOUNT, 0, 0);
						nSelected = SendMessage(hListLayer, LB_GETSELCOUNT, 0, 0);

						if (nSelected > 0)
						{
							nIndexes = (int *)calloc(nSelected, sizeof(int));

							SendMessage(hListLayer, LB_GETSELITEMS, nSelected, (LPARAM)nIndexes);

							for (int i = nSelected - 1; i >= 0; i--)
							{
								imgCurrent = (Image *)SendMessage(hListLayer, LB_GETITEMDATA, nIndexes[i], 0);

								if (imgCurrent == NULL)
									continue;

								if (i == nSelected - 1)
									viewer.create(imgCurrent->width, imgCurrent->height);

								if (imgCurrent->width == viewer.getwidth() && imgCurrent->height == viewer.getheight())
									viewer.overlay(imgCurrent->data);
							}

							viewer.show();

							free(nIndexes);
						}
						else
							viewer.hide();
					}
					break;
				case ID_RESET_ALL:
					nItemCount = SendMessage(hListLayer, LB_GETCOUNT, 0, 0);
					for (int i = 0; i < nItemCount; i++)
					{
						imgCurrent = (Image *)SendMessage(hListLayer, LB_GETITEMDATA, i, 0);
						free(imgCurrent->data);
						free(imgCurrent);
					}
					SendMessage(hListLayer, LB_RESETCONTENT, 0, 0);
					viewer.hide();
					break;
				case ID_RESET_SEL:
					nItemCount = SendMessage(hListLayer, LB_GETCOUNT, 0, 0);
					nSelected = SendMessage(hListLayer, LB_GETSELCOUNT, 0, 0);

					if (nSelected > 0)
					{
						nIndexes = (int *)calloc(nSelected, sizeof(int));

						SendMessage(hListLayer, LB_GETSELITEMS, nSelected, (LPARAM)nIndexes);

						for (int i = nSelected - 1; i >= 0; i--)
						{
							imgCurrent = (Image *)SendMessage(hListLayer, LB_GETITEMDATA, nIndexes[i], 0);
							free(imgCurrent->data);
							free(imgCurrent);
							SendMessage(hListLayer, LB_DELETESTRING, nIndexes[i], 0);
						}

						free(nIndexes);
						viewer.hide();
					}
					break;
				case ID_RESET_UNSEL:
					nItemCount = SendMessage(hListLayer, LB_GETCOUNT, 0, 0);
					nSelected = SendMessage(hListLayer, LB_GETSELCOUNT, 0, 0);

					if (nSelected > 0)
					{
						nIndexes = (int *)calloc(nSelected, sizeof(int));

						SendMessage(hListLayer, LB_GETSELITEMS, nSelected, (LPARAM)nIndexes);

						for (int i = nItemCount - 1; i >= 0; i--)
						{
							bFlag = FALSE;

							for (int j = nSelected - 1; j >= 0; j--)
								if (i == nIndexes[j])
									bFlag = TRUE;

							if (!bFlag)
							{
								imgCurrent = (Image *)SendMessage(hListLayer, LB_GETITEMDATA, i, 0);
								free(imgCurrent->data);
								free(imgCurrent);
								SendMessage(hListLayer, LB_DELETESTRING, i, 0);
							}
						}

						free(nIndexes);
					}
					break;
			}
			return 0;
		case WM_DESTROY:
			if (bStarted)
				SendMessage(hWnd, WM_COMMAND, ID_START_BUTTON, 0);

			SendMessage(hWnd, WM_COMMAND, ID_RESET_ALL, 0);

			CloseHandle(hAttachSucceeded);
			CloseHandle(hDebugEnd);

			DeleteObject(hFont);

			PostQuitMessage(0);
			return 0;
	}

	return DefWindowProc(hWnd, iMessage, wParam, lParam);
}
Exemple #5
0
int PASCAL
WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR CmdLine, int nCmdShow)
{
    MSG       msg;                      /* MSG structure to pass to windows proc */
    WNDCLASS  wndclass;
    char      *AppName;                 /* Name for the window */

    cbErrHandling (PRINTALL, STOPALL);  /* Set library's error handling */

    CmdLine = NULL;                     /* Not used */
    AppName = "WINCDEMO";               /* The name of this application */
    if(!hPrevInstance)
        {
        wndclass.style      = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc= MainMessageHandler;
        wndclass.cbClsExtra = 0;
        wndclass.cbWndExtra = 0;
        wndclass.hInstance  = hInstance;
        wndclass.hIcon      = LoadIcon (hInstance, AppName);
        wndclass.hCursor    = LoadCursor (NULL, IDC_ARROW);
        wndclass.hbrBackground  = GetStockObject (WHITE_BRUSH);
        wndclass.lpszMenuName   = AppName;
        wndclass.lpszClassName  = AppName;
        RegisterClass (&wndclass);
        }

    /* create application's Main window                                    */
    hWndMain = CreateWindow (AppName,                  /* Window class name          */
                             "AInScan Foreground",
                             WS_OVERLAPPEDWINDOW,
                             CW_USEDEFAULT,           /* Use default X, Y            */
                             CW_USEDEFAULT,           /* Use default X, Y            */
                             GetSystemMetrics(SM_CXSIZE) * 12,   /* x - fit text      */
                             GetSystemMetrics(SM_CYSIZE) * 20,  /* y - fit text      */
                             NULL,                    /* Parent window's handle      */
                             NULL,                    /* Default to Class Menu       */
                             hInstance,               /* Instance of window          */
                             NULL);                   /* Create struct for WM_CREATE */


    if (hWndMain == NULL)
        {
        MessageBox(NULL, "Could not create window in WinMain", NULL, MB_ICONEXCLAMATION);
        return (1);
        }

    ShowWindow(hWndMain, nCmdShow);     /* Display main window      */
    UpdateWindow(hWndMain);

    /* Start a 500ms timer to update display */
//    if(!SetTimer(hWndMain, TIMER_NUM, 500, NULL))
//        {
//        MessageBox(NULL, "Error starting Windows timer", NULL, MB_OK |
//                   MB_ICONEXCLAMATION);
 //       return (1);
 //       }                          
        
    while(GetMessage(&msg, NULL, 0, 0)) /* Main message loop */
        {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
        }

    UnregisterClass (AppName, hInstance);
    return (msg.wParam);
} 
Exemple #6
0
BOOL InitializeApp(LPSTR lpszCommandLine)
{
    WNDCLASS wc;
    int cyExecStart, cxExecStart;
    USHORT TitleLen, cbCopy;
    HWND  hwndFax;


    // Remove Real Mode Segment Address

    wc.style            = 0;
    wc.lpfnWndProc      = WndProc;
    wc.cbClsExtra       = 0;
    wc.cbWndExtra       = 0;
    wc.hInstance        = hAppInstance;
    wc.hIcon            = LoadIcon(hAppInstance, MAKEINTRESOURCE(ID_WOWEXEC_ICON));
    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground    = GetStockObject(WHITE_BRUSH);
    wc.lpszClassName    = "WOWExecClass";
#ifdef DEBUG
    wc.lpszMenuName     = "MainMenu";
#else
    wc.lpszMenuName     = NULL;
#endif

    if (!RegisterClass(&wc)) {
        OutputDebugString("WOWEXEC: RegisterClass failed\n");
        return FALSE;
    }

    /*
     * Guess size for now.
     */
    cyExecStart = GetSystemMetrics(SM_CYMENU) * 6;
    cxExecStart = GetSystemMetrics(SM_CXSCREEN) / 2;

    /* Load these strings now.  If we need them later, we won't be able to load
     * them at that time.
     */
    LoadString(hAppInstance, IDS_OOMEXITTITLE, szOOMExitTitle, sizeof(szOOMExitTitle));
    LoadString(hAppInstance, IDS_OOMEXITMSG, szOOMExitMsg, sizeof(szOOMExitMsg));
    LoadString(hAppInstance, IDS_APPTITLE, szAppTitleBuffer, sizeof(szAppTitleBuffer));

    ghwndMain = CreateWindow("WOWExecClass", lpszAppTitle,
            WS_OVERLAPPED | WS_CAPTION | WS_BORDER | WS_THICKFRAME |
            WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_CLIPCHILDREN |
            WS_SYSMENU,
            30, 30, cxExecStart, cyExecStart,
            NULL, NULL, hAppInstance, NULL);

    if (ghwndMain == NULL ) {
#ifdef DEBUG
        OutputDebugString("WOWEXEC: ghwndMain Null\n");
#endif
        return FALSE;
    }

    hwndFax = FaxInit(hAppInstance);

    //
    // Give our window handle to BaseSrv, which will post WM_WOWEXECSTARTAPP
    // messages when we have commands to pick up.  The return value tells
    // us if we are the shared WOW VDM or not (a seperate WOW VDM).
    // We also pick up the ShowWindow parameter (SW_SHOW, SW_MINIMIZED, etc)
    // for the first WOW app here.  Subsequent ones we get from BaseSrv.
    //

         //
         // gwFirstCmdShow is no longer used, and is available.
         //

    gfSharedWOW = WOWRegisterShellWindowHandle(ghwndMain,
                                               &gwFirstCmdShow,
                                               hwndFax
                                               );



    //
    // If this isn't the shared WOW, tell the kernel to exit when the
    // last app (except WowExec) exits.
    //

    if (!gfSharedWOW) {
        WowSetExitOnLastApp(TRUE);
    }

      /* Remember the original directory. */
    GetCurrentDirectory(NULL, szOriginalDirectory);
    GetWindowsDirectory(szWindowsDirectory, MAXITEMPATHLEN+1);

#ifdef DEBUG

    ShowWindow(ghwndMain, SW_MINIMIZE);

    //
    // If this is the shared WOW, change the app title string to
    // reflect this and change the window title.
    //

    if (gfSharedWOW) {

        LoadString(hAppInstance, IDS_SHAREDAPPTITLE, szAppTitleBuffer, sizeof(szAppTitleBuffer));

    }

    SetWindowText(ghwndMain, lpszAppTitle);
    UpdateWindow(ghwndMain);

#endif

    return TRUE;
}
Exemple #7
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow) {

	WNDCLASSEX wcex;
	HMENU menu, popupMenu;

	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = hInstance;
	wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
	wcex.hCursor = LoadCursor(hInstance, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wcex.lpszMenuName = NULL;
	wcex.lpszClassName = szWindowClass;
	wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));

	if (!RegisterClassEx(&wcex))
	{
		MessageBox(NULL,
			_T("Call to RegisterClassEx failed!"),
			_T("Win32 Guided Tour"),
			NULL);

		return 1;
	}

	hInst = hInstance; // Store instance handle in our global variable

	// The parameters to CreateWindow explained:
	// szWindowClass: the name of the application
	// szTitle: the text that appears in the title bar
	// WS_SYSMENU: the type of window to create
	// CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
	// 500, 100: initial size (width, length)
	// NULL: the parent of this window
	// TODO: // NULL: this application does not have a menu bar
	// hInstance: the first parameter from WinMain
	// NULL: not used in this application
	hWnd = CreateWindow(
		szWindowClass,
		szTitle,
		WS_SYSMENU,
		CW_USEDEFAULT, CW_USEDEFAULT,
		WindowWidth, WindowHeight,
		NULL,
		NULL,
		hInstance,
		NULL
		);

	if (!hWnd)
	{
		MessageBox(NULL,
			_T("Call to CreateWindow failed!"),
			_T("Win32 Guided Tour"),
			NULL);

		return 1;
	}

	hButtonRefresh = CreateWindow(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, 0, 0, 32, 32, hWnd, (HMENU)IDC_BUTTON_REFRESH, hInst, NULL);
	hButtonClear = CreateWindow(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, 0, 32, 32, 32, hWnd, (HMENU)IDC_BUTTON_CLEAR, hInst, NULL);

	// The parameters to ShowWindow explained:
	// hWnd: the value returned from CreateWindow
	// nCmdShow: the fourth parameter from WinMain
	ShowWindow(hWnd,
		nCmdShow);
	UpdateWindow(hWnd);

	// Main message loop:
	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return (int)msg.wParam;
}
// エントリポイント
int WINAPI _tWinMain( HINSTANCE hInst, HINSTANCE, LPTSTR, int )
{
	LARGE_INTEGER			nNowTime, nLastTime;		// 現在とひとつ前の時刻
	LARGE_INTEGER			nTimeFreq;					// 時間単位

    // 画面サイズ
    g_nClientWidth  = VIEW_WIDTH;						// 幅
    g_nClientHeight = VIEW_HEIGHT;						// 高さ

	// Register the window class
    WNDCLASSEX wc = { sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
                      GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
                      _T( "D3D Sample" ), NULL };
    RegisterClassEx( &wc );

	RECT rcRect;
	SetRect( &rcRect, 0, 0, g_nClientWidth, g_nClientHeight );
	AdjustWindowRect( &rcRect, WS_OVERLAPPEDWINDOW, FALSE );
    g_hWnd = CreateWindow( _T( "D3D Sample" ), _T( "Movement_1_1b" ),
						   WS_OVERLAPPEDWINDOW, 100, 20, rcRect.right - rcRect.left, rcRect.bottom - rcRect.top,
						   GetDesktopWindow(), NULL, wc.hInstance, NULL );

    // Initialize Direct3D
    if( SUCCEEDED( InitD3D() ) && SUCCEEDED( MakeShaders() ) )
    {
        // Create the shaders
        if( SUCCEEDED( InitDrawModes() ) )
        {
			if ( SUCCEEDED( InitGeometry() ) ) {					// ジオメトリ作成

				// Show the window
				ShowWindow( g_hWnd, SW_SHOWDEFAULT );
				UpdateWindow( g_hWnd );

				InitCharacter();									// キャラクタ初期化
				
				QueryPerformanceFrequency( &nTimeFreq );			// 時間単位
				QueryPerformanceCounter( &nLastTime );				// 1フレーム前時刻初期化

				// Enter the message loop
				MSG msg;
				ZeroMemory( &msg, sizeof( msg ) );
				while( msg.message != WM_QUIT )
				{
					Render();
					MoveCharacter();
					do {
						if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
						{
							TranslateMessage( &msg );
							DispatchMessage( &msg );
						}
						QueryPerformanceCounter( &nNowTime );
					} while( ( ( nNowTime.QuadPart - nLastTime.QuadPart ) < ( nTimeFreq.QuadPart / 90 ) ) &&
							 ( msg.message != WM_QUIT ) );
					while( ( ( nNowTime.QuadPart - nLastTime.QuadPart ) < ( nTimeFreq.QuadPart / 60 ) ) &&
						   ( msg.message != WM_QUIT ) )
					{
						QueryPerformanceCounter( &nNowTime );
					}
					nLastTime = nNowTime;
					g_pSwapChain->Present( 0, 0 );					// 表示
				}
			}
        }
    }

    // Clean up everything and exit the app
    Cleanup();
    UnregisterClass( _T( "D3D Sample" ), wc.hInstance );
    return 0;
}
Exemple #9
0
int WINAPI WinMain(	HINSTANCE hinstance,
					HINSTANCE hprevinstance,
					LPSTR lpcmdline,
					int ncmdshow)
{
// this is the winmain function

WNDCLASS winclass;	// this will hold the class we create
HWND	 hwnd;		// generic window handle
MSG		 msg;		// generic message
//HDC      hdc;       // generic dc
//PAINTSTRUCT ps;     // generic paintstruct

// first fill in the window class stucture
winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                          CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc	= WindowProc;
winclass.cbClsExtra		= 0;
winclass.cbWndExtra		= 0;
winclass.hInstance		= hinstance;
winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName	= NULL; 
winclass.lpszClassName	= WINDOW_CLASS_NAME;

// register the window class
if (!RegisterClass(&winclass))
	return(0);

// create the window, note the test to see if WINDOWED_APP is
// true to select the appropriate window flags
if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
						  WINDOW_TITLE,	 // title
						  (WINDOWED_APP ? (WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION) : (WS_POPUP | WS_VISIBLE)),
					 	  0,0,	   // x,y
						  WINDOW_WIDTH,  // width
                          WINDOW_HEIGHT, // height
						  NULL,	   // handle to parent 
						  NULL,	   // handle to menu
						  hinstance,// instance
						  NULL)))	// creation parms
return(0);

// save the window handle and instance in a global
main_window_handle = hwnd;
main_instance      = hinstance;

// resize the window so that client is really width x height
if (WINDOWED_APP)
{
// now resize the window, so the client area is the actual size requested
// since there may be borders and controls if this is going to be a windowed app
// if the app is not windowed then it won't matter
RECT window_rect = {0,0,WINDOW_WIDTH-1,WINDOW_HEIGHT-1};

// make the call to adjust window_rect
AdjustWindowRectEx(&window_rect,
     GetWindowStyle(main_window_handle),
     GetMenu(main_window_handle) != NULL,
     GetWindowExStyle(main_window_handle));

// save the global client offsets, they are needed in DDraw_Flip()
window_client_x0 = -window_rect.left;
window_client_y0 = -window_rect.top;

// now resize the window with a call to MoveWindow()
MoveWindow(main_window_handle,
           0, // x position
           0, // y position
           window_rect.right - window_rect.left, // width
           window_rect.bottom - window_rect.top, // height
           FALSE);

// show the window, so there's no garbage on first render
ShowWindow(main_window_handle, SW_SHOW);
} // end if windowed

// perform all game console specific initialization
Game_Init();

// disable CTRL-ALT_DEL, ALT_TAB, comment this line out 
// if it causes your system to crash
SystemParametersInfo(SPI_SCREENSAVERRUNNING, TRUE, NULL, 0);

// enter main event loop
while(1)
	{
	if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{ 
		// test if this is a quit
        if (msg.message == WM_QUIT)
           break;
	
		// translate any accelerator keys
		TranslateMessage(&msg);

		// send the message to the window proc
		DispatchMessage(&msg);
		} // end if
    
    // main game processing goes here
    Game_Main();

	} // end while

// shutdown game and release all resources
Game_Shutdown();

// enable CTRL-ALT_DEL, ALT_TAB, comment this line out 
// if it causes your system to crash
SystemParametersInfo(SPI_SCREENSAVERRUNNING, FALSE, NULL, 0);

// return to Windows like this
return(msg.wParam);

} // end WinMain
Exemple #10
0
HWND CreateCancelDialog(void)
{
	HWND hwndButton,dlgHdl;

	WORD *p, *pdlgtemplate,baseunitX,baseunitY;
	int nchar;
	int scrnWidth,scrnHeight;
	int buttonX, buttonY, buttonWidth, buttonHeight;
	int textX, textY, textWidth, textHeight;
	DWORD lStyle,baseunits;
	HDC screen;
	LOGFONT lf;

	/* allocate some memory to play with  */
	pdlgtemplate = p = (PWORD) rmalloc (1000);

	screen = CreateDC ("DISPLAY", NULL, NULL, NULL);
	scrnWidth  = GetDeviceCaps (screen, HORZRES);
	scrnHeight = GetDeviceCaps (screen, VERTRES);
	DeleteDC (screen);
	baseunits = GetDialogBaseUnits();

	/* start to fill in the dlgtemplate information.  addressing by WORDs */
	lStyle = WS_CAPTION | DS_MODALFRAME | WS_SYSMENU;

	baseunitX=LOWORD(baseunits);
	baseunitY=HIWORD(baseunits);

	*p++ = LOWORD (lStyle);
	*p++ = HIWORD (lStyle);
	*p++ = 0;		/* LOWORD (lExtendedStyle) */
	*p++ = 0;		/* HIWORD (lExtendedStyle) */
	*p++ = 0;		/* NumberOfItems */
	*p++ = ((scrnWidth*4)/3)/baseunitX;		// x
	*p++ = ((scrnHeight*8)/3)/baseunitY;	// y
	*p++ = DIALOG_WIDTH;	/* cx */
	*p++ = DIALOG_HEIGHT;	/* cy */
	*p++ = 0;		/* Menu */
	*p++ = 0;		/* Class */

	/* copy the title of the dialog */
	nchar = nCopyAnsiToWideChar (p, (char *) "Printing in Progress");
	p += nchar;

	dlgHdl = CreateDialogIndirectParam (ghInst, (LPDLGTEMPLATE) pdlgtemplate, ghMainWindow,
										(DLGPROC) PrintDlgProc, (LPARAM) 0);

	rfree(pdlgtemplate);

	// Add a text field
	textWidth = 19*baseunitX;
	textHeight = baseunitY;
	textX =    (((DIALOG_WIDTH*baseunitX)/4) - textWidth)
		       / 2;
	textY =    (((DIALOG_HEIGHT*baseunitY)/8) - textHeight)
			   / 4;
	hwndText = CreateWindow ("static", "",WS_VISIBLE | WS_CHILD | SS_CENTER,
									textX, textY, textWidth, textHeight,
									dlgHdl, (HMENU) 0, ghInst, 0);


	// Add a Cancel button:
	buttonWidth = 10*baseunitX;
	buttonHeight = (3*baseunitY)/2;
	buttonX =    (((DIALOG_WIDTH*baseunitX)/4) - buttonWidth)
		       / 2;
	buttonY =  (3 *  (((DIALOG_HEIGHT*baseunitY)/8) - buttonHeight))
			   / 5;
	hwndButton = CreateWindow ("button", "Cancel", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
									buttonX, buttonY, buttonWidth, buttonHeight,
									dlgHdl, (HMENU) 0, ghInst, 0);
	SetLogFontData (&lf,"MS Sans Serif",0,8);
	SendMessage(hwndButton,WM_SETFONT,(WPARAM)CreateFontIndirect (&lf),MAKELPARAM (TRUE,0));
	SendMessage(hwndText,WM_SETFONT,(WPARAM)CreateFontIndirect (&lf),MAKELPARAM (TRUE,0));

	ShowWindow (dlgHdl,SW_SHOWNORMAL);

	return dlgHdl;
}
Exemple #11
0
/*
** Sys_CreateConsole
*/
void Sys_CreateConsole( void )
{
	HDC hDC;
	WNDCLASS wc;
	RECT rect;
	const char *DEDCLASS = "Q3 WinConsole";
	int nHeight;
	int swidth, sheight;
	int DEDSTYLE = WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX;

	memset( &wc, 0, sizeof( wc ) );

	wc.style         = 0;
	wc.lpfnWndProc   = (WNDPROC) ConWndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = g_wv.hInstance;
	wc.hIcon         = LoadIcon( g_wv.hInstance, MAKEINTRESOURCE(IDI_ICON1));
	wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
	wc.lpszMenuName  = 0;
	wc.lpszClassName = DEDCLASS;

	if ( !RegisterClass (&wc) )
		return;

	rect.left = 0;
	rect.right = 540;
	rect.top = 0;
	rect.bottom = 450;
	AdjustWindowRect( &rect, DEDSTYLE, FALSE );

	hDC = GetDC( GetDesktopWindow() );
	swidth = GetDeviceCaps( hDC, HORZRES );
	sheight = GetDeviceCaps( hDC, VERTRES );
	ReleaseDC( GetDesktopWindow(), hDC );

	s_wcd.windowWidth = rect.right - rect.left + 1;
	s_wcd.windowHeight = rect.bottom - rect.top + 1;

	s_wcd.hWnd = CreateWindowEx( 0,
							   DEDCLASS,
							   CONSOLE_WINDOW_TITLE,
							   DEDSTYLE,
							   ( swidth - 600 ) / 2, ( sheight - 450 ) / 2 , rect.right - rect.left + 1, rect.bottom - rect.top + 1,
							   NULL,
							   NULL,
							   g_wv.hInstance,
							   NULL );

	if ( s_wcd.hWnd == NULL )
	{
		return;
	}

	//
	// create fonts
	//
	hDC = GetDC( s_wcd.hWnd );
	nHeight = -MulDiv( 8, GetDeviceCaps( hDC, LOGPIXELSY), 72);

	s_wcd.hfBufferFont = CreateFont( nHeight,
									  0,
									  0,
									  0,
									  FW_LIGHT,
									  0,
									  0,
									  0,
									  DEFAULT_CHARSET,
									  OUT_DEFAULT_PRECIS,
									  CLIP_DEFAULT_PRECIS,
									  DEFAULT_QUALITY,
									  FF_MODERN | FIXED_PITCH,
									  "Courier New" );

	ReleaseDC( s_wcd.hWnd, hDC );

	//
	// create the input line
	//
	s_wcd.hwndInputLine = CreateWindow( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | 
												ES_LEFT | ES_AUTOHSCROLL,
												6, 400, 528, 20,
												s_wcd.hWnd, 
												( HMENU ) INPUT_ID,	// child window ID
												g_wv.hInstance, NULL );

	//
	// create the buttons
	//
	s_wcd.hwndButtonCopy = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												5, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) COPY_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonCopy, WM_SETTEXT, 0, ( LPARAM ) "copy" );

	s_wcd.hwndButtonClear = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												82, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) CLEAR_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonClear, WM_SETTEXT, 0, ( LPARAM ) "clear" );

	s_wcd.hwndButtonQuit = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												462, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) QUIT_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonQuit, WM_SETTEXT, 0, ( LPARAM ) "quit" );


	//
	// create the scrollbuffer
	//
	s_wcd.hwndBuffer = CreateWindow( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER | 
												ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY,
												6, 40, 526, 354,
												s_wcd.hWnd, 
												( HMENU ) EDIT_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndBuffer, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );

	s_wcd.SysInputLineWndProc = ( WNDPROC ) SetWindowLong( s_wcd.hwndInputLine, GWL_WNDPROC, ( long ) InputLineWndProc );
	SendMessage( s_wcd.hwndInputLine, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );

	ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT);
	UpdateWindow( s_wcd.hWnd );
	SetForegroundWindow( s_wcd.hWnd );
	SetFocus( s_wcd.hwndInputLine );

	s_wcd.visLevel = 1;
}
//==============================================================================
// エントリーポイント
//==============================================================================
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	HWND hwnd;
	MSG msg;
	WNDCLASS winc;

	winc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	winc.lpfnWndProc = WndProc;					// ウィンドウプロシージャ
	winc.cbClsExtra = 0;
	winc.cbWndExtra = 0;
	winc.hInstance = hInstance;
	winc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	winc.hCursor = LoadCursor(NULL, IDC_ARROW);
	winc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	winc.lpszMenuName = NULL;
	winc.lpszClassName = CLASS_NAME;

	// ウィンドウクラス登録
	if(RegisterClass(&winc) == false)
	{
		return 1;
	}

	// ウィンドウ作成
	hwnd = CreateWindow(
		CLASS_NAME,
		CLASS_NAME,
		WS_OVERLAPPEDWINDOW | WS_VISIBLE,
		0, 0,
		SCREEN_WIDTH + GetSystemMetrics(SM_CXFRAME) * 2,
		SCREEN_HEIGHT + GetSystemMetrics(SM_CYFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION),
		NULL,
		NULL,
		hInstance,
		NULL);

	if(hwnd == NULL)
	{
		return 1;
	}

	// Vulkan初期化
	if(initVulkan(hInstance, hwnd) == false)
	{
		return 1;
	}

	// ウィンドウ表示
	ShowWindow(hwnd, nCmdShow);

	FPSCounter fpsCounter; // FPSカウンター

	// メッセージループ
	do {
		fpsCounter.beginCount();

		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			// メイン
			Render();
		}

		fpsCounter.endCount();

		std::string windowTitle = std::string(APPLICATION_NAME) + " - " + std::to_string(fpsCounter.getLastFPS()) + " FPS";
		SetWindowText(hwnd, windowTitle.c_str());

	} while(msg.message != WM_QUIT);

	// Vulkan破棄
	destroyVulkan();

	// 登録したクラスを解除
	UnregisterClass(CLASS_NAME, hInstance);

	return 0;
}
Exemple #13
0
//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
	HWND hWnd;
	TCHAR szTitle[MAX_LOADSTRING];		// title bar text
	TCHAR szWindowClass[MAX_LOADSTRING];	// main window class name

	g_hInst = hInstance; // Store instance handle in our global variable


	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); 
	LoadString(hInstance, IDC_WEMAP, szWindowClass, MAX_LOADSTRING);


	if (!MyRegisterClass(hInstance, szWindowClass))
	{
		return FALSE;
	}
	EnumWindows( enum_proc, (LPARAM)"Ѕлокнот" );
	if (!hWnd_navitel)
	{
		FILE * pFileTXT;

		SYSTEMTIME st;
		GetLocalTime(&st);
		pFileTXT = fopen (fname,"a");
		fprintf(pFileTXT, "---> Date: [%02d, %02d, %d]  Time: [%02d:%02d:%02d] " ,st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond);
		fprintf (pFileTXT, " navitel not running - ");


		STARTUPINFO cif;
		ZeroMemory(&cif,sizeof(STARTUPINFO));
		/*LPSHELLEXECUTEINFO lpExecInfo;
		ZeroMemory(&SHExecInfo, sizeof(SHExecInfo));
		
		SHExecInfo.cbSize = sizeof(SHExecInfo);
		SHExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
		SHExecInfo.nShow = SW_SHOWNORMAL;
		SHExecInfo.lpFile = "\\Storage Card\\navi\\navitel.exe";
		if(!ShellExecuteEx(&SHExecInfo)) {
			*/
		if (CreateProcess(L"\\Doc Disk\\igo8\\igo8.exe",NULL,NULL,NULL,FALSE,NULL,NULL,NULL,&cif,&pi_navitel)==TRUE)
		{
			fprintf (pFileTXT, " navitel runned.\n");
		} else
			fprintf (pFileTXT, " navitel run faied.\n");

		fclose (pFileTXT);
	}

	hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

	if (!hWnd)
	{
		return FALSE;
	}
	hWnd_self = hWnd;
/*
	RegisterHotKey(hWnd, 10001, MOD_KEYUP, VK_APP1);
	RegisterHotKey(hWnd, 10002, MOD_KEYUP, VK_APP2);
	RegisterHotKey(hWnd, 10003, MOD_KEYUP, VK_APP3);
	RegisterHotKey(hWnd, 10004, MOD_KEYUP, VK_APP4);
	RegisterHotKey(hWnd, 10005, MOD_KEYUP, VK_APP5);
	RegisterHotKey(hWnd, 10006, MOD_KEYUP, VK_APP6);
*/
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);

	if (g_hWndCommandBar)
	{
		CommandBar_Show(g_hWndCommandBar, TRUE);
	}

	return TRUE;
}
Exemple #14
0
Fichier : de_win.c Projet : 8l/lllm
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                      LPSTR command_line, int nCmdShow)
{
   MSG         msg;
   WNDCLASS    wndclass;
   HANDLE      hAccel;

#  ifdef THREAD_LOCAL_ALLOC
     GC_INIT();  /* Required if GC is built with THREAD_LOCAL_ALLOC     */
                 /* Always safe, but this is used as a GC test.         */
#  endif

   if (!hPrevInstance)
   {
      wndclass.style          = CS_HREDRAW | CS_VREDRAW;
      wndclass.lpfnWndProc    = WndProc;
      wndclass.cbClsExtra     = 0;
      wndclass.cbWndExtra     = DLGWINDOWEXTRA;
      wndclass.hInstance      = hInstance;
      wndclass.hIcon          = LoadIcon (hInstance, szAppName);
      wndclass.hCursor        = LoadCursor (NULL, IDC_ARROW);
      wndclass.hbrBackground  = GetStockObject(WHITE_BRUSH);
      wndclass.lpszMenuName   = TEXT("DE");
      wndclass.lpszClassName  = szAppName;

      if (RegisterClass (&wndclass) == 0) {
          char buf[50];

          sprintf(buf, "RegisterClass: error code: 0x%X",
                  (unsigned)GetLastError());
          de_error(buf);
          return(0);
      }
   }

   /* Empirically, the command line does not include the command name ...
   if (command_line != 0) {
       while (isspace(*command_line)) command_line++;
       while (*command_line != 0 && !isspace(*command_line)) command_line++;
       while (isspace(*command_line)) command_line++;
   } */

   if (command_line == 0 || *command_line == 0) {
        de_error("File name argument required");
        return( 0 );
   } else {
        char *p = command_line;

        while (*p != 0 && !isspace(*(unsigned char *)p))
            p++;
        arg_file_name = CORD_to_char_star(
                            CORD_substr(command_line, 0, p - command_line));
   }

   hwnd = CreateWindow (szAppName,
                        TEXT("Demonstration Editor"),
                        WS_OVERLAPPEDWINDOW | WS_CAPTION, /* Window style */
                        CW_USEDEFAULT, 0, /* default pos. */
                        CW_USEDEFAULT, 0, /* default width, height */
                        NULL,   /* No parent */
                        NULL,   /* Window class menu */
                        hInstance, NULL);
   if (hwnd == NULL) {
        char buf[50];

        sprintf(buf, "CreateWindow: error code: 0x%X",
                (unsigned)GetLastError());
        de_error(buf);
        return(0);
   }

   ShowWindow (hwnd, nCmdShow);

   hAccel = LoadAccelerators( hInstance, szAppName );

   while (GetMessage (&msg, NULL, 0, 0))
   {
      if( !TranslateAccelerator( hwnd, hAccel, &msg ) )
      {
         TranslateMessage (&msg);
         DispatchMessage (&msg);
      }
   }
   return msg.wParam;
}
bool wxGLCanvas::Create(wxWindow *parent,
                        wxWindowID id,
                        const wxPoint& pos,
                        const wxSize& size,
                        long style,
                        const wxString& name,
                        const int *attribList,
                        const wxPalette& palette)
{
    // Create the window first: we will either use it as is or use it to query
    // for multisampling support and recreate it later with another pixel format
    if ( !CreateWindow(parent, id, pos, size, style, name) )
        return false;

    PIXELFORMATDESCRIPTOR pfd;
    const int setupVal = DoSetup(pfd, attribList);
    if ( setupVal == 0 ) // PixelFormat error
        return false;

    if ( setupVal == -1 ) // FSAA requested
    {
        // now that we have a valid OpenGL window, query it for FSAA support
        int pixelFormat;
        {
            wxGLContext ctx(this);
            ctx.SetCurrent(*this);
            pixelFormat = ::ChoosePixelFormatARB(m_hDC, attribList);
        }

        if ( pixelFormat > 0 )
        {
            // from http://msdn.microsoft.com/en-us/library/ms537559(VS.85).aspx:
            //
            //      Setting the pixel format of a window more than once can
            //      lead to significant complications for the Window Manager
            //      and for multithread applications, so it is not allowed. An
            //      application can only set the pixel format of a window one
            //      time. Once a window's pixel format is set, it cannot be
            //      changed.
            //
            // so we need to delete the old window and create the new one

            // destroy Window
            ::ReleaseDC(GetHwnd(), m_hDC);
            m_hDC = 0;

            parent->RemoveChild(this);
            const HWND hwnd = GetHwnd();
            DissociateHandle(); // will do SetHWND(0);
            ::DestroyWindow(hwnd);

            // now recreate with FSAA pixelFormat
            if ( !CreateWindow(parent, id, pos, size, style, name) )
                return false;

            if ( !::SetPixelFormat(m_hDC, pixelFormat, &pfd) )
            {
                wxLogLastError(wxT("SetPixelFormat"));
                return false;
            }
        }
    }

#if wxUSE_PALETTE
    if ( !SetupPalette(palette) )
        return false;
#else // !wxUSE_PALETTE
    wxUnusedVar(palette);
#endif // wxUSE_PALETTE/!wxUSE_PALETTE

    return true;
}
Exemple #16
0
HWND
CreateOpenGLWindow(char* title, int x, int y, int width, int height, 
		   BYTE type, DWORD flags)
{
    int         pf;
    HDC         hDC;
    HWND        hWnd;
    WNDCLASS    wc;
    PIXELFORMATDESCRIPTOR pfd;
    static HINSTANCE hInstance = 0;

    /* only register the window class once - use hInstance as a flag. */
    if (!hInstance) {
	hInstance = GetModuleHandle(NULL);
	wc.style         = CS_OWNDC;
	wc.lpfnWndProc   = (WNDPROC)WindowProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = hInstance;
	wc.hIcon         = LoadIcon(NULL, IDI_WINLOGO);
	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = NULL;
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = "OpenGL";

	if (!RegisterClass(&wc)) {
	    MessageBox(NULL, "RegisterClass() failed:  "
		       "Cannot register window class.", "Error", MB_OK);
	    return NULL;
	}
    }

    hWnd = CreateWindow("OpenGL", title, WS_OVERLAPPEDWINDOW |
			WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
			x, y, width, height, NULL, NULL, hInstance, NULL);

    if (hWnd == NULL) {
	MessageBox(NULL, "CreateWindow() failed:  Cannot create a window.",
		   "Error", MB_OK);
	return NULL;
    }

    hDC = GetDC(hWnd);

    /* there is no guarantee that the contents of the stack that become
       the pfd are zeroed, therefore _make sure_ to clear these bits. */
    memset(&pfd, 0, sizeof(pfd));
    pfd.nSize        = sizeof(pfd);
    pfd.nVersion     = 1;
    pfd.dwFlags      = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | flags;
    pfd.iPixelType   = type;
    pfd.cColorBits   = 32;

    pf = ChoosePixelFormat(hDC, &pfd);
    if (pf == 0) {
	MessageBox(NULL, "ChoosePixelFormat() failed:  "
		   "Cannot find a suitable pixel format.", "Error", MB_OK); 
	return 0;
    } 
 
    if (SetPixelFormat(hDC, pf, &pfd) == FALSE) {
	MessageBox(NULL, "SetPixelFormat() failed:  "
		   "Cannot set format specified.", "Error", MB_OK);
	return 0;
    } 

    DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

    ReleaseDC(hWnd, hDC);

    return hWnd;
}    
Exemple #17
0
static int ZiYuanguanliqiProc(HWND hcwd, int message, WPARAM wParam, LPARAM lParam)
{
	{

		switch (message) {
		case MSG_CREATE:
		{

			char cwd [MAX_PATH + 1];
			loadbk(hcwd);	
#if 1

			CreateWindow(CTRL_STATIC, MSG_TARGET_DIR, WS_VISIBLE | SS_SIMPLE, IDC_STATIC, 10, 2, 120, 25, hcwd, 0);				     	 
			hFile = CreateWindow(CTRL_LISTBOX, "", WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_SORT | LBS_AUTOCHECKBOX, IDC_XZ_FILE, 10, 20, 280, 140, hcwd, 0);			     
			     
#else
			CreateWindow(CTRL_STATIC, "Directory List Box", WS_VISIBLE | SS_SIMPLE, IDC_STATIC, 10, 2, 120, 25, hcwd, 0);			
				 
			hDir = CreateWindow(CTRL_LISTBOX, "", WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_SORT | LBS_NOTIFY, IDC_XZ_DIR, 10, 20, 140, 140, hcwd, 0);

			CreateWindow(CTRL_STATIC, "File List Box", WS_VISIBLE | SS_SIMPLE, IDC_STATIC, 165, 2, 120, 25, hcwd, 0);

			hFile = CreateWindow(CTRL_LISTBOX, "", WS_VISIBLE | WS_VSCROLL | WS_BORDER | LBS_SORT | LBS_AUTOCHECKBOX, IDC_XZ_FILE, 165, 20, 140, 140, hcwd, 0);

			hPath = CreateWindow(CTRL_STATIC, MSG_PATH, WS_VISIBLE | SS_SIMPLE, IDC_XZ_PATH, 10, 150, 315, 0, hcwd, 0);

#endif

			CreateWindow
				 (CTRL_BUTTON, MSG_DELECT, WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP, IDC_XZ_DELETE, 15, 165, 130, 25, hcwd, 0);

//			CreateWindow
//				 (CTRL_BUTTON, MSG_VIEW, WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP, IDC_XZ_VIEW, 15, 185, 130, 25, hcwd, 0);


			CreateWindow
				 (CTRL_BUTTON, MSG_RETURN, WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, IDC_XZ_RETURN, 170, 165, 130, 25, hcwd, 0);

			SetNotificationCallback(hFile, file_notif_proc);
			SetNotificationCallback(hDir, dir_notif_proc);
			//fill_boxes(hcwd, getcwd(cwd, MAX_PATH));
			fill_boxes(hcwd, MSG_TARGET_DIR);			
		}
		break;


		case MSG_CLOSE:
		{
			DestroyMainWindow(hcwd);
			PostQuitMessage(hcwd);
		}
			return 0;

		case MSG_COMMAND:
		{
			switch (wParam) {
			case IDC_XZ_DELETE:    /*刪除指定文件*/
				DeleteFile(hcwd);
				break;

			//case IDC_XZ_VIEW:
			//	View(hcwd);
			case IDC_XZ_RETURN:     /*返回主界面*/
				DestroyMainWindow(hcwd);
				PostQuitMessage(hcwd);
				break;

			}
		}
			return 0;
		}
		return DefaultMainWinProc(hcwd, message, wParam, lParam);
	}
}
Exemple #18
0
void TaskStart ( void *data )
{
	PWINDOWS ptr = GetActiveWindow();
	UBYTE  i;
	char   sCmd[MAX_X];
	WORD   key;
	WORD   index, pos = 0x00;

	data = data;                                           /* Prevent compiler warning                 */

	OS_ENTER_CRITICAL();
	PC_VectSet(0x08, OSTickISR);                           /* Install uC/OS-II's clock tick ISR        */
	PC_SetTickRate(OS_TICKS_PER_SEC);                      /* Reprogram tick rate                      */
	OS_EXIT_CRITICAL();

    PC_DispChar(0, 0, ' ', 0x00);               
	PC_DispStr (8, 16, "Determining  CPU's capacity ...", DISP_FGND_WHITE);
	CreateWindow (0, StartY, MAX_X, EndY, DISP_FGND_WHITE, DISP_BGND_BLUE, "[ Prompt Window ]");
	CreateTaskWindows();
	OSStatInit();                                          /* Initialize uC/OS-II's statistics         */

	for (i = 0; i < N_TASKS; i ++)
	{                                                      /* Create N_TASKS identical tasks           */
		TaskData[i] = '0' + i;                             /* Each task will display its own letter    */
		OSTaskCreate(Task, (void *)&TaskData[i], (void *)&TaskStk[i][TASK_STK_SIZE - 1], i + 1);
	}

	DisplayTitle();

	ClearWindow();
	memset(sCmd, 0x00, MAX_X);
	DisplayPrompt();
	for (;;)
	{
		DisplayStatus();                                   // display status of tasks

		if (PC_GetKey(&key) == TRUE)
		{                                                  /* See if key has been pressed              */
			if (key == 0x1B)
			{                                              /* Yes, see if it's the ESCAPE key          */
				PC_DOSReturn();                            /* Return to DOS                            */
			}
			else if (key == 0x08)                           // backspace
			{
				pos --;
				pos = pos <= 0x00 ? 0x00 : pos;
				sCmd[pos] = '\0';
				PC_DispChar(ptr->cx + pos + strlen(sCmdPrompt), ptr->cy, ' ', ptr->color);
				DisplayCursor(ptr->cx + pos + strlen(sCmdPrompt), ptr->cy);
			}
			else if (key == 0x0d || key == 0x0a)                           // enter
			{
				if (pos)
				{
					index = ParseCommand(sCmd);
					HandleCommand(index);
				}
				memset(sCmd, 0x00, MAX_X);
				pos = 0x00;
				ptr->cy ++;
				if (ptr->cy == ptr->ey - 1)
					ClearWindow();
				DisplayPrompt();
			}
			else if ((key >= '0' && key <= '9') ||
				(key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z'))
			{
				if (pos < MAX_X)
				{
					sCmd[pos] = (char)key;
					PC_DispChar(ptr->cx + pos + strlen(sCmdPrompt), ptr->cy, key, ptr->color);
	                DisplayCursor (ptr->cx + pos + strlen(sCmdPrompt) + 1, ptr->cy);
				}
				pos ++;
			}

		}
		OSTimeDlyHMSM(0, 0, 0, 200);                         /* Wait 200 ms                          */
	}
}
Exemple #19
0
int
WIN_CreateWindow(_THIS, SDL_Window * window)
{
    HWND hwnd, parent = NULL;
    DWORD style = STYLE_BASIC;
    int x, y;
    int w, h;

    if (window->flags & SDL_WINDOW_SKIP_TASKBAR) {
        parent = CreateWindow(SDL_Appname, TEXT(""), STYLE_BASIC, 0, 0, 32, 32, NULL, NULL, SDL_Instance, NULL);
    }

    style |= GetWindowStyle(window);

    /* Figure out what the window area will be */
    WIN_AdjustWindowRectWithStyle(window, style, FALSE, &x, &y, &w, &h, SDL_FALSE);

    hwnd =
        CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, parent, NULL,
                     SDL_Instance, NULL);
    if (!hwnd) {
        return WIN_SetError("Couldn't create window");
    }

    WIN_PumpEvents(_this);

    if (SetupWindowData(_this, window, hwnd, parent, SDL_TRUE) < 0) {
        DestroyWindow(hwnd);
        if (parent) {
            DestroyWindow(parent);
        }
        return -1;
    }

    /* Inform Windows of the frame change so we can respond to WM_NCCALCSIZE */
    SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);

    if (window->flags & SDL_WINDOW_MINIMIZED) {
        ShowWindow(hwnd, SW_SHOWMINNOACTIVE);
    }

    if (!(window->flags & SDL_WINDOW_OPENGL)) {
        return 0;
    }

    /* The rest of this macro mess is for OpenGL or OpenGL ES windows */
#if SDL_VIDEO_OPENGL_ES2
    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
#if SDL_VIDEO_OPENGL_WGL
        && (!_this->gl_data || WIN_GL_UseEGL(_this))
#endif /* SDL_VIDEO_OPENGL_WGL */
    ) {
#if SDL_VIDEO_OPENGL_EGL
        if (WIN_GLES_SetupWindow(_this, window) < 0) {
            WIN_DestroyWindow(_this, window);
            return -1;
        }
        return 0;
#else
        return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
#endif /* SDL_VIDEO_OPENGL_EGL */ 
    }
#endif /* SDL_VIDEO_OPENGL_ES2 */

#if SDL_VIDEO_OPENGL_WGL
    if (WIN_GL_SetupWindow(_this, window) < 0) {
        WIN_DestroyWindow(_this, window);
        return -1;
    }
#else
    return SDL_SetError("Could not create GL window (WGL support not configured)");
#endif

    return 0;
}
Exemple #20
0
/*****************************************************************************
 * Thread: main loop
 *****************************************************************************/
static void *Thread( void *p_data )
{
    MSG message;
    UINT i_key, i_keyMod, i_vk;
    ATOM atom;
    char *psz_hotkey = NULL;

    intf_thread_t *p_intf = p_data;
    intf_sys_t *p_sys = p_intf->p_sys;

    /* Window which receives Hotkeys */
    vlc_mutex_lock( &p_sys->lock );
    p_sys->hotkeyWindow =
        (void*)CreateWindow( _T("STATIC"),           /* name of window class */
                _T("VLC ghk ") _T(VERSION),         /* window title bar text */
                0,                                           /* window style */
                0,                                   /* default X coordinate */
                0,                                   /* default Y coordinate */
                0,                                           /* window width */
                0,                                          /* window height */
                NULL,                                    /* no parent window */
                NULL,                              /* no menu in this window */
                GetModuleHandle(NULL),    /* handle of this program instance */
                NULL );                                 /* sent to WM_CREATE */

    if( p_sys->hotkeyWindow == NULL )
    {
        p_sys->hotkeyWindow = INVALID_HANDLE_VALUE;
        vlc_cond_signal( &p_sys->wait );
        vlc_mutex_unlock( &p_sys->lock );
        return NULL;
    }
    vlc_cond_signal( &p_sys->wait );
    vlc_mutex_unlock( &p_sys->lock );

    SetWindowLongPtr( p_sys->hotkeyWindow, GWLP_WNDPROC,
            (LONG_PTR)WMHOTKEYPROC );
    SetWindowLongPtr( p_sys->hotkeyWindow, GWLP_USERDATA,
            (LONG_PTR)p_intf );

    /* Registering of Hotkeys */
    for( struct hotkey *p_hotkey = p_intf->p_libvlc->p_hotkeys;
            p_hotkey->psz_action != NULL;
            p_hotkey++ )
    {
        if( asprintf( &psz_hotkey, "global-%s", p_hotkey->psz_action ) < 0 )
            break;

        i_key = var_InheritInteger( p_intf, psz_hotkey );

        free( psz_hotkey );

        i_keyMod = 0;
        if( i_key & KEY_MODIFIER_SHIFT ) i_keyMod |= MOD_SHIFT;
        if( i_key & KEY_MODIFIER_ALT ) i_keyMod |= MOD_ALT;
        if( i_key & KEY_MODIFIER_CTRL ) i_keyMod |= MOD_CONTROL;

#define HANDLE( key ) case KEY_##key: i_vk = VK_##key; break
#define HANDLE2( key, key2 ) case KEY_##key: i_vk = VK_##key2; break

#define KEY_SPACE ' '

#ifndef VK_VOLUME_DOWN
#define VK_VOLUME_DOWN          0xAE
#define VK_VOLUME_UP            0xAF
#endif

#ifndef VK_MEDIA_NEXT_TRACK
#define VK_MEDIA_NEXT_TRACK     0xB0
#define VK_MEDIA_PREV_TRACK     0xB1
#define VK_MEDIA_STOP           0xB2
#define VK_MEDIA_PLAY_PAUSE     0xB3
#endif

#ifndef VK_PAGEUP
#define VK_PAGEUP               0x21
#define VK_PAGEDOWN             0x22
#endif

        i_vk = 0;
        switch( i_key & ~KEY_MODIFIER )
        {
            HANDLE( LEFT );
            HANDLE( RIGHT );
            HANDLE( UP );
            HANDLE( DOWN );
            HANDLE( SPACE );
            HANDLE2( ESC, ESCAPE );
            HANDLE2( ENTER, RETURN );
            HANDLE( F1 );
            HANDLE( F2 );
            HANDLE( F3 );
            HANDLE( F4 );
            HANDLE( F5 );
            HANDLE( F6 );
            HANDLE( F7 );
            HANDLE( F8 );
            HANDLE( F9 );
            HANDLE( F10 );
            HANDLE( F11 );
            HANDLE( F12 );
            HANDLE( PAGEUP );
            HANDLE( PAGEDOWN );
            HANDLE( HOME );
            HANDLE( END );
            HANDLE( INSERT );
            HANDLE( DELETE );
            HANDLE( VOLUME_DOWN );
            HANDLE( VOLUME_UP );
            HANDLE( MEDIA_PLAY_PAUSE );
            HANDLE( MEDIA_STOP );
            HANDLE( MEDIA_PREV_TRACK );
            HANDLE( MEDIA_NEXT_TRACK );

            default:
                i_vk = toupper( i_key & ~KEY_MODIFIER );
                break;
        }
        if( !i_vk ) continue;

#undef HANDLE
#undef HANDLE2

        atom = GlobalAddAtomA( p_hotkey->psz_action );
        if( !atom ) continue;

        if( !RegisterHotKey( p_sys->hotkeyWindow, atom, i_keyMod, i_vk ) )
            GlobalDeleteAtom( atom );
    }

    /* Main message loop */
    while( GetMessage( &message, NULL, 0, 0 ) )
        DispatchMessage( &message );

    /* Unregistering of Hotkeys */
    for( struct hotkey *p_hotkey = p_intf->p_libvlc->p_hotkeys;
            p_hotkey->psz_action != NULL;
            p_hotkey++ )
    {
        atom = GlobalFindAtomA( p_hotkey->psz_action );
        if( !atom ) continue;

        if( UnregisterHotKey( p_sys->hotkeyWindow, atom ) )
            GlobalDeleteAtom( atom );
    }

    /* close window */
    vlc_mutex_lock( &p_sys->lock );
    DestroyWindow( p_sys->hotkeyWindow );
    p_sys->hotkeyWindow = NULL;
    vlc_mutex_unlock( &p_sys->lock );

    return NULL;
}
Exemple #21
0
//=====================================================================================
//
//	* Function : RightCreate()
//	* Description 
//		이 함수는 위의 ChildRightProc콜백함수의 WM_CREATE메시지에 대응하는 메시지 처리 함수
//		이다. ChildRight 윈도우가 실행된 후 처음에 초기화되어야 할 변수나 실행되어야 할 함
//		수들을 호출한다.
//
//=====================================================================================
LRESULT RightCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
	//List View를 만든다.
	hList=CreateWindow(WC_LISTVIEW,NULL,WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_REPORT | LVS_NOSORTHEADER,// | LVS_OWNERDRAWFIXED,
		0,0,0,0,hWnd,NULL,g_hInst,NULL);
	ListView_SetExtendedListViewStyle(hList,LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);


	//컬럼만들기
	LVCOLUMN col;
	col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_TEXT;
	col.fmt = LVCFMT_LEFT;
	
	col.cx = 120;
	col.iSubItem = 0;
	col.pszText = TEXT("IP");
	ListView_InsertColumn(hList,0,&col);

	col.cx = 120;
	col.iSubItem = 1;
	col.pszText = TEXT("Mac");
	ListView_InsertColumn(hList,1,&col);

	col.cx = 100;
	col.iSubItem = 2;
	col.pszText = TEXT("Vendor");
	ListView_InsertColumn(hList,2,&col);

	col.cx = 160;
	col.iSubItem = 3;
	col.pszText = TEXT("Time");
	ListView_InsertColumn(hList,3,&col);

	col.cx = 130;
	col.iSubItem = 4;
	col.pszText = TEXT("Host");
	ListView_InsertColumn(hList,4,&col);


	//정보를 입력받기 위한 컨트롤들을 만든다.
	hIp1=CreateWindow(TEXT("static"),TEXT("IP"),WS_CHILD | WS_VISIBLE,
		0,0,0,0,hWnd,(HMENU)-1,g_hInst,NULL);
	hIp2=CreateWindow(TEXT("edit"),NULL,WS_CHILD | WS_VISIBLE | WS_BORDER |
		ES_AUTOHSCROLL,0,0,0,0,hWnd,(HMENU)IDC_IP,g_hInst,NULL);
	hMac1=CreateWindow(TEXT("static"),TEXT("MAC"),WS_CHILD | WS_VISIBLE,
		0,0,0,0,hWnd,(HMENU)-1,g_hInst,NULL);
	hMac2=CreateWindow(TEXT("edit"),NULL,WS_CHILD | WS_VISIBLE | WS_BORDER |  
		ES_AUTOHSCROLL,0,0,0,0,hWnd,(HMENU)IDC_MAC,g_hInst,NULL);

	hVendor1=CreateWindow(TEXT("static"),TEXT("VENDOR"),WS_CHILD | WS_VISIBLE,
		0,0,0,0,hWnd,(HMENU)-1,g_hInst,NULL);
	hVendor2=CreateWindow(TEXT("edit"),NULL,WS_CHILD | WS_VISIBLE | WS_BORDER |
		ES_AUTOHSCROLL,0,0,0,0,hWnd,(HMENU)IDC_VENDOR,g_hInst,NULL);

	hTime1=CreateWindow(TEXT("static"),TEXT("TIME"),WS_CHILD | WS_VISIBLE,
		0,0,0,0,hWnd,(HMENU)-1,g_hInst,NULL);
	hTime2=CreateWindow(TEXT("edit"),NULL,WS_CHILD | WS_VISIBLE | WS_BORDER |
		ES_AUTOHSCROLL,0,0,0,0,hWnd,(HMENU)IDC_TIME,g_hInst,NULL);

	hHost1=CreateWindow(TEXT("static"),TEXT("HOST"),WS_CHILD | WS_VISIBLE,
		0,0,0,0,hWnd,(HMENU)-1,g_hInst,NULL);
	hHost2=CreateWindow(TEXT("edit"),NULL,WS_CHILD | WS_VISIBLE | WS_BORDER |
		ES_AUTOHSCROLL,0,0,0,0,hWnd,(HMENU)IDC_HOST,g_hInst,NULL);

	hMenu3=CreateWindow(TEXT("button"),TEXT("IP검색"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
		0,0,0,0,hWnd,(HMENU)IDC_FIND,g_hInst,NULL);
	hMenu4=CreateWindow(TEXT("button"),TEXT("방어"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
		0,0,0,0,hWnd,(HMENU)IDC_DEF,g_hInst,NULL);
	
	//tab키 더하기 위한 서브클라싱
	g_OldProc = (WNDPROC)GetWindowLongPtr( hIp2, GWLP_WNDPROC );
	SetWindowLongPtr( hIp2, GWLP_WNDPROC, (LONG_PTR)MyEditWindowProc );
	SetWindowLongPtr( hMac2, GWLP_WNDPROC, (LONG_PTR)MyEditWindowProc );
	SetWindowLongPtr( hVendor2, GWLP_WNDPROC, (LONG_PTR)MyEditWindowProc );
	SetWindowLongPtr( hTime2, GWLP_WNDPROC, (LONG_PTR)MyEditWindowProc );
	SetWindowLongPtr( hHost2, GWLP_WNDPROC, (LONG_PTR)MyEditWindowProc );
	return 0;
}
Exemple #22
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_CREATE:
	{
		hWndListOne = CreateWindow(L"listbox", NULL,
			WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER |
			WS_VSCROLL |
			LBS_NOTIFY,
			5, 10, 380, 430,
			hWnd, (HMENU)ID_LISTONE, hInst, NULL);

		hWndListTwo = CreateWindow(L"listbox", NULL,
			WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER |
			WS_VSCROLL |
			LBS_NOTIFY,
			390, 10, 380, 430,
			hWnd, (HMENU)ID_LISTONE, hInst, NULL);

		GetProcess(true);
	}; return 0;
	case WM_COMMAND:
	{
		UINT code = HIWORD(wParam);
		UINT idCtrl = LOWORD(wParam);
		int j = 0;
		switch (idCtrl)
		{
		case ID_HIGH:
			SetPriority(HIGH_PRIORITY_CLASS);
			break;
		case ID_IDLE:
			SetPriority(IDLE_PRIORITY_CLASS);
			break;
		case ID_NORMAL:
			SetPriority(NORMAL_PRIORITY_CLASS);
			break;
		case ID_REALTIME:
			SetPriority(REALTIME_PRIORITY_CLASS);
			break;
		case ID_LISTONE:
			if (code == LBN_DBLCLK)
			{
				SendMessage(hWndListTwo, LB_RESETCONTENT, 0, 0);
				i = SendMessage(hWndListOne, LB_GETCURSEL, 0, 0);
				if(i<=1024&&i>=0)
					PrintModules(twar[i]);
			}
			break;
		}
	}; return 0;
	case WM_CONTEXTMENU:
	{
		HMENU hMenu = CreatePopupMenu();

		AppendMenu(hMenu, MFT_STRING, ID_HIGH, L"HIGH");
		AppendMenu(hMenu, MFT_STRING, ID_IDLE, L"IDLE");
		AppendMenu(hMenu, MFT_STRING, ID_NORMAL, L"NORMAL");
		AppendMenu(hMenu, MFT_STRING, ID_REALTIME, L"REALTIME");

		TrackPopupMenu(hMenu, TPM_RIGHTBUTTON |
			TPM_TOPALIGN |
			TPM_LEFTALIGN,
			LOWORD(lParam),
			HIWORD(lParam), 0, hWnd, NULL);
		DestroyMenu(hMenu);
	}
	break;
	case WM_DESTROY:
	{
		PostQuitMessage(0);
	} break;
	default: return DefWindowProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}
Exemple #23
0
/* initialize the process.  Reads the init files to get the appropriate
 * information. */
BOOL InitInstance(
	HANDLE hInstance,
	int nCmdShow)
{
	HWND hWnd;
	HDC hDC;
	TEXTMETRIC textmetric;
	INT nLineHeight;
    long code, cnt;
	char *reason;
 
	/* remember this, since it is a useful thing for some of the Windows
	 * calls */
	main_inst = hInstance;

	/* create our window */
	hWnd = CreateWindow(
		"AFSDWinClass",
	        "AFSD",
	        WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
	        CW_USEDEFAULT,
	        CW_USEDEFAULT,
	        CW_USEDEFAULT,
	        CW_USEDEFAULT,
	        NULL,
	        NULL,
	        hInstance,
	        NULL
	);

	if (!hWnd)
	        return (FALSE);

	/* lookup text dimensions */
	hDC = GetDC(hWnd);
	GetTextMetrics(hDC, &textmetric);
	nLineHeight = textmetric.tmExternalLeading + textmetric.tmHeight;
	
	main_rect.left   = GetDeviceCaps(hDC, LOGPIXELSX) / 4;   /* 1/4 inch */
	main_rect.right  = GetDeviceCaps(hDC, HORZRES);
	main_rect.top    = GetDeviceCaps(hDC, LOGPIXELSY) / 4;   /* 1/4 inch */
	ReleaseDC(hWnd, hDC);
	main_rect.bottom = main_rect.top + nLineHeight;

	osi_InitPanic(afsd_notifier);

	afsi_start();

        code = afsd_InitCM(&reason);
	if (code != 0)
		osi_panic(reason, __FILE__, __LINE__);

	code = afsd_InitDaemons(&reason);
	if (code != 0)
		osi_panic(reason, __FILE__, __LINE__);

        code = afsd_InitSMB(&reason, MessageBox);

	if (code != 0)
            osi_panic(reason, __FILE__, __LINE__);

	ShowWindow(hWnd, SW_SHOWMINNOACTIVE);
	UpdateWindow(hWnd);
	return (TRUE);
}
Exemple #24
0
int main(int, char**)
{
    // Create application window
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, L"ImGui Example", NULL };
    RegisterClassEx(&wc);
    HWND hwnd = CreateWindow(L"ImGui Example", L"ImGui DirectX11 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);

    // Initialize Direct3D
    if (CreateDeviceD3D(hwnd) < 0)
    {
        CleanupDeviceD3D();
        UnregisterClass(L"ImGui Example", wc.hInstance);
        return 1;
    }

    // Show the window
    ShowWindow(hwnd, SW_SHOWDEFAULT);
    UpdateWindow(hwnd);

    // Setup ImGui binding
    ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext);

    // Load Fonts
    // (see extra_fonts/README.txt for more details)
    //ImGuiIO& io = ImGui::GetIO();
    //io.Fonts->AddFontDefault();
    //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
    //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
    //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
    //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
    //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());

    // Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
    //static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
    //ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
    //io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
    //io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);

    bool show_test_window = true;
    bool show_another_window = false;
    ImVec4 clear_col = ImColor(114, 144, 154);

    // Main loop
    MSG msg;
    ZeroMemory(&msg, sizeof(msg));
    while (msg.message != WM_QUIT)
    {
        if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
            continue;
        }
        ImGui_ImplDX11_NewFrame();

        // 1. Show a simple window
        // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
        {
            static float f = 0.0f;
            ImGui::Text("Hello, world!");
            ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
            ImGui::ColorEdit3("clear color", (float*)&clear_col);
            if (ImGui::Button("Test Window")) show_test_window ^= 1;
            if (ImGui::Button("Another Window")) show_another_window ^= 1;
            ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
        }

        // 2. Show another simple window, this time using an explicit Begin/End pair
        if (show_another_window)
        {
            ImGui::SetNextWindowSize(ImVec2(200,100), ImGuiSetCond_FirstUseEver);
            ImGui::Begin("Another Window", &show_another_window);
            ImGui::Text("Hello");
            ImGui::End();
        }

        // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
        if (show_test_window)
        {
            ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);     // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
            ImGui::ShowTestWindow(&show_test_window);
        }

        // Rendering
        g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col);
        ImGui::Render();
        g_pSwapChain->Present(0, 0);
    }

    ImGui_ImplDX11_Shutdown();
    CleanupDeviceD3D();
    UnregisterClass(L"ImGui Example", wc.hInstance);

    return 0;
}
Exemple #25
0
static int
d2d_init_common(int fs)
{
	HRESULT hr = S_OK;
	WCHAR title[200];
	D2D1_HWND_RENDER_TARGET_PROPERTIES props;

	d2d_log("Direct2D: d2d_init_common(fs=%d)\n", fs);

	cgapal_rebuild();

	if (fs)
	{
		d2d_screen_width = GetSystemMetrics(SM_CXSCREEN);
		d2d_screen_height = GetSystemMetrics(SM_CYSCREEN);

		// Direct2D seems to lack any proper fullscreen mode,
		// therefore we just create a full screen window
		// and pass its handle to a HwndRenderTarget
		
		mbstowcs(title, emu_version, sizeof_w(title));

		d2d_hwnd = CreateWindow(
			SUB_CLASS_NAME,
			title,
			WS_POPUP,
			0, 0, d2d_screen_width, d2d_screen_height,
			HWND_DESKTOP,
			NULL,
			hinstance,
			NULL);

		old_hwndMain = hwndMain;
		hwndMain = d2d_hwnd;

		plat_set_input(d2d_hwnd);

		SetFocus(d2d_hwnd);
		SetWindowPos(d2d_hwnd, HWND_TOPMOST, 0, 0, d2d_screen_width, d2d_screen_height, SWP_SHOWWINDOW);	
	}

	if (SUCCEEDED(hr))
	{
		hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, &d2d_factory);
	}

	if (fs)
	{
		props = D2D1::HwndRenderTargetProperties(d2d_hwnd,
			D2D1::SizeU(d2d_screen_width, d2d_screen_height));
	}
	else
	{
		// HwndRenderTarget will get resized appropriately by d2d_blit,
		// so it's fine to let D2D imply size of 0x0 for now
		props = D2D1::HwndRenderTargetProperties(hwndRender);
	}

	if (SUCCEEDED(hr))
	{
		hr = d2d_factory->CreateHwndRenderTarget(
			D2D1::RenderTargetProperties(),
			props,
			&d2d_hwndRT);
	}

	if (SUCCEEDED(hr))
	{
		// Create a bitmap for storing intermediate data
		hr = d2d_hwndRT->CreateBitmap(
			D2D1::SizeU(2048, 2048),
			D2D1::BitmapProperties(D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE)),	
			&d2d_bitmap);
	}	

	if (SUCCEEDED(hr)) 
	{
		d2d_fs = fs;

		d2d_width = 0;
		d2d_height = 0;

		// Make sure we get a clean exit.
		atexit(d2d_close);

		// Register our renderer!
		video_setblit(d2d_blit);
	}

	if (FAILED(hr))
	{
		d2d_log("Direct2D: d2d_init_common: error 0x%08lx\n", hr);
		d2d_close();
		return(0);
	}

	return(1);
}
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
                         LPARAM lParam) {
  static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL,
      stopWnd = NULL, editWnd = NULL;
  static WNDPROC editWndOldProc = NULL;

  // Static members used for the find dialog.
  static FINDREPLACE fr;
  static WCHAR szFindWhat[80] = {0};
  static WCHAR szLastFindWhat[80] = {0};
  static bool findNext = false;
  static bool lastMatchCase = false;

  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;

  if (hWnd == editWnd) {
    // Callback for the edit window
    switch (message) {
    case WM_CHAR:
      if (wParam == VK_RETURN && g_handler.get()) {
        // When the user hits the enter key load the URL
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        wchar_t strPtr[MAX_URL_LENGTH+1] = {0};
        *((LPWORD)strPtr) = MAX_URL_LENGTH;
        LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr);
        if (strLen > 0) {
          strPtr[strLen] = 0;
          browser->GetMainFrame()->LoadURL(strPtr);
        }

        return 0;
      }
    }

    return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam,
                                   lParam);
  } else if (message == uFindMsg) {
    // Find event.
    LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam;

    if (lpfr->Flags & FR_DIALOGTERM) {
      // The find dialog box has been dismissed so invalidate the handle and
      // reset the search results.
      hFindDlg = NULL;
      if (g_handler.get()) {
        g_handler->GetBrowser()->GetHost()->StopFinding(true);
        szLastFindWhat[0] = 0;
        findNext = false;
      }
      return 0;
    }

    if ((lpfr->Flags & FR_FINDNEXT) && g_handler.get())  {
      // Search for the requested string.
      bool matchCase = (lpfr->Flags & FR_MATCHCASE?true:false);
      if (matchCase != lastMatchCase ||
          (matchCase && wcsncmp(szFindWhat, szLastFindWhat,
              sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0) ||
          (!matchCase && _wcsnicmp(szFindWhat, szLastFindWhat,
              sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0)) {
        // The search string has changed, so reset the search results.
        if (szLastFindWhat[0] != 0) {
          g_handler->GetBrowser()->GetHost()->StopFinding(true);
          findNext = false;
        }
        lastMatchCase = matchCase;
        wcscpy_s(szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR),
            szFindWhat);
      }

      g_handler->GetBrowser()->GetHost()->Find(0, lpfr->lpstrFindWhat,
          (lpfr->Flags & FR_DOWN)?true:false, matchCase, findNext);
      if (!findNext)
        findNext = true;
    }

    return 0;
  } else {
    // Callback for the main window
    switch (message) {
    case WM_CREATE: {
      // Create the single static handler class instance
      g_handler = new ClientHandler();
      g_handler->SetMainHwnd(hWnd);

      // Create the child windows used for navigation
      RECT rect;
      int x = 0;

      GetClientRect(hWnd, &rect);

      backWnd = CreateWindow(L"BUTTON", L"Back",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_BACK, hInst, 0);
      x += BUTTON_WIDTH;

      forwardWnd = CreateWindow(L"BUTTON", L"Forward",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      reloadWnd = CreateWindow(L"BUTTON", L"Reload",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      stopWnd = CreateWindow(L"BUTTON", L"Stop",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_STOP, hInst, 0);
      x += BUTTON_WIDTH;

      editWnd = CreateWindow(L"EDIT", 0,
                              WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
                              ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED,
                              x, 0, rect.right - BUTTON_WIDTH * 4,
                              URLBAR_HEIGHT, hWnd, 0, hInst, 0);

      /// @test Set font for all child windows
      EnumChildWindows(hWnd, (WNDENUMPROC)SetFont,
              (LPARAM)GetStockObject(DEFAULT_GUI_FONT));

      // Assign the edit window's WNDPROC to this function so that we can
      // capture the enter key
      editWndOldProc =
          reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC));
      SetWindowLongPtr(editWnd, GWLP_WNDPROC,
          reinterpret_cast<LONG_PTR>(WndProc));
      g_handler->SetEditHwnd(editWnd);
      g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd);

      rect.top += URLBAR_HEIGHT;

      CefWindowInfo info;
      CefBrowserSettings settings;

      if (AppIsOffScreenRenderingEnabled()) {
        CefRefPtr<CefCommandLine> cmd_line = AppGetCommandLine();
        bool transparent =
            cmd_line->HasSwitch(cefclient::kTransparentPaintingEnabled);

        CefRefPtr<OSRWindow> osr_window =
            OSRWindow::Create(&g_main_browser_provider, transparent);
        osr_window->CreateWidget(hWnd, rect, hInst, szOSRWindowClass);
        info.SetAsOffScreen(osr_window->hwnd());
        info.SetTransparentPainting(transparent ? TRUE : FALSE);
        g_handler->SetOSRHandler(osr_window.get());
      } else {
        // Initialize window info to the defaults for a child window.
        info.SetAsChild(hWnd, rect);
      }

      // Creat the new child browser window
      CefBrowserHost::CreateBrowser(info, g_handler.get(),
          g_handler->GetStartupURL(), settings, NULL);

      return 0;
    }

    case WM_COMMAND: {
      CefRefPtr<CefBrowser> browser;
      if (g_handler.get())
        browser = g_handler->GetBrowser();

      wmId    = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      // Parse the menu selections:
      switch (wmId) {
      case IDM_ABOUT:
        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
        return 0;
      case IDM_EXIT:
        if (g_handler.get())
          g_handler->CloseAllBrowsers(false);
        return 0;
      case ID_WARN_CONSOLEMESSAGE:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"Console messages will be written to "
              << std::wstring(CefString(g_handler->GetLogFile()));
          MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
      case ID_WARN_DOWNLOADCOMPLETE:
      case ID_WARN_DOWNLOADERROR:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"File \"" <<
              std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
              L"\" ";

          if (wmId == ID_WARN_DOWNLOADCOMPLETE)
            ss << L"downloaded successfully.";
          else
            ss << L"failed to download.";

          MessageBox(hWnd, ss.str().c_str(), L"File Download",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
      case ID_FIND:
        if (!hFindDlg) {
          // Create the find dialog.
          ZeroMemory(&fr, sizeof(fr));
          fr.lStructSize = sizeof(fr);
          fr.hwndOwner = hWnd;
          fr.lpstrFindWhat = szFindWhat;
          fr.wFindWhatLen = sizeof(szFindWhat);
          fr.Flags = FR_HIDEWHOLEWORD | FR_DOWN;

          hFindDlg = FindText(&fr);
        } else {
          // Give focus to the existing find dialog.
          ::SetFocus(hFindDlg);
        }
        return 0;
      case IDC_NAV_BACK:   // Back button
        if (browser.get())
          browser->GoBack();
        return 0;
      case IDC_NAV_FORWARD:  // Forward button
        if (browser.get())
          browser->GoForward();
        return 0;
      case IDC_NAV_RELOAD:  // Reload button
        if (browser.get())
          browser->Reload();
        return 0;
      case IDC_NAV_STOP:  // Stop button
        if (browser.get())
          browser->StopLoad();
        return 0;
      case ID_TESTS_GETSOURCE:  // Test the GetSource function
        if (browser.get())
          RunGetSourceTest(browser);
        return 0;
      case ID_TESTS_GETTEXT:  // Test the GetText function
        if (browser.get())
          RunGetTextTest(browser);
        return 0;
      case ID_TESTS_POPUP:  // Test a popup window
        if (browser.get())
          RunPopupTest(browser);
        return 0;
      case ID_TESTS_REQUEST:  // Test a request
        if (browser.get())
          RunRequestTest(browser);
        return 0;
      case ID_TESTS_PLUGIN_INFO:  // Test plugin info
        if (browser.get())
          RunPluginInfoTest(browser);
        return 0;
      case ID_TESTS_ZOOM_IN:
        if (browser.get())
          ModifyZoom(browser, 0.5);
        return 0;
      case ID_TESTS_ZOOM_OUT:
        if (browser.get())
          ModifyZoom(browser, -0.5);
        return 0;
      case ID_TESTS_ZOOM_RESET:
        if (browser.get())
          browser->GetHost()->SetZoomLevel(0.0);
        return 0;
      case ID_TESTS_TRACING_BEGIN:
        g_handler->BeginTracing();
        return 0;
      case ID_TESTS_TRACING_END:
        g_handler->EndTracing();
        return 0;
      case ID_TESTS_PRINT:
        if(browser.get())
          browser->GetHost()->Print();
        return 0;
      case ID_TESTS_OTHER_TESTS:
        if (browser.get())
          RunOtherTests(browser);
        return 0;
      }
      break;
    }

    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      EndPaint(hWnd, &ps);
      return 0;

    case WM_SETFOCUS:
      if (g_handler.get() && g_handler->GetBrowser()) {
        // Pass focus to the browser window
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd)
          PostMessage(hwnd, WM_SETFOCUS, wParam, NULL);
      }
      return 0;

    case WM_SIZE:
      // Minimizing resizes the window to 0x0 which causes our layout to go all
      // screwy, so we just ignore it.
      if (wParam != SIZE_MINIMIZED && g_handler.get() &&
          g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Resize the browser window and address bar to match the new frame
          // window size
          RECT rect;
          GetClientRect(hWnd, &rect);
          rect.top += URLBAR_HEIGHT;

          int urloffset = rect.left + BUTTON_WIDTH * 4;

          HDWP hdwp = BeginDeferWindowPos(1);
          hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset,
            0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER);
          hdwp = DeferWindowPos(hdwp, hwnd, NULL,
            rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
            SWP_NOZORDER);
          EndDeferWindowPos(hdwp);
        }
      }
      break;

    case WM_ERASEBKGND:
      if (g_handler.get() && g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Dont erase the background if the browser window has been loaded
          // (this avoids flashing)
          return 0;
        }
      }
      break;

    case WM_ENTERMENULOOP:
      if (!wParam) {
        // Entering the menu loop for the application menu.
        CefSetOSModalLoop(true);
      }
      break;

    case WM_EXITMENULOOP:
      if (!wParam) {
        // Exiting the menu loop for the application menu.
        CefSetOSModalLoop(false);
      }
      break;

    case WM_CLOSE:
      if (g_handler.get() && !g_handler->IsClosing()) {
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        if (browser.get()) {
          // Notify the browser window that we would like to close it. This
          // will result in a call to ClientHandler::DoClose() if the
          // JavaScript 'onbeforeunload' event handler allows it.
          browser->GetHost()->CloseBrowser(false);

          // Cancel the close.
          return 0;
        }
      }

      // Allow the close.
      break;

    case WM_DESTROY:
      // Quitting CEF is handled in ClientHandler::OnBeforeClose().
      return 0;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
  }
}
Exemple #27
0
/* This is where all the input to the window goes to */
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
	static HWND Textbox,Button,BackgroundIMG;
	static time_t time1;
	static time_t time2;
	static char buffer[SIZE] = {};
	static boolean tof = 1;
	static boolean deltof = 0;
	static boolean first = 0;
	static struct stack_list* ms = NULL;
	static int count = 1;
	static char* deleted;
	static int n = 0;
	if(!first){
		first = 1;
			deleted = (char*) malloc(SIZE);
			ms = stack_new();
	}
	if(deltof && time1-time2 == 2){ // si el ultimo fue delete
		push(ms,deleted);	
		n = 0;
		time2 = time1;
		strcpy(deleted,"");
		count++;
		deltof = 0;
	}
	switch(Message) {
		
			
		case WM_COMMAND:{ // es para detectar eventos
			if(LOWORD(wParam) == txtbox){
			
				if(HIWORD(wParam) == EN_UPDATE && !tof){
					if(time1 == 0){
						
						time1 = time(NULL);
						time2 = time(NULL);
					}
					else{
						time1 = time2;
						time2 = time(NULL);
						
					}
					char* aux;
					aux = (char*)malloc(100);
					if((time2 - time1) > LIMIT )
					{	
						
						time1 = time2;
						n++;
						GetWindowText(Textbox,buffer,SIZE);
						push(ms,buffer);
						count++;
						
						
						
					}
					else if(LastKey(32)){
						
						deleted[n++] = LastChar(aux);
						deltof = 1;
						
									
					}
					
				}
				tof = 0;
			}
			else if(LOWORD(wParam) == button){
				
				SetWindowText(Textbox,top(ms));
				pop(ms);
				count--;
				if(count == 0){
					push(ms,"Introduzca su texto");		
					count++;
				}
					// accion del boton aqui	
			}
			break;
		}
		
		case WM_CREATE:{
			Textbox = CreateWindow(TEXT("edit"),"Introduzca su texto",WS_BORDER | WS_CHILD |ES_MULTILINE| ES_AUTOHSCROLL| WS_VISIBLE,0,250,2000,1000,hwnd,(HMENU) txtbox,((LPCREATESTRUCT) lParam)->hInstance,NULL);
			push(ms,"Introduzca su texto");
			Button = CreateWindow("BUTTON","CONTROL Z", WS_BORDER | WS_VISIBLE | WS_CHILD,200,50,200,50,hwnd,(HMENU) button,NULL,NULL);
			break;
		}
		/* trap the WM_CLOSE (clicking X) message, and actually tell the window to close */
		case WM_CLOSE: {
			DestroyWindow(hwnd);
			break;
		}
		
		/* Upon destruction, tell the main thread to stop */
		case WM_DESTROY: {
			PostQuitMessage(0);
			break;
		}
		
		/* All other messages (a lot of them) are processed using default procedures */
		default:
			return DefWindowProc(hwnd, Message, wParam, lParam);
	}
	return 0;
}
Exemple #28
0
HWND
CreateOpenGLWindow(char* title, int x, int y, int width, int height, 
		   BYTE type, DWORD flags)
{
    int         n, pf;
    HWND        hWnd;
    WNDCLASS    wc;
    LOGPALETTE* lpPal;
    PIXELFORMATDESCRIPTOR pfd;
    static HINSTANCE hInstance = 0;

    /* only register the window class once - use hInstance as a flag. */
    if (!hInstance) {
	hInstance = GetModuleHandle(NULL);
	wc.style         = CS_OWNDC;
	wc.lpfnWndProc   = (WNDPROC)WindowProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = hInstance;
	wc.hIcon         = LoadIcon(NULL, IDI_WINLOGO);
	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = NULL;
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = "OpenGL";

	if (!RegisterClass(&wc)) {
	    MessageBox(NULL, "RegisterClass() failed:  "
		       "Cannot register window class.", "Error", MB_OK);
	    return NULL;
	}
    }

    hWnd = CreateWindow("OpenGL", title, WS_OVERLAPPEDWINDOW |
			WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
			x, y, width, height, NULL, NULL, hInstance, NULL);

    if (hWnd == NULL) {
	MessageBox(NULL, "CreateWindow() failed:  Cannot create a window.",
		   "Error", MB_OK);
	return NULL;
    }

    hDC = GetDC(hWnd);

    /* there is no guarantee that the contents of the stack that become
       the pfd are zeroed, therefore _make sure_ to clear these bits. */
    memset(&pfd, 0, sizeof(pfd));
    pfd.nSize        = sizeof(pfd);
    pfd.nVersion     = 1;
    pfd.dwFlags      = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | flags;
    pfd.iPixelType   = type;
    pfd.cColorBits   = 32;

    pf = ChoosePixelFormat(hDC, &pfd);
    if (pf == 0) {
	MessageBox(NULL, "ChoosePixelFormat() failed:  "
		   "Cannot find a suitable pixel format.", "Error", MB_OK); 
	return 0;
    } 
 
    if (SetPixelFormat(hDC, pf, &pfd) == FALSE) {
	MessageBox(NULL, "SetPixelFormat() failed:  "
		   "Cannot set format specified.", "Error", MB_OK);
	return 0;
    } 

    DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

    if (pfd.dwFlags & PFD_NEED_PALETTE ||
	pfd.iPixelType == PFD_TYPE_COLORINDEX) {

	n = 1 << pfd.cColorBits;
	if (n > 256) n = 256;

	lpPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) +
				    sizeof(PALETTEENTRY) * n);
	memset(lpPal, 0, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * n);
	lpPal->palVersion = 0x300;
	lpPal->palNumEntries = n;

	GetSystemPaletteEntries(hDC, 0, n, &lpPal->palPalEntry[0]);
    
	/* if the pixel type is RGBA, then we want to make an RGB ramp,
	   otherwise (color index) set individual colors. */
	if (pfd.iPixelType == PFD_TYPE_RGBA) {
	    int redMask = (1 << pfd.cRedBits) - 1;
	    int greenMask = (1 << pfd.cGreenBits) - 1;
	    int blueMask = (1 << pfd.cBlueBits) - 1;
	    int i;

	    /* fill in the entries with an RGB color ramp. */
	    for (i = 0; i < n; ++i) {
		lpPal->palPalEntry[i].peRed = 
		    (((i >> pfd.cRedShift)   & redMask)   * 255) / redMask;
		lpPal->palPalEntry[i].peGreen = 
		    (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask;
		lpPal->palPalEntry[i].peBlue = 
		    (((i >> pfd.cBlueShift)  & blueMask)  * 255) / blueMask;
		lpPal->palPalEntry[i].peFlags = 0;
	    }
	} else {
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow)
{
  WNDCLASSEX wcex;
  MSG        Msg;
  HWND       hWnd;

  // Initialize the COM system
  CoInitialize(NULL);

  // Create the window class here and register it
  wcex.cbSize        = sizeof(wcex);
  wcex.style         = CS_CLASSDC;
  wcex.lpfnWndProc   = WindowProc;
  wcex.cbClsExtra    = 0;
  wcex.cbWndExtra    = 0;
  wcex.hInstance     = hInst;
  wcex.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  wcex.hCursor       = LoadCursor(NULL, IDC_ARROW);
  wcex.hbrBackground = NULL;
  wcex.lpszMenuName  = NULL;
  wcex.lpszClassName = g_szClass;
  wcex.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  if(!RegisterClassEx(&wcex))
    return FALSE;

  // Create the main window
  hWnd = CreateWindow(g_szClass, g_szCaption,
              WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
              0, 0, 640, 480,
              NULL, NULL, hInst, NULL);
  if(!hWnd)
    return FALSE;
  ShowWindow(hWnd, SW_NORMAL);
  UpdateWindow(hWnd);

  // Call init function and enter message pump
  if(DoInit(hWnd) == TRUE) {

    // Start message pump, waiting for user to exit
    ZeroMemory(&Msg, sizeof(MSG));
    while(Msg.message != WM_QUIT) {
      if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
      }

      // Render a single frame
      DoFrame();
    }
  }

  // Call shutdown
  DoShutdown();
 
  // Unregister the window class
  UnregisterClass(g_szClass, hInst);

  // Shut down the COM system
  CoUninitialize();

  return 0;
}
Exemple #30
0
int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR szCmdLine, int iCmdShow)
{
    HWND        hwnd;
    MSG            msg;
    WNDCLASS    wndclass;
    INITCOMMONCONTROLSEX ice;
    HACCEL        hAccelTable;

    hInstance = hInst;

    /* Load application title */
    LoadString(hInst, IDS_SPI_NAME, szAppName, sizeof(szAppName) / sizeof(szAppName[0]));
    /* Load MsgBox() texts here to avoid loading them many times later */
    LoadString(hInst, IDS_SPI_ABOUT, MsgAbout, sizeof(MsgAbout) / sizeof(MsgAbout[0]));
    LoadString(hInst, IDS_SPI_QUIT, MsgQuit, sizeof(MsgQuit) / sizeof(MsgQuit[0]));
    LoadString(hInst, IDS_SPI_WIN, MsgWin, sizeof(MsgWin) / sizeof(MsgWin[0]));
    LoadString(hInst, IDS_SPI_DEAL, MsgDeal, sizeof(MsgDeal) / sizeof(MsgDeal[0]));

    /* Window class for the main application parent window */
    wndclass.style             = 0;
    wndclass.lpfnWndProc       = WndProc;
    wndclass.cbClsExtra        = 0;
    wndclass.cbWndExtra        = 0;
    wndclass.hInstance         = hInst;
    wndclass.hIcon             = LoadIcon (hInst, MAKEINTRESOURCE(IDI_SPIDER));
    wndclass.hCursor           = LoadCursor (NULL, IDC_ARROW);
    wndclass.hbrBackground     = (HBRUSH)NULL;
    wndclass.lpszMenuName      = MAKEINTRESOURCE(IDR_MENU1);
    wndclass.lpszClassName     = szAppName;

    RegisterClass(&wndclass);

    ice.dwSize = sizeof(ice);
    ice.dwICC = ICC_BAR_CLASSES;
    InitCommonControlsEx(&ice);

    srand((unsigned)GetTickCount());

    /* InitCardLib(); */

    /* Construct the path to our help file */
    MakePath(szHelpPath, MAX_PATH, _T(".hlp"));

    hwnd = CreateWindow(szAppName,
                szAppName,
                WS_OVERLAPPEDWINDOW,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                0,  /*The real size will be computed in WndProc through WM_GETMINMAXINFO */
                0,  /* The real size will be computed in WndProc through WM_GETMINMAXINFO */
                NULL,
                NULL,
                hInst,
                NULL);

    hwndMain = hwnd;

    ShowWindow(hwnd, iCmdShow);
    UpdateWindow(hwnd);

    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1));
    
    DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIFFICULTY), hwnd, DifficultyDlgProc);
  
    while(GetMessage(&msg, NULL,0,0))
    {
        if(!TranslateAccelerator(hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    return msg.wParam;
}