Showing posts with label Apple Inc.. Show all posts
Showing posts with label Apple Inc.. Show all posts

28 March, 2018

Make App Disappear From Taskbar On Minimize

Screenshot showing Windows 8's ability to pin ...
Screenshot showing Windows 8's ability to pin apps and show different wallpapers on different monitors, as well as displaying the new Explorer file browser interface, Task Manager, and multi-monitor taskbar (in "Duplicated on all taskbars" mode). (Photo credit: Wikipedia)
28-March-2018

I wanted to completely hide an application after it is minimized. Hide() is not enough. [ShowInTaskbar = false] did the trick.

Well, I could say that I struggled a bit finding out what would really make the application disappear from the taskbar.

I used Hide(). Didn't work. I also tried Visible = false. Also did not work. I combined both, but still, it did not work. I combined both Hide() and Visible = false, and even then, I still did not see the job done. App icon still shows in the taskbar when it was minimized.

I should mention that I already have the application creating an icon in the System Tray as I have previously created a NotifyIcon to handle that. And what I am adding now is to minimize the window via code, which also requires the app icon to be not shown in the Taskbar.

I couldn't find many articles that provided help. What came up usually just mentioned Hide() or Visible, and some of the old stuff about adding a NotifyIcon function. I found one that did mention about making use of the property ShowInTaskbar. So I grabbed that one-liner code, tried it, and it worked!

So now my program is complete! Now I can hide an application after it is minimized. Thanks to ShowInTaskbar, I could declare it a holiday!

Till then!

[Late posting; drafted on 04-October-2017]


06 September, 2017

Singleton: Create A Single-Instance Application

UML class diagram of the singleton design pattern
UML class diagram of the singleton design pattern (Photo credit: Wikipedia)
06-September-2017


Create a single-instance application. That was the objective I thought of lately on one small program I am creating. That is due to some database update needed. So no double-update or better yet, multiple updates, must happen.

Okay. It was actually simple, but here I will just outline the simple steps - again, for my own use when I need it in the future - and also for anybody else who might need to implement this same feature in their programs.

So how do you create a single-instance application? How to enforce a singleton pattern?

It is very easy. Just look at the code snippet below. And this is using Mutex in the Program section where your code execution starts.


internal static class Program {
private static Mutex mutex = new Mutex(true, "{a381c74c-c9a1-4716-beff-e8a08e964462}");

[STAThread]
private static void Main() {
if (mutex.WaitOne(TimeSpan.Zero, true)) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
mutex.ReleaseMutex();
}
else {
MessageBox.Show("Only one instance allowed.");
}
}
}


So that is the baseline requirement to satisfy a singleton pattern. And if you are wondering the seemingly cryptic string in the Mutex declaration, fret not. It is just a string that Mutex implementation requires, so it can be anything, like the name of your application, but it must be unique.

Alright, if you insist on using the same seemingly cryptic alphanumeric combination so it is unique, then add these 2 lines somewhere in the form load event, and just capture that value, and put it in the Mutex declaration. And comment those 2 lines right away as they are no longer needed.


var guiId = System.Guid.NewGuid();
MessageBox.Show("guiId");


Yes, that's how I got mine.

Now there is an additional feature that can be included, and not just simply throwing a message box. The thing is, why not bring up the instance of the running application instead?

Well, that is possible.

Modify the Program section as per below code, which means disabling the message box and replacing it with some nifty Win32 function (API). It is sending a message to all other running applications, but since it is unique only to this application, then it is understood only by this same application, so only this particular program will respond. Mind-boggling, isn't it?

Let's get done with it then!


internal static class Program {
private static Mutex mutex = new Mutex(true, "{a381c74c-c9a1-4716-beff-e8a08e964462}");

[STAThread]
private static void Main() {
if (mutex.WaitOne(TimeSpan.Zero, true)) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
mutex.ReleaseMutex();
}
else {
// MessageBox.Show("Only one instance allowed.");
// send our Win32 message to make the currently running instance
// jump on top of all the other windows
NativeMethods.PostMessage((IntPtr)NativeMethods.HWND_BROADCAST,
NativeMethods.WM_SHOWME, IntPtr.Zero, IntPtr.Zero);
}
}
}


As for NativeMethods.cs, you need to create a new class for that.


internal class NativeMethods {
public const int HWND_BROADCAST = 0xffff;
public static readonly int WM_SHOWME = RegisterWindowMessage("WM_SHOWME");

[DllImport("user32")]
public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);

[DllImport("user32")]
public static extern int RegisterWindowMessage(string message);
}


Then, to complete the code, add two procedures after the Main Form's call to InitializeComponent.


public MainForm() {
InitializeComponent();
}

protected override void WndProc(ref Message m) {
if (m.Msg == NativeMethods.WM_SHOWME) {
ShowMe();
}
base.WndProc(ref m);
}

private void ShowMe() {
Show();
if (WindowState == FormWindowState.Minimized) { WindowState = FormWindowState.Normal; }
// get our current "TopMost" value (ours will always be false though)
var top = TopMost;
// make our form jump to the top of everything
TopMost = true;
// set it back to whatever it was
TopMost = top;
}


Now this is all that it takes to create a singleton implementation of a program. This is written in C#, so feel free to adapt this to other languages as you deem fit.


Sources

I am simply blogging on this singleton implementation, on how to create a single-instance application, but the source articles are here and here, thanks to the authors! Read on these 2 articles to get more explanations, and other suggestions, too.


Until then, happy coding!


16 July, 2017

Remote data not accessible: Excel 2016

English: Illustration of subroutine in Microso...
English: Illustration of subroutine in Microsoft Excel that reads the x-column, squares it, and writes the squares into the y-column. All proprietary Microsoft art work has been cropped to leave a generic spreadsheet (Photo credit: Wikipedia)
English: Use of user-defined function in Micro...
English: Use of user-defined function in Microsoft Excel. All proprietary Microsoft art work has been cropped to leave a generic spreadsheet (Photo credit: Wikipedia)
16 July 2017, 10:20 PM


Remote data not accessible:
To access this data Excel needs to start another application. Some legitimate applications on your computer could be used maliciously to spread viruses or damage your computer. Only click Yes if you trust the source of theis workbook and you want to let the workbook start the application. Start application 'SV.EXE'?  YES NO

I am working on PcVue data extraction using Excel 2016. That was the response thrown by Excel after I typed "=SV|DB!DATE" and pressed [Enter].

Of course, I clicked on YES, but then again, this is the result:

“Cannot run ‘SV.EXE’.  The program or one of its components is damaged or missing.”

Beats me!

This is another one of those DDE nightmares, where the support for a legacy system is required even when already using Windows 10 64 bit and Excel 2016.

I searched for more articles using the string "remote data not accessible" and well, I got some from Technet, and some from Microsft forums, and some scattered Q&A here and there, even in StackOverflow. And I think the solution was derived from one of the Microsoft forums Q&A.

The advice is to make Excel run as Admin. So I did that. I modified the shortcut of Excel 2016 to make it execute, 'Run as administrator'.

And yes, it worked! I was able to extract data from PcVue iNexus 10/11.2 into Excel using DDE!

Then the C# program wouldn't still work, though.

But getting the idea from what I did to Excel, I looked for the compiled program, set it also to execute and 'Run as administrator', well, what do you know?

It also worked!

So while I cannot make use of DDE through Visual Studio's Ctrl+F5. I just do a build, set the compiled exe file's property to 'Run ad administrator', and voila! It would be working like a charm!

I hope this helps somebody working on the same legacy system, DDE, and still make it work.

Till then!



06 April, 2017

Kernel Panic - Not Syncing After Ubuntu Upgrade, Update

Ubuntu Desktop 11.04 started from Live CD with...
Ubuntu Desktop 11.04 started from Live CD with Install window open (Photo credit: Wikipedia)
Kernel panic - not syncing! I upgraded to Ubuntu 16.04, and that is what I got.

After being away from my blogs for so long a time, building my own website, and letting it go after a year, I am back to Blogger.com.

Since my last blog, it was about 2 years already, I think more than. And I have forgotten what my e-mail was. I mean, there is one e-mail that I always use, as much as I can remember. But I tried to log in using that account, and it was not!

I tried my second best candidate, and even that one, it was not!

Searched a bit on how to find out who the blog owner is, found some things, like looking at the profile, etc. Didn't work for me.

Finally, I had to log-in with the account that I knew I always use, and checked out the settings, and I saw another e-mail account, and to my surprise! I mean, I can't believe, and I doubted, that I am using that e-mail in my blogs.

Nothing would be lost, so I tried, and what do you know? That was the correct e-mail account!

And I had to put this in writing, the error I encountered when I updated Ubuntu Linux to 16.04. That was the reason why I was anxious to start blogging again.

Kernel panic - not syncing... and some other texts.

Problem: 

After upgrading Ubuntu Linux to 16.04, I can't boot up Ubuntu Linux. Grub shows, but after selecting Ubuntu, OS stops at that line: Kernel panic - not syncing....

Solution(s):

1. boot-repair - this was the first thing I did. Using a Live CD/USD of the same distro, I booted up my laptop to Ubuntu, and issued below commands line-by-line:

sudo apt-add-repository ppa:yannubuntu/boot-repair
sudo apt-get update
sudo apt-get install -y boot-repair
boot-repair

There is a good graphical article here in help.ubuntu.com: Boot-Repair. 

That fixed Grub, and Ubuntu is able to boot up properly again. But Windows is now not showing in Grub! So I searched for possible fixes.

2. bootrec /rebuildbcd. That was the suggested fix, which requires botting up with a Windows installation CD/USD. And that was required to be run in a command prompt environment.

At first, it was not a success. Further searches, I got the idea that I need to mount Windows drive, which I unmounted when I tried to install 16.04 over my 15.04 version.

3. mount Windows partition. I booted up to Ubuntu Live CD/USB, opened up disks from terminal, click-select Windows partition, flicked the switch to mount, then remove hibernate file by adding in mount option: ,remove_hiberfile.

Then I ran grub repair utility. Still didn't see Windows in the Grub list.

4. boot-repair. I ran it a second time, and I saw that it is already seen as one of the OSes. I completed the repair.

As I was able to boot up Ubuntu Linux and Windows, I did 2 cycles of booting up Windows and Ubuntu Linux without touching anything yet. Once I am confident that Grub is properly working again, I did the last step of customization.

5. Grub Customizer. I removed Windows 8, moved up and down Ubuntu, Advanced Ubuntu Options and Windows according to my liking, and I am back.

I am posting up this article from Ubuntu Linux 16.04 distro. I hope it helps me in the future, if the opportunity comes, and I hope that it helps somebody else who face the same problem.

Till then!

19 December, 2014

Google Uses its Social Network to Get Nosy

English: Google+ wordmark
English: Google+ wordmark (Photo credit: Wikipedia)
The Social Network
The Social Network (Photo credit: Wikipedia)
I am just wondering and pondering what would happen if I post this seemingly anti-Google article in a Google-owned blog site. But this was an article published in the open, so while I am having my doubts, I still believe this is a fair game.

Read on...
-----


BY CLAIRE CAINE MILLER


SAN FRANCISCO – Google Plus, the company’s social network, is like a ghost town. Want to see your old roommate’s baby or post your vacation status? Chances are, you’ll use Facebook instead.

But Google isn’t worried. Google Plus may not be much of a competitor to Facebook as a social network, but it is central to Google’s future – a lens that allows the company to peer more broadly into people’s digital life, and to gather an ever-richer trove of the personal information that advertisers covet.

Once you sign up for Plus, it becomes your account for all Google products, so Google sees who you are and what you do across its services, even if you never return to the social network itself.

Google says Plus has 540 million monthly active users, but almost half do not visit the social network.

“Google Plus gives you the opportunity to be yourself, and gives Google that common understanding of who you are,” said Bradley Horowitz, vice president of product management for Google Plus. “It’s about you showing up at Google and having a consistent experience across products so they feel like one product, and that makes your experiences with every Google product better.”

Plus is now so important to Google that the company requires people to sign to use some Google services, like commenting on YouTube. Larry Page, Google’s chief executive, tied employee bonuses companywide to its success and appointed Vic Gundotra, a senior Google executive, to lead it.

The value of Plus has only increased in the last year, as search advertising. Google’s main source of profits, has slowed.

“The database of affinity could be the holy grail for more effective brand advertising,” said Nate Elliott, an analyst at Forrester studying social media and marketing.

----------
Need help in achieving clarity of mind?
----------

Google says the information it gains about people through Google Plus helps it create better products – like sending traffic updates to cell-phones or knowing whether a search for “Hillary” refers to a family member or to the former American secretary of state – as well as better ads.

Plus has 29 million unique monthly users on its website and 41 million on smartphones, with some users overlapping, compared with Facebook’s 128 million users on its website and 108 million on phones, according to Nielsen.

The way Google is tying its research its search engine, which dominates the market, with a less popular product in Plus has set off antitrust concerns. The United States Federal Trade Commission raised the issue during its recent antitrust investigation of Google, according to two people briefed on the matter. That investigation closed without a finding of wrongdoing.

Google declined to comment on this issue.

In the meantime, while some Google users have been turned off by the push to sign up for Plus, few have actually fled.

“If people want to use your platform enough,” Mr. Elliott said,” you can get away with quite a lot.”


Taken from TODAY Saturday Edition, March 22, 2014