Esempio n. 1
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	MSG msg;
    INITCOMMONCONTROLSEX ctrls;
	HACCEL haccel;
	static char *class_name="DB_UTIL_CLASS";
	int first_instance=TRUE;
	int debug=0;

	first_instance=set_single_instance(TRUE);

	ghinstance=hInstance;
	init_ini_file();

#ifdef _DEBUG
	debug=1;
#else
	get_ini_value("SETTINGS","DEBUG",&debug);
#endif
	if(debug!=0){
		open_console();
	}

	{
		int val=0;
		get_ini_value("SETTINGS","SINGLE_INSTANCE",&val);
		if(val && (!first_instance)){
			COPYDATASTRUCT cd={0};
			HWND hdbutil;
			cd.cbData=nCmdShow;
			cd.cbData=strlen(lpCmdLine)+1;
			cd.lpData=lpCmdLine;
			hdbutil=FindWindow("DB_UTIL_CLASS",NULL);
			if(hdbutil!=0){
				int sw;
				SendMessage(hdbutil,WM_COPYDATA,hInstance,&cd);
				if (IsZoomed(hdbutil))
					sw=SW_MAXIMIZE;
				else if(IsIconic(hdbutil))
					sw=SW_RESTORE;
				else
					sw=SW_SHOW;
				ShowWindow(hdbutil,sw);
				SetForegroundWindow(hdbutil);
			}
			return TRUE;
		}
		set_single_instance(val);
	}
	init_mdi_stuff();

	LoadLibrary("RICHED20.DLL");
	LoadLibrary("Msftedit.dll");

	ctrls.dwSize=sizeof(ctrls);
    ctrls.dwICC = ICC_LISTVIEW_CLASSES|ICC_TREEVIEW_CLASSES|ICC_BAR_CLASSES;
	InitCommonControlsEx(&ctrls);
	
	InitializeCriticalSection(&mutex);

	start_worker_thread();
	start_intellisense_thread();

	setup_mdi_classes(ghinstance);
	
	ghmenu=LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
	ghmainframe=create_mainwindow(&WndProc,ghmenu,hInstance,class_name,"DB_UTIL");

	ShowWindow(ghmainframe,nCmdShow);
	UpdateWindow(ghmainframe);

	haccel=LoadAccelerators(ghinstance,MAKEINTRESOURCE(IDR_ACCELERATOR1));

	process_cmd_line(lpCmdLine);

    while(GetMessage(&msg,NULL,0,0)){
		if(!custom_dispatch(&msg))
		if(!TranslateMDISysAccel(ghmdiclient, &msg) && !TranslateAccelerator(ghmainframe,haccel,&msg)){
			TranslateMessage(&msg);
			//if(msg!=WM_MOUSEFIRST&&msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_NOTIFY)
			if(FALSE)
			if(msg.message!=0x118&&msg.message!=WM_NCHITTEST&&msg.message!=WM_SETCURSOR&&msg.message!=WM_ENTERIDLE&&msg.message!=WM_NCMOUSEMOVE&&msg.message!=WM_MOUSEFIRST)
			{
				static DWORD tick=0;
				if((GetTickCount()-tick)>500)
					printf("--\n");
				printf("x");
				print_msg(msg.message,msg.lParam,msg.wParam,msg.hwnd);
				tick=GetTickCount();
			}
			DispatchMessage(&msg);
		}
    }
	DeleteCriticalSection(&mutex);
    return msg.wParam;
	
}
Esempio n. 2
0
LRESULT CALLBACK settings_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	static HWND grippy=0;
	static int font_changed=FALSE;
	static int justify_changed=FALSE;
	switch(msg){
	case WM_INITDIALOG:
		{
			extern int keep_closed;
			int val;
			get_ini_value(INI_SETTINGS,"KEEP_CLOSED",&keep_closed);
			if(!keep_closed)
				CheckDlgButton(hwnd,IDC_KEEP_CONNECTED,BST_CHECKED);
			val=0;
			get_ini_value(INI_SETTINGS,"SINGLE_INSTANCE",&val);
			if(val)
				CheckDlgButton(hwnd,IDC_SINGLE_INSTANCE,BST_CHECKED);
			val=0;
			get_ini_value(INI_SETTINGS,"DEBUG",&val);
			if(val)
				CheckDlgButton(hwnd,IDC_DEBUG,BST_CHECKED);

			get_ini_value(INI_SETTINGS,"TRIM_TRAILING",&trim_trailing);
			if(trim_trailing)
				CheckDlgButton(hwnd,IDC_TRIM_TRAILING,BST_CHECKED);

			get_ini_value(INI_SETTINGS,"LEFT_JUSTIFY",&left_justify);
			if(left_justify)
				CheckDlgButton(hwnd,IDC_LEFT_JUSTIFY,BST_CHECKED);

			get_ini_value(INI_SETTINGS,"SAVE_MDI_WIN_SIZE",&save_mdi_win_size);
			if(save_mdi_win_size)
				CheckDlgButton(hwnd,IDC_SAVE_MDI_WIN_SIZE,BST_CHECKED);

			add_fonts(hwnd,IDC_SQL_FONT);
			add_fonts(hwnd,IDC_LISTVIEW_FONT);
			add_fonts(hwnd,IDC_TREEVIEW_FONT);
			select_current_font(hwnd,IDC_SQL_FONT);
			select_current_font(hwnd,IDC_LISTVIEW_FONT);
			select_current_font(hwnd,IDC_TREEVIEW_FONT);
			font_changed=FALSE;
			justify_changed=FALSE;
		}
		grippy=create_grippy(hwnd);
		break;
	case WM_SIZE:
		grippy_move(hwnd,grippy);
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDC_DEBUG:
			printf("debug %08X %08X\n",wparam,lparam);
			if(IsDlgButtonChecked(hwnd,IDC_DEBUG)==BST_CHECKED)
				open_console();
			else
				hide_console();
			break;
		case IDC_FILE_ASSOCIATIONS:
			DialogBoxParam(ghinstance,IDD_FILE_ASSOCIATIONS,hwnd,file_assoc_proc,0);
			break;
		case IDC_OPEN_INI:
			open_ini(hwnd,FALSE);
			break;
		case IDC_SQL_FONT:
			if(HIWORD(wparam)==CBN_SELENDOK){
				int i,max=get_max_table_windows();
				int font;
				char str[80]={0};
				GetDlgItemText(hwnd,IDC_SQL_FONT,str,sizeof(str));
				font=fontname_to_int(str);
				for(i=0;i<max;i++){
					HWND hedit=0;
					if(get_win_hwnds(i,NULL,&hedit,NULL)){
						SendMessage(hedit,WM_SETFONT,GetStockObject(font),0);
						InvalidateRect(hedit,NULL,TRUE);
					}
				}
				font_changed=TRUE;
			}
			break;
		case IDC_LISTVIEW_FONT:
			if(HIWORD(wparam)==CBN_SELENDOK){
				int i,max=get_max_table_windows();
				int font;
				char str[80]={0};
				GetDlgItemText(hwnd,IDC_LISTVIEW_FONT,str,sizeof(str));
				font=fontname_to_int(str);
				for(i=0;i<max;i++){
					HWND hlistview;
					if(get_win_hwnds(i,NULL,NULL,&hlistview)){
						SendMessage(hlistview,WM_SETFONT,GetStockObject(font),0);
						InvalidateRect(hlistview,NULL,TRUE);
					}
				}
				font_changed=TRUE;
			}
			break;
		case IDC_TREEVIEW_FONT:
			if(HIWORD(wparam)==CBN_SELENDOK){
				extern HWND ghtreeview;
				int font;
				char str[80]={0};
				GetDlgItemText(hwnd,IDC_TREEVIEW_FONT,str,sizeof(str));
				font=fontname_to_int(str);
				if(ghtreeview!=0){
					SendMessage(ghtreeview,WM_SETFONT,GetStockObject(font),0);
					InvalidateRect(ghtreeview,NULL,TRUE);
				}
				font_changed=TRUE;
			}
			break;
		case IDC_LEFT_JUSTIFY:
			if(HIWORD(wparam)==BN_CLICKED){
				extern int left_justify;
				int i,max=get_max_table_windows();
				if(IsDlgButtonChecked(hwnd,IDC_LEFT_JUSTIFY)==BST_CHECKED)
					left_justify=1;
				else
					left_justify=0;
				for(i=0;i<max;i++){
					HWND hlistview;
					if(get_win_hwnds(i,NULL,NULL,&hlistview))
						InvalidateRect(hlistview,NULL,TRUE);
				}
				justify_changed=TRUE;
			}
			break;
		case IDOK:
			{
			extern int keep_closed;
			char key[80],str[80];
			int i,val,ctrls[3]={IDC_SQL_FONT,IDC_LISTVIEW_FONT,IDC_TREEVIEW_FONT};
			if(IsDlgButtonChecked(hwnd,IDC_KEEP_CONNECTED)==BST_CHECKED)
				keep_closed=FALSE;
			else
				keep_closed=TRUE;
			
			write_ini_value(INI_SETTINGS,"KEEP_CLOSED",keep_closed);

			val=0;
			if(IsDlgButtonChecked(hwnd,IDC_SINGLE_INSTANCE)==BST_CHECKED)
				val=1;
			write_ini_value(INI_SETTINGS,"SINGLE_INSTANCE",val);
			set_single_instance(val);

			val=0;
			if(IsDlgButtonChecked(hwnd,IDC_DEBUG)==BST_CHECKED)
				val=1;
			write_ini_value(INI_SETTINGS,"DEBUG",val);

			
			if(IsDlgButtonChecked(hwnd,IDC_TRIM_TRAILING)==BST_CHECKED)
				trim_trailing=1;
			else
				trim_trailing=0;
			write_ini_value(INI_SETTINGS,"TRIM_TRAILING",trim_trailing);

			if(IsDlgButtonChecked(hwnd,IDC_LEFT_JUSTIFY)==BST_CHECKED)
				left_justify=1;
			else
				left_justify=0;
			write_ini_value(INI_SETTINGS,"LEFT_JUSTIFY",left_justify);

			if(IsDlgButtonChecked(hwnd,IDC_SAVE_MDI_WIN_SIZE)==BST_CHECKED)
				save_mdi_win_size=1;
			else
				save_mdi_win_size=0;
			write_ini_value(INI_SETTINGS,"SAVE_MDI_SIZE",save_mdi_win_size);

			for(i=0;i<sizeof(ctrls)/sizeof(int);i++){
				key[0]=0;
				get_control_name(ctrls[i],key,sizeof(key));
				str[0]=0;
				GetDlgItemText(hwnd,ctrls[i],str,sizeof(str));
				write_ini_str(INI_SETTINGS,key,str);
			}
			}
		case IDCANCEL:
			if(font_changed){
				int i,ctrls[3]={IDC_SQL_FONT,IDC_LISTVIEW_FONT,IDC_TREEVIEW_FONT};
				for(i=0;i<sizeof(ctrls)/sizeof(int);i++){
					char key[80],str[80];
					key[0]=0;
					get_control_name(ctrls[i],key,sizeof(key));
					str[0]=0;
					GetDlgItemText(hwnd,ctrls[i],str,sizeof(str));
					get_ini_str(INI_SETTINGS,key,str,sizeof(str));
					if(str[0]!=0){
						int max=get_max_table_windows();
						int font=fontname_to_int(str);
						if(ctrls[i]==IDC_SQL_FONT){
							int j;
							for(j=0;j<max;j++){
								HWND hedit=0;
								if(get_win_hwnds(j,NULL,&hedit,NULL)){
									SendMessage(hedit,WM_SETFONT,GetStockObject(font),0);
									InvalidateRect(hedit,NULL,TRUE);
								}
							}
						}
						else if(ctrls[i]==IDC_LISTVIEW_FONT){
							int j;
							for(j=0;j<max;j++){
								HWND hlistview;
								if(get_win_hwnds(j,NULL,NULL,&hlistview)){
									SendMessage(hlistview,WM_SETFONT,GetStockObject(font),0);
									InvalidateRect(hlistview,NULL,TRUE);
								}
							}
						}
						else if(ctrls[i]==IDC_TREEVIEW_FONT){
							extern HWND ghtreeview;
							SendMessage(ghtreeview,WM_SETFONT,GetStockObject(font),0);
						}
					}
				}
			}
			if(justify_changed){
				int i,max=get_max_table_windows();
				get_ini_value(INI_SETTINGS,"LEFT_JUSTIFY",&left_justify);
				for(i=0;i<max;i++){
					HWND hlistview;
					if(get_win_hwnds(i,NULL,NULL,&hlistview))
						InvalidateRect(hlistview,NULL,TRUE);
				}
			}
			EndDialog(hwnd,0);
			break;
		}
		break;
	}
	return 0;
}