Skip to main content

Creating an SDI/MDI application that is initially maximized

· One min read

To Creating an SDI/MDI application that is initially maximized Pass SW_SHOWMAXIMIZED as paramater to m_pMainWnd->ShowWindow() in the  in the CWinApp::InitInstance()

Code Snippet:

BOOL CWindowTitleApp::InitInstance() { 
////////////////////////////////////////////////////////////////////////////
// To Create an SDI/MDI application that is initially maximized
// /////////////////////////////////////////////////////////////////////////

m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
m_pMainWnd->DragAcceptFiles();

return TRUE;
}

Change a Window's title of an SDI/MDI Application

· One min read

Call SetWindowText method by passing required title as a string in the CWinApp::InitInstance() method after ProcessShellCommand() method. Please see the below code snippet

m_pMainWnd->SetWindowText("My New Window Title");

BOOL CWindowTitleApp::InitInstance()
{
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);

CWinApp::InitInstance();
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(4);

CSingleDocTemplate\* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CWindowTitleDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CWindowTitleView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);

EnableShellOpen();
RegisterShellFileTypes(TRUE);

CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);

if (!ProcessShellCommand(cmdInfo))
return FALSE;
////////////////////////////////////////////////////////////////////////////
// To Change Window Title //
////////////////////////////////////////////////////////////////////////////
m_pMainWnd->SetWindowText("My New Window Title");
////////////////////////////////////////////////////////////////////////////

m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
m_pMainWnd->DragAcceptFiles();

return TRUE;
}

How do remove 'Untitled' in main window caption

· One min read

To remove 'Untitled' in main window caption

  1. Override the PreCreateWindow() function in CMainFrame class
  2. Modify the CREATESTRUCT style by adding the below code cs.style &= ~FWS_ADDTOTITLE ;

Code snippet:

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;

////////////////////////////////////////////////////////////////////////////
// To remove 'Untitled' in main window caption //
////////////////////////////////////////////////////////////////////////////
cs.style &= ~FWS\_ADDTOTITLE ;
////////////////////////////////////////////////////////////////////////////

return TRUE;
}

Steve Jobs by Walter Isaacson

· 2 min read

Bought Steve Jobs by Walter Isaacson Biography on February 14, 2012 to present it to my self through flipkart.com.

Today March 10, 2012 12.20 PM I had completed reading the book it contains 42 chapters spread over 571 pages

Reality Distortion Field: It can be done

Books That Inspired Steve Jobs

  1. 'Autobiography of a Yogi' by Paramahansa Yogananda Jobs read and re-read many times during his life. Jobs had first read as a teenager," Isaacson writes, "then re-read in India and had read once a year ever since.

  2. 'Be Here Now' by Ram Dass

  3. Zen Mind, Beginner's Mind by Shunryu Suzuki

  4. 'The Innovator's Dilemma' by Clayton Christensen

  5. 'The Whole Earth Catalog' periodicals

  6. Herman Melville's Moby Dick

  7. Shakespeare's King Lear

  8. Poems of Dylan Thomas

  9. 'Diet For A Small Planet' by Frances Lapp

  10. 'Mucusless Diet Healing System' by Arnold Ehret

  11. Chogyam Trungpa's "Cutting Through Spiritual Materialism"

Articles

  1. "Secrets of the Little Blue Box,"

The Music That Inspired Steve Jobs

  1. Bob Dylan - bootlegs
  2. Beatles
  3. Stones
  4. Joan Baez - Love Is A Four Letter Word song
  5. Joni Mitchell - Both Sides Now song
  6. "Uncle John's Band" by the Grateful Dead
  7. Glenn Gould

Quotes From His Biography

"If you don't cannibalize yourself, someone else will."

"People don’t know what they want until you show it to them."

"I hate it when people call themselves 'entrepreneurs' when what they’re really trying to do is launch a startup and then sell or go public, so they can cash in and move on."

Get back the Recent Documents Menu in Windows 7

· One min read

Here is how I got it back:

  1. Right click the Start/Win button, select Properties
  2. Click the Start Menu tab (it should be select as default)
  3. Click the Customize button
  4. Scroll down and check the Recent Items check box
  5. Click Ok
  6. Click Apply
  7. Click Ok
  8. Check "Recent" option in the start menu.

Sending SMS using C

· 2 min read

Step 1: Create a new project in Microsoft Visual Studio 2008 (File -> New -> Project -> Visual C# -> Console Application). Give SMS_Sender name and also specify the location where to store the project.

Step 2: Now add a new item to the project we just created (Project -> Add New Item -> Class). Specify a name to the class as ‘SMSHelper’. The code now looks like as follows. The namespace used is

using System.IO; 
using System.Net;

SMSHelper.cs

 public class SMSHelper { 
private WebResponse myResponse = null;
private string result = string.Empty;
private string formatUrl(string ToMobileNo, string Message) {
DateTime mydate = System.DateTime.Now;
string url = ""; url += "method=sendMessage";
url += "&userid=2000053959"; // your loginId - 1
url += "&password=Gdgek2yiY";//password - 2
url += "&msg=" + mydate.ToString();
url += Message;
url += "&send_to="; // a valid 10 digit phone no.
url += ToMobileNo; url += "&v=1.1";
url += "&msg_type=TEXT"; // Can be "FLASH" or "UNICODE\_TEXT" or "BINARY"
url += "&auth_scheme=PLAIN";
return url;
}

public string SendSms(string ToMobileNo , string Message)
{
try
{
string finalUrl = "http://enterprise.smsgupshup.com/GatewayAPI/rest?" + formatUrl(ToMobileNo, Message);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(finalUrl);
myResponse = myRequest.GetResponse();
Stream st = myResponse.GetResponseStream();

Encoding ec = System.Text.Encoding.GetEncoding("utf-8");
StreamReader reader = new System.IO.StreamReader(st, ec);

result = reader.ReadToEnd();

reader.Close();
st.Close();
return result;
}
catch (Exception exp)
{
return result;
}
finally
{
if (myResponse != null) myResponse.Close();
}
}
}

Step 3: Open Program.cs and in Main write the following lines to send the SMS

 class Program { 
static void Main(string[] args) {
SMSHelper smsObj = new SMSHelper();
string Text = smsObj.SendSms("1234567890", "HelloWorld");
Console.WriteLine(Text);
}
}

Message Map vs Virtual Functions

· One min read

Message Map is a logical table that maps the windows messages to the member functions of the class. Message map is preferred than virtual functions due  to avoid following drawbacks:

  1. Most windows only process a small number of messages, yet each window require to giant virtual function table with the entries of each message.

  2. More efficient and use less space then virtual functions.

  3. Virtual functions don't handle user defined messages and other custom cases.

All About Design Patterns

· One min read

Definition

Design Patterns represent solutions to problems that arise when developing software within a particular context. Patterns help you learn from other's successes, instead of your own failures. Mark Johnson (cited by Bruce Eckel)

Types of Design Patterns

There are three types of design patterns

  1. Creational Patterns: Creational Patterns deals with initializing and configuring classes and objects
  2. Structural Patterns: Structural Patterns deals with decoupling the interface and implementation of classes and objects
  3. Behavioral Patterns: Behavioral Patterns deals with dynamic interactions among societies of classes and objects

These three design patters are divided in to 22 different kinds of patterns as shown below.

Simple Windows Form in C

· One min read

Minimal code to write a c# windows form:

using System.Windows.Forms;

namespace ConsoleFormApp {
class MyWindow : Form {
public MyWindow() {
this.Text = "First Form";
}
}

class Program {
static void Main(string\[\] args) {
Application.Run(new MyWindow());
}
}
}

Single Document Interface Class Diagram

· One min read

A CSDIApp MFC application will have a single CWinApp class object. This holds a CDocManager object which is used by the MFC to handle all the CDocTemplate objects that we registered with the framework.

The CWinApp object also creates a CMainFrame object which is the main window of CSDIApp application.

Every time if we open/create a document in CSDIApp application, a CDocument object of the right type will be created. A pointer to CDocument object will be stored in a list under the corresponding CDocTemplate object.