1. 求一個桌面右下角彈窗代碼 類似QQ新聞消息的那種。要c語言的
那個是富媒體彈窗,是一種網頁插件,所以不是病毒,所以金山和360不會提示,那個x不是關的,是點開的,如果沒有猜錯的話,x旁邊會有機關,可以關掉,或者在右下角靠近時間的那個區域.
2. C語言如何彈出提示框
直接調用系統API MessageBox()函數就可以了。
函數原形
int WINAPI MessageBox(HWND hWnd,LPCTSTR lpText,LPCTSTR lpCaption,UINT uType);
參數說明
hWnd: 消息框的擁有窗此參數口。如果為NULL,則消息框沒有擁有窗口。
lpText: 消息框的內容。
lpCaption: 消息框的標題。
uType:
指定一個決定對話框的內容和行為的位標志集。此參數可以為下列標志組中標志的組合。指定下列標志中的一個來顯示消息框中的按鈕以及圖標。
MB_OK 默認值。有一個確認按鈕在裡面。
MB_YESNO 有是和否在裡面。
MB_ABORTRETRYIGNORE 有Abort(放棄),Retry(重試)和Ignore(跳過)
MB_YESNOCANCEL 消息框含有三個按鈕:Yes,No和Cancel
MB_RETRYCANCEL 有Retry(重試)和Cancel(取消)
MB_OKCANCEL 消息框含有兩個按鈕:OK和Cancel
當然還有其他標志和返回值, 具體內容參考
https://msdn.microsoft.com/en-us/library/ms645505(VS.85).aspx
最後是用系統API時需要包含頭文件 windows.h
3. c語言簡單彈窗程序,比如彈出窗口可單擊是和否,單擊之後分別顯示不同的語句(單擊輸出你好,單擊否拜拜)
Demo程序,左鍵單擊窗口會彈出對話框:單擊「是」輸出「你好」,單擊「否」輸出「拜拜」~
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_INFORMATION);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinProc;
wndcls.lpszClassName="Demo";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("Demo","Demo",WS_OVERLAPPEDWINDOW,
0,0,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_LBUTTONDOWN:
HDC hdc;
hdc=GetDC(hwnd);
if (IDYES == MessageBox(hwnd, "你好 or 拜拜?", "ask", MB_YESNO))
{
TextOut(hdc,0,50,"你好",strlen("你好"));
}
else
{
TextOut(hdc,0,50,"拜拜",strlen("拜拜"));
}
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"Demo",strlen("Demo"));
EndPaint(hwnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
4. c語言製作彈出式菜單
void Menu()
{
system("cls"); /*調用系統的清屏命令*/
textbackground(BLUE);/*將背景設置為藍色*/
textmode(2);
window(1,1,25,80);
clrscr();
textx=3;/*游標初始化位置*/
texty=2;
gotoxy(1,2);
cprintf("%c",218);/*畫左上角*/
for(i=0;i<78;i++)
cprintf("%c",196); /*畫水平直線*/
cprintf("%c",191);/*畫右上角*/
for(i=3;i<=23;i++)
{
gotoxy(1,i);
cprintf("%c",179); /*畫垂直線*/
gotoxy(80,i);
cprintf("%c",179);
}
cprintf("%c",192); /*畫左下角*/
for(i=0;i<78;i++)
cprintf("%c",196);
cprintf("%c",217); /*畫右下角*/
gotoxy(1,1);
textcolor(7); /*設置灰色*/
for(i=0;i<80;i++)
cprintf("%c",219);/*用符號實現畫主菜單的灰色背景區*/
Selectitem(); /*調用選項函數*/
DrawSelectitem(); /*畫選項*/
gettext(2,3,78,23,c); /*保存當前文本區域*/
}
/*定義菜單*/
void Selectitem()
{
strcpy(ml[0].name,"File");/*下面的具體選項補空格是為了各菜單黑色背景相同*/
strcpy(ml[0].str[0],"Open ALT-O");
strcpy(ml[0].str[1],"New ALT-N");
strcpy(ml[0].str[2],"Save Ctrl-S");
strcpy(ml[0].str[3],"Write to... ");
strcpy(ml[0].str[4],"Exit ");
ml[0].n=5; /*保存菜單的項數*/
strcpy(ml[1].name,"Edit");
strcpy(ml[1].str[0],"Cut Ctrl+X");
strcpy(ml[1].str[1],"Copy Ctrl+C");
strcpy(ml[1].str[2],"Paste Ctrl+V");
strcpy(ml[1].str[3],"Find ");
strcpy(ml[1].str[4],"Find&Replace ");
ml[1].n=5;
strcpy(ml[2].name,"Help");/*系統幫助*/
strcpy(ml[2].str[0],"This System ");
strcpy(ml[2].str[1],"Ver ");
ml[2].n=2;
}
/*顯示主單名*/
void DrawSelectitem()
{
for(i=0;i<3;i++)
RedText(i,1,ml[i].name); /*顯示主菜單名,且首字母為紅色*/
}
/*正常顯示菜單*/
void RedText(int x,int y,char *z)
{
textbackground(7); /*設置背景顏色為淺灰色*/
gotoxy(3+x*20,y);
for(j=0;z[j];j++)
{
if(j==0)
textcolor(RED);/*第一個字母顯示紅色*/
else
textcolor(BLACK); /*設置黑色*/
cprintf("%c",z[j]); /*輸出菜單名*/
}
}
/*顯示選中菜單*/
void BlackText(int x,int y,char *z)
{
textbackground(0); /*設置背景顏色為黑色*/
textcolor(15); /*設置文本顏色為白色*/
gotoxy(3+20*x,y);/*定位坐標*/
cputs(z); /*輸出菜單名字元串*/
}
/*畫邊框函數*/
void DrawFrame(int l,int u,int r,int d,int tcolor,int bcolor)
{
textbackground(bcolor); /*背景顏色*/
textcolor(bcolor); /*文本顏色*/
for(i=l;i<=r;i++) /*輸出背景區域*/
{
for(j=u;j<=d;j++)
{
gotoxy(i,j);
cprintf("%c",219); /*輸出背景字元*/
}
}
textcolor(tcolor);/*邊框顏色*/
for(i=u+1;i<d;i++) /*在背景區域內輸出邊框線*/
{
gotoxy(l,i);
cprintf("%c",179); /*垂直線*/
gotoxy(r,i);
cprintf("%c",179);
}
for(i=l+1;i<r;i++)
{
gotoxy(i,u);
cprintf("%c",196); /*水平線*/
gotoxy(i,d);
cprintf("%c",196);
}
gotoxy(l,u);
cprintf("%c",218);/*左上角*/
gotoxy(r,u);
cprintf("%c",191);/*右上角*/
gotoxy(l,d);
cprintf("%c",192);/*左下角*/
gotoxy(r,d);
cprintf("%c",217); /*右下角*/
/* gettext(l+1,u+1,r-1,d-1,save1);*//*保存邊框內區域*/
}
/*顯示具體下拉選擇項目*/
void DrawMl(int n,charnodeptr *L,rownodeptr *R,pformateptr *P,operationptr *C,editptr *E)
{
gettext(1,1,80,25,save);/*保存被掩蓋的地方*/
BlackText(n,1,ml[n].name);/*反選顯示主菜單*/
DrawFrame(3+20*n-1,2,3+20*n+19,3+ml[n].n,0,7);/*下拉菜單的邊框*/
for(i=3;i<3+ml[n].n;i++)/*輸出所選菜單各選項*/
{
if(i==3)
BlackText(n,i,ml[n].str[i-3]);/*默認選中第一項*/
else
RedText(n,i,ml[n].str[i-3]);/*其餘各項首字元紅色顯示*/
}
gotoxy(79,1);
MoveMl(n,3,L,R,P,C,E);/*菜單選項的控制*/
}
/*菜單選項的控制,n決定水平項,x決定下拉的選項*/
void MoveMl(int n,int x,charnodeptr *L,rownodeptr *R,pformateptr *P,operationptr *C,editptr *E)
{
int flag=1;
while(flag)
{
gotoxy(79,1);
key=bioskey(0);/*接收按鍵*/
gotoxy(79,1);
switch(key)
{
case ESC:/*退出循環*/
puttext(1,1,80,25,save);/*恢復打開菜單前的樣子*/
flag=0;
break;
case LEFT:/*移到左邊的選項*/
puttext(1,1,80,25,save);/*恢復打開菜單前的樣子*/
if(n==0)/*往左移動越界的話移到最後一個選項*/
DrawMl(2,L,R,P,C,E);
else
DrawMl(n-1,L,R,P,C,E);
flag=0;
break;
case RIGHT:/*移動右邊的選項*/
puttext(1,1,80,25,save);/*恢復打開菜單前的樣子*/
if(n==2)/*往右移動越界的話移到第一個選項*/
DrawMl(0,L,R,P,C,E);
else
DrawMl(n+1,L,R,P,C,E);
flag=0;
break;
case UP:/*具體選項往上移動*/
RedText(n,x,ml[n].str[x-3]);/*輸出紅色字體*/
if(x==3)/*移到最上面再按上鍵,就移到最下面*/
x=3+ml[n].n-1;
else
x--;/*移動到新的要顯示的內容*/
BlackText(n,x,ml[n].str[x-3]);/*輸出黑色字體*/
flag=1;
break;
case DOWN:/*具體選項往下移動*/
RedText(n,x,ml[n].str[x-3]);
if(x==(3+ml[n].n-1))/*移動到最底下再按下鍵就移到最上面*/
x=3;
else
x++;/*移動到新的要顯示的內容*/
BlackText(n,x,ml[n].str[x-3]);
flag=1;
break;
case ENTER:
puttext(1,1,80,25,save);/*恢復打開菜單前的樣子*/
Enter(n,x-3,L,R,P,C,E);/*菜單選項的具體功能*/
flag=0;
break;
}
gotoxy(79,1);
}
}
/*菜單選項的具體功能*/
void Enter(int m,int n,charnodeptr *L,rownodeptr *R,pformateptr *P,operationptr *C,editptr *E)
{
switch(m)
{
case 0:switch(n)
{
case 0:Openfile(L,R,P,C,E);break; /*打開一個已存在的文件*/
case 1:Newfile(L,R,P,C,E);break; /*創建一個文件*/
case 2:Savefile(L);break; /*保存當前操作和文件*/
case 3:Writeto(L); /*另存為*/
case 4:Exit(L); /*退出系統*/
} break;
case 1: switch(n)
{
case 0: cut(L,R,P,C,E);break; /*剪切*/
case 1: (L,R,P,C,E);break; /*復制*/
case 2: paste(L,R,P,C,E);break; /*粘貼*/
case 3:find(L,R,P,C,E);break; /*查找*/
case 4:replace(L,R,P,C,E);break;/*替換*/
}break;
case 2:switch(n) /*選擇了幫助菜單選項*/
{
case 0:Help();break;
case 1:Ver();
}
}/*結束外switch*/
}
//這是部分程序,如果要完整的例子程序,告訴我郵箱,我發給你.
5. 用c語言如何實現彈除對話框
#include
#include
char format[]="%s%s ";
char hello[]="Hello";
char world[]="world";
HWND hwnd;void main(void)
asm
//push NULL
//call dword ptr GetMoleHandle
//mov hwnd,eax push MB_OK mov eax,offset world push eax mov eax,offset hello push eax push 0//說明此處不能將前面注釋掉代碼處得到的hwnd壓棧,否則對話框彈不出來。
call dword ptr MessageBox
}
}
WINDOWS程序MessagBox
WINDOWS或控制台 assert
C/C++ code
// crt_assert.c
// compile with: /c
#include <stdio.h>
#include <assert.h>
#include <string.h>
void analyze_string( char *string ); // Prototype
int main( void )
{
char test1[] = "abc", *test2 = NULL, test3[] = "";
printf ( "Analyzing string '%s' ", test1 ); fflush( stdout );
analyze_string( test1 );
printf ( "Analyzing string '%s' ", test2 ); fflush( stdout );
analyze_string( test2 );
printf ( "Analyzing string '%s' ", test3 ); fflush( stdout );
analyze_string( test3 );
}
// Tests a string to see if it is NULL,
// empty, or longer than 0 characters.
void analyze_string( char * string )
{
assert( string != NULL ); // Cannot be NULL
assert( *string != '