AutoCAD VB.Net Color Picker - autocad

I am porting some AutoCAD VBA to VB.Net.
Several of the modules do a ThisDrawing.SendCommand("_color" & vbCR) to popup an AutoCAD color picker, then process the response by doing a ThisDrawing.GetVariable("CECOLOR") to get the selected color.
With .Net, the SendCommand does not execute until the program ends.
How can I get the AutoCAD color picker to execute inline in my code?

There is a ColorDialog class to do that. Here is some C# code:
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
var cd = new ColorDialog();
if (cd.ShowDialog() != DialogResult.OK) return;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("\nSelected color: " + cd.Color);

Related

Windows Forms c++ cannot set default values in datagrid cells

I've just started working with Windows Forms on Visual Studio 2019. I am most familiar with C++ and thus have been creating an application with C++/CLI. The basis of the project is that I have a schedule generating set of functions these are called in MyForm.h which is the main form originally launched. MyForm.h also opens MyForm2.h when a button is pressed. This MyForm2.h is where I have a problem. I want to allow the user to edit a series of specific settings for the schedule generator. The most user friendly way I've found to do this is with a datagrid using textboxes and checkmarks, but I need to have the original timeslots for the schedule in the datagrid for the user to edit when the open MyForm2.h.
I've looked all over to find how to set default values for a datagrid, but have only come up with two ok methods, both of which have some fatal flaws.
The first was from this microsoft guide.
The problem here is that the solution is written in c#, and I don't know how to implement it in a c++ program.
The second was from a few sites which generally displayed one of two formats which are displayed here in a way that is formatted to how I used them in my forms:
void InitializeComponent()
{
this->dgvStudents = (gcnew System::Windows::Forms::DataGridView());
this->dataGridViewTextBoxColumn1 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dgvStudents))->BeginInit();
this->SuspendLayout();
this->dgvStudents->Columns->Add(this->dataGridViewTextBoxColumn1);
this->dgvStudents->Location = System::Drawing::Point(0, 0);
this->dgvStudents->Name = L"dgvStudents";
this->dgvStudents->Size = System::Drawing::Size(350, 100);
this->dgvStudents->TabIndex = 0;
//
// dataGridViewTextBoxColumn1
//
this->dataGridViewTextBoxColumn1->HeaderText = L"First Name";
this->dataGridViewTextBoxColumn1->Name = L"dataGridViewTextBoxColumn1";
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(638, 261);
this->Controls->Add(this->dgvStudents);
this->Name = L"MyForm3";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Exercise";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dgvStudents))->EndInit();
this->ResumeLayout(false);
// Option 1
this->dgvStudents->Rows[0]->Cells[0]->Value = "MLP";
// Option 2
this->dgvStudents->Rows->Add("MLP");
}
I have tried putting both options in several various parts of the InitializeComponent() function and it makes no difference. The problem with Option 2 of this second solution is that it will be removed from the code if I change anything in the [Design] part of the MyForm2.h code editor in VS and save it. Weirdly, Option 1 will not be displayed in the [Design] part of the code and instead I will get the error Member Cells not found in class System.Windows.Forms.DataGridViewRowCollection, but if I launch the debugger for the program, both options will be displayed exactly how I want them to be in the GUIs that appear. As previously meantioned though, both options will most likely be removed if I change anything else in the form designer. Any help would be greatly appreciated:)

IUP, menu, webbrowser, tree, tabs

I have such menu situation:
int menu_create(Ihandle *menu)
{
hamburger = IupItem("&Hamburger", "hamburger");
IupSetAttributes(hamburger, "AUTOTOGGLE=YES, RADIO=YES");
char* ce = "Ćev&apčići";
cevapcici = IupItem(utf8_to_cp1250(ce), "cevapcici");
IupSetAttributes(cevapcici, "AUTOTOGGLE=YES, RADIO=YES");
exit = IupItem("Exit\tAlt+F4", "exit");
img4 = IupLoadImage("icons\\delete_16x16.ico");
IupSetAttributeHandle(exit, "TITLEIMAGE", img4);
menu = IupMenu(
IupSubmenu("File",
IupMenu(
hamburger,
cevapcici,
IupSeparator(),
IupItem("Carro&t", "carrot"),
IupSeparator(),
exit,
NULL)),
NULL);
IupSetFunction("exit", (Icallback)mnu_exit);
... etc...
IupSetHandle("menu", menu);
return IUP_DEFAULT;
}
How to get "radio toggle group" functionality with items hamburger and cevapcici so first turns off a second checkmark and opposite. This is my try but it don't work.
2) I try webbrowser example from IUP suite on my windows 7. Problem is that bad black flickering appear's during resize (increase). Also, background of webbrowser flicker black during showing.
I try a same example on Ubuntu and there flickering appear's too but it is not so much visible since background is there white.
Is here any way to get rid of those flickering or if not to get white background of webbrowser window on windows?
3) Since webbrowser is ole object (on windows) is it possible to use say "print preview" or "zoom" function by reference from IUP handle or at any other way like we used to do from MS programming tools?
wbInstance.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, ExecOpt.OLECMDEXECOPT_DONTPROMPTUSER, 150, DBNull.Value)
4) How can I get key_up event fired from IupTree?
5) Interesting situation with IupTabs:
frame3 = IupHbox(mat, val, NULL);
vboxt1 = IupVbox(frame3, NULL);
vboxt2 = IupVbox(frame3, NULL);
IupSetAttribute(vboxt1, "TABTITLE", "First documents... ");
IupSetAttribute(vboxt2, "TABTITLE", "Second documents... ");
tabs = IupTabs(vboxt1, vboxt2, NULL);
hbox1 = IupHbox(tabs, IupVbox(frame, tree, frame2, NULL), NULL);
dlg = IupDialog(hbox1);
When I set frame3 which should be a same for both tabs my GUI frozes.
However, I have to got same "mat" (IupMatrix) in both tabs because by changing tabs other data load in matrix but similar enough to use same matrix and related functions.
What to do here?
1) The RADIO attribute belongs to the IupMenu, not to the IupItem. This also means that all the IupItems inside that menu will be part of the radio.
A workaround would be to manually unset the other toggle inside the action callback.
2) That flicker is not caused by IUP. Don't know why the native controls are doing it.
3) Yes, but you will have to program that using the OLE API. If you take a look at the IupOleControl and IupWebBrower source code and send me the code to do it, I will be happy to add it to IUP.
4) You don't. Use the K_ANY callbacks.
5) You can not reuse a control in different places in any dialog. So you must have two different frames, with two different matrices. What you can do is to encapsulate your matrix, so the same function will create a matrix with the same attributes and callbacks any time you want one.

In Win32, how can a Change Color dialog be used to change STATIC text?

I am relatively new to the Win32/Windows API (non-MFC), and am trying to change the text colour of a static text control. It is already drawn to the screen in black, but I want to change it to another colour using the Windows Colour Chooser dialog, which is opened on clicking a button. Is this possible?
For the button, the WM_COMMAND message is handled on clicking. So far, I have written:
CHOOSECOLOR ccColour;
ccColour.lStructSize = sizeof(ccColour);
ccColour.hwndOwner = hWnd;
ccColour.rgbResult = crLabelTextColour;
ccColour.Flags = CC_FULLOPEN | CC_RGBINIT;
if (ChooseColor(&ccColour) == TRUE)
{
// crLabelTextColour is a COLORREF global variable assigned on loading the program
crLabelTextColour = ccColour.rgbResult;
}
This code, however, fails with an unhandled exception at the if statement, and I'm not sure why! Other examples seem to write code like this.
ChooseColor() crashes because you are not initializing the CHOOSECOLOR structure completely. You are only setting 3 fields, the rest will contain garbage. You'll need to zero-initialize everything, simple to do:
CHOOSECOLOR ccColour = {0};

InDesign Scripting how to quit application (not document)

I'm trying to automate data merge process. Here's what I have:
First of all have created a working datamerge script:
function main(){
mySnippet ();
myTeardown();
}
//<setup>
//<snippet>
function mySnippet(){
// automate datamerge
var myDocument = app.open(File("P:/RxCut/In Design Implementation/build/automate/automate.indd"));
var myDataSource = File("P:/RxCut/In Design Implementation/build/automate/automate.txt");
myDocument.dataMergeProperties.selectDataSource(myDataSource);
myDocument.dataMergeProperties.mergeRecords();
myDocument=myDocument.save("P:/RxCut/In Design Implementation/build/automate/AutomatedMerged.indd");
app.activeDocument.save(new File("P:/RxCut/In Design Implementation/build/automate/AutomatedMerged2.indd"));
myDocument.close();
}
//</snippet>
//<teardown>
function myTeardown(){
}
This runs great as expected!
Then had to write a vbscript to open InDesign and run that jsx script above:
Set myInDesign = CreateObject("InDesign.Application.CS5")
Msgbox("This message from Vbscript")
myJavaScript = "C:\test2.jsx"
myInDesign.DoScript myJavaScript, 1246973031
Now if CreateObject("InDesign.Application.CS5") opens InDesign how to close it?
app.quit();
easy as that
app.open
to open
app.quit
to quit

MATLAB date selection popup calendar for gui

Does anyone know of a method to display a popup date selection calendar in a MATLAB gui? I know the financial toolbox has a uicalendar function, but unfortunately I don't have that toolbox.
I have a hunch I'm going to have to use some Java or some other language for this one, which I know nothing about.
I'm looking for something similar to this:
(source: welie.com)
which would return a date string after the user selects the date.
Here are two approaches that would give you a professional-looking calendar component in Matlab without too much programming work:
Use a Java calendar component (for example, one of these or these). Once you download the relevant Java class or Jar-file, add it to your static Java classpath (use the edit('classpath.txt') command from the Matlab Command Prompt). Finally, use the built-in javacomponent function to place the component in your Matlab figure window.
If you are using a Windows OS, you can embed any Active-X calendar control that is available. Use the built-in actxcontrolselect function to choose your favorite calendar control (for example, Microsoft Office's "Calendar Control 11.0" - MSCAL.Calendar.7 - which is automatically installed with Office 2003; or "Microsoft Date and Time Picker Control 6.0" - MSComCtl2.DTPicker.2, or ...). Then use the actxcontrol function to place the component in your Matlab figure window.
Matlab has some pretty useful built-in calendar (date-selection) controls - I posted an article about them today
I don't have much time for a more complete answer, unfortunately, but I'd try uitable to create a table and to define the CellSelectionCallback to get the date.
Here's a bit to get you started:
dates = calendar;
dates(~any(dates,2),:) = [];
fh = figure;
uh = uitable('parent',fh,'data',dates,'ColumnWidth',repmat({20},1,7),...
'ColumnName',{'S','M','T','W','T','F','S'});
I'd start with the calendar() function which outputs a matrix containing the calendar for any month. I assume you could combine this with a user-clickable interface to retrieve a specific date?
The following code is really ugly, but could help you get started...
WINDOW_WIDTH = 300;
WINDOW_HEIGHT = 200;
f= figure('Position',[300 300 WINDOW_WIDTH WINDOW_HEIGHT]);
NB_ROWS = 6;
NB_COLS = 7;
width = round(WINDOW_WIDTH/NB_COLS);
height = round(WINDOW_HEIGHT/NB_ROWS);
buttons = nan(NB_ROWS,NB_COLS);
dates = calendar();
for row = 1:NB_ROWS
for col = 1:NB_COLS
if dates(row,col) == 0
mydate = '';
else
mydate = sprintf('%i', dates(row,col));
end
buttons(row,col) = uicontrol('Style', 'PushButton', ...
'String', mydate, ...
'Position', [(col-1)*width (NB_ROWS - row)*height width height]);
end
end

Resources