// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ERRORSHOW ICON DISCARDABLE "ErrorShow.ico"
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
case IDC_ERRORCODE:
EnableWindow(GetDlgItem(hwnd, IDOK), Edit_GetTextLength(hwndCtl) > 0);
break;
case IDOK:
// Get the error code
DWORD dwError = GetDlgItemInt(hwnd, IDC_ERRORCODE, NULL, FALSE);
HLOCAL hlocal = NULL; // Buffer that gets the error message string
// Use the default system locale since we look for Windows messages.
// Note: this MAKELANGID combination has 0 as value
DWORD systemLocale = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
if (fOk && (hlocal != NULL)) {
SetDlgItemText(hwnd, IDC_ERRORTEXT, (PCTSTR)LocalLock(hlocal));
LocalFree(hlocal);
}
else {
SetDlgItemText(hwnd, IDC_ERRORTEXT,
TEXT("No text found for this error number."));
}
int WINAPI _tWinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) {
HWND hwnd = FindWindow(TEXT("#32770"), TEXT("Error Show2"));
if (IsWindow(hwnd)) {
// An instance is already running, activate it and send it the new #
SendMessage(hwnd, ESM_POKECODEANDLOOKUP, _ttoi(pszCmdLine), 0);
}
else {
DialogBoxParam(hinstExe, MAKEINTRESOURCE(IDD_ERRORSHOW),
NULL, Dlg_Proc, _ttoi(pszCmdLine));
}
return(0);
}
//////////////////////////////// End of File //////////////////////////////////
The question is How the gui and dialogue in cpp file formed by rc file?
How are they related to each other.
Could I have everything in one file, say cpp file?
Just please help me understand
The .rc file is compiled by a "resource compiler", you get a .res file. It's linked with the.obj file to create the executable.
The program can create the dialog box defined in the resource file by using IDD_ERRORSHOW. It then has handlers for the things that happen when it's poked.
Could I have everything in one file, say cpp file?
You can't have everything in one file. Well, you can (because nothing's impossible), but you shouldn't. It's normal for applications to be built this way in Windows.
What I dont understand is: How did .rc file appear in the project? Did it appear automatically after the programmer created the gui in the vs constructor? Or the programmer created this file?
A Visual Studio wizard will create it. There's also a resource.h that is included by the .rc and .c/.cpp file where the constants are defined, like IDD_ERRORSHOW and any elements used by the dialog box. IDOK and IDCANCEL have always been used by every dialog box, so are defined thru using windows.h.