å½ç¶å¯ä»¥ï¼
é¢å对象æ¬èº«æ¯ä¸ç§ææ³ï¼èç¨åªç§è¯è¨å®ç°åªæ¯ä¸ç§ææ¯æ段ãäºå®ä¸ææ³åææ¯çå
³ç³»æ¬èº«å°±æ¯classåobjectçå
³ç³»ã
class oo {
//è¿æ¯é¢å对象çææ³ç±»
};
oo java; //javaæ¯ooçä¸ä¸ªå
·ä½çææ¯å®ç°
oo cxx; //c++æ¯ooçä¸ä¸ªå
·ä½çææ¯å®ç°
æ¿Windowsç³»ç»æ¥è®²ï¼å®æ¯æCè¯è¨ç¼åçï¼ä½æ¯ä½¿ç¨çå´æ¯é¢å对象çææ³ï¼è¿æ¹é¢å¯ä»¥åèreactosï¼ä¸ä¸ªå
è´¹å¼æºçç¨äºå¤§å¦æææä½ç³»ç»åççwindowsç³»ç»ï¼ã
举ä¸ä¸ªä¾åä¹è®¸æ´å®é
ä¸äºï¼æ¯å¦ï¼æä½ç³»ç»æ两ç§æä½çé¢ï¼ä¸ç§æ¯GUIçé¢ï¼ä¸ç§æ¯æ§å¶å°çé¢ï¼å¨windowså¹³å°ä¸ç¼åä¸ä¸ªç¨åºï¼å¨cmdä¸è¿è¡æ¶ï¼æ§è¡æ§å¶å°çé¢ç代ç ï¼å¨GUIä¸è¿è¡çæ¶åï¼æ§è¡å¾å½¢çé¢ç代ç ãè¿å®é
ä¸ä¹ç®æ¯ä¸ç§é¢å对象ç¼ç¨ä¸çå¤æå®ä¾ã以ä¸ç¤ºä¾ä»£ç å¨vc6.0ç¼è¯éè¿ã
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <TLHELP32.H>
char what_shell_run()
{
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnap==0){
return _T('E');
}
PROCESSENTRY32 pe32 = {0};
pe32.dwSize = sizeof pe32;
DWORD dwSelfPid = GetCurrentProcessId();
DWORD dwParentPid = ~0;
for (BOOL bLoop=Process32First(hSnap, &pe32); bLoop!=FALSE; bLoop=Process32Next(hSnap, &pe32))
{
if (dwSelfPid==pe32.th32ProcessID){
dwParentPid = pe32.th32ParentProcessID;
break;
}
}
if (dwParentPid==~0) return _T('U');
for (bLoop=Process32First(hSnap, &pe32); bLoop!=FALSE; bLoop=Process32Next(hSnap, &pe32))
{
if (dwParentPid==pe32.th32ProcessID){
if (lstrcmpi(pe32.szExeFile, _T("cmd.exe"))==0)
{
CloseHandle(hSnap);
return _T('C');
}else if (lstrcmpi(pe32.szExeFile, _T("explorer.exe"))==0){
CloseHandle(hSnap);
return _T('G');
}
}
}
CloseHandle(hSnap);
return _T('U');
}
void console(void) {
printf("è¿æ¯ä¸æ§å¶å°ç¨åº\n");
}
void gui (void) {
MessageBox(0, _T("è¿æ¯ä¸ä¸ªGUIç¨åº"), _T("GUI"), MB_OK);
}
int main()
{
char ch = what_shell_run();
switch (ch)
{
case 'C':
console();break;
case 'G':
gui(); break;
}
return 0;
}
å¨cmdä¸è¿è¡è¯¥ç¨åºçç»æï¼
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/0b55b319ebc4b74588e4afbacafc1e178a82152d?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
å¨GUIçé¢è¿è¡è¯¥ç¨åºçç»æï¼
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/ac4bd11373f08202e7f589934efbfbedab641b32?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)