Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3711
Number of posts: 9173

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Error in builiding.. Posted by innocent_boy on 5 Dec 2003 at 7:11 PM
hey,
when i compile it generato no error. but only warnings. and whn i try to build exe it gave following errors....
plz help me... what is that...


Linking...
maintoolbar.obj : error LNK2001: unresolved external symbol __imp__InitCommonControls@0
Debug/toolbar.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

toolbar.exe - 2 error(s), 0 warning(s)

Report
Re: Error in builiding.. Posted by pingpong on 5 Dec 2003 at 8:07 PM
You need to add comctl32.lib to your project.

Tip: whenever you use a Microsoft API and you get a link error, look it up in MSDN, usually they put the required lib file in the API help page.

: hey,
: when i compile it generato no error. but only warnings. and whn i try to build exe it gave following errors....
: plz help me... what is that...
:
:
: Linking...
: maintoolbar.obj : error LNK2001: unresolved external symbol __imp__InitCommonControls@0
: Debug/toolbar.exe : fatal error LNK1120: 1 unresolved externals
: Error executing link.exe.
:
: toolbar.exe - 2 error(s), 0 warning(s)
:
:

Report
Re: Error in builiding.. Posted by AsmGuru62 on 7 Dec 2003 at 1:31 PM
AGAIN, as pingpong mentioned...

You need to add comctl32.lib to your project.

If you are using VC++, then go: Project - Settings - 'Link' tab - category 'General' or 'Input' - in the box called 'Object/library modules:' add the "comctl32.lib" and separate it from others with a blank. Click OK. Rebuild.

In case you have some other compiler - check its manual on how to add a library to link with.

Report
Re: Error in builiding.. Posted by innocent_boy on 6 Dec 2003 at 7:54 PM
// this is main c file...

#include <windows.h>

#include <commctrl.h>

#include "resource.h"

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

static char gszClassName[] = "MyWindowClass";
static HINSTANCE ghInstance = NULL;
HWND ghToolBar;



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

WNDCLASSEX WndClass;
HWND hwnd;
MSG Msg;

ghInstance = hInstance;

WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = NULL;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = ghInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = gszClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&WndClass)) {
MessageBox(0, "Window Registration Failed!", "Error!", MB_ICONSTOP | MB_OK);
return 0;
}

hwnd = CreateWindowEx(
WS_EX_STATICEDGE,
gszClassName,
"Windows Title",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
320, 240,
NULL, NULL,
ghInstance,
NULL);

if(hwnd == NULL) {
MessageBox(0, "Window Creation Failed!", "Error!", MB_ICONSTOP | MB_OK);
return 0;
}


ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

while(GetMessage(&Msg, NULL, 0, 0)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
TBADDBITMAP tbAddBitmap;
TBBUTTON tbButton[8];


switch(Message) {
case WM_CREATE:


InitCommonControls();

ghToolBar = CreateWindowEx(
NULL,
TOOLBARCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE,
0, 0,
0, 0,
hwnd, (HMENU)IDR_TOOLBAR1,
ghInstance,
NULL);
SendMessage(ghToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), (LPARAM)NULL);

tbAddBitmap.hInst = ghInstance;
tbAddBitmap.nID = IDR_TOOLBAR1;
SendMessage(ghToolBar, TB_ADDBITMAP, 6, (LPARAM) &tbAddBitmap);

ZeroMemory(tbButton, sizeof(tbButton));

tbButton[0].iBitmap = 0;
tbButton[0].fsState = TBSTATE_ENABLED;
tbButton[0].fsStyle = TBSTYLE_BUTTON;
tbButton[0].idCommand = ID_BUTTON40001;

tbButton[1].iBitmap = 1;
tbButton[1].fsState = TBSTATE_ENABLED;
tbButton[1].fsStyle = TBSTYLE_BUTTON;
tbButton[1].idCommand = ID_BUTTON40002;

tbButton[2].fsStyle = TBSTYLE_SEP;

tbButton[3].iBitmap = 2;
tbButton[3].fsState = TBSTATE_ENABLED;
tbButton[3].fsStyle = TBSTYLE_BUTTON;
tbButton[3].idCommand = ID_BUTTON40003;

tbButton[4].iBitmap = 3;
tbButton[4].fsState = TBSTATE_ENABLED;
tbButton[4].fsStyle = TBSTYLE_BUTTON;
tbButton[4].idCommand = ID_BUTTON40004;

tbButton[5].fsStyle = TBSTYLE_SEP;

/* tbButton[6].iBitmap = 4;
tbButton[6].fsState = TBSTATE_ENABLED;
tbButton[6].fsStyle = TBSTYLE_BUTTON;
tbButton[6].idCommand = IDM_BUTTON4;

tbButton[7].iBitmap = 5;
tbButton[7].fsState = TBSTATE_ENABLED;
tbButton[7].fsStyle = TBSTYLE_BUTTON;
tbButton[7].idCommand = IDM_BUTTON5;
*/
SendMessage(ghToolBar, TB_ADDBUTTONS, 8, (LPARAM) &tbButton);
break;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case ID_BUTTON40001:
case ID_BUTTON40002:
case ID_BUTTON40003:
case ID_BUTTON40004:
/* case IDM_BUTTON4:
case IDM_BUTTON5:*/
MessageBox(hwnd, "A Button was clicked.", "Toolbar Message", MB_ICONINFORMATION | MB_OK);
break;
}
break;
case WM_SIZE:
SendMessage(ghToolBar, TB_AUTOSIZE, 0, 0);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}

//
// Used by rc.rc
//
#define IDR_TOOLBAR1 101
#define ID_BUTTON40001 40001
#define ID_BUTTON40002 40002
#define ID_BUTTON40003 40003
#define ID_BUTTON40004 40004

// Next default values for new objects


/////////////////////////////////////////////////////////////////////////////
//
// Toolbar
//

IDR_TOOLBAR1 TOOLBAR DISCARDABLE 16, 15
BEGIN
BUTTON ID_BUTTON40001
BUTTON ID_BUTTON40002
BUTTON ID_BUTTON40003
BUTTON ID_BUTTON40004
END


/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//

IDR_TOOLBAR1 BITMAP DISCARDABLE "toolbar1.bmp"


and now tell me what is the problem with this code... it generates one error i mentioned in previous post.

thanx..
Report
Re: Error in builiding.. Posted by xkgdiam on 7 Dec 2003 at 5:56 PM
: // this is main c file...
: 
: #include <windows.h>
: 
: #include <commctrl.h>
: 
: #include "resource.h"
: 
: LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
: 
: static char gszClassName[]  = "MyWindowClass";
: static HINSTANCE ghInstance = NULL;
: HWND   ghToolBar;
: 
: 
:   
: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 
: {
: 
:         WNDCLASSEX WndClass;
:         HWND hwnd;
:         MSG Msg;
: 				
:         ghInstance = hInstance;
: 		
:         WndClass.cbSize        = sizeof(WNDCLASSEX);
:         WndClass.style         = NULL;
:         WndClass.lpfnWndProc   = WndProc;
:         WndClass.cbClsExtra    = 0;
:         WndClass.cbWndExtra    = 0;
:         WndClass.hInstance     = ghInstance;
:         WndClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
:         WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
:         WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
:         WndClass.lpszMenuName  = NULL;
:         WndClass.lpszClassName = gszClassName;
:         WndClass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
: 
:         if(!RegisterClassEx(&WndClass)) {
:                 MessageBox(0, "Window Registration Failed!", "Error!", MB_ICONSTOP | MB_OK);
:                 return 0;
:         }
: 
:         hwnd = CreateWindowEx(
:                 WS_EX_STATICEDGE,
:                 gszClassName,
:                 "Windows Title",
:                 WS_OVERLAPPEDWINDOW,
:                 CW_USEDEFAULT, CW_USEDEFAULT,
:                 320, 240,
:                 NULL, NULL,
:                 ghInstance,
:                 NULL);
: 
:         if(hwnd == NULL) {
:                 MessageBox(0, "Window Creation Failed!", "Error!", MB_ICONSTOP | MB_OK);
:                 return 0;
:         }
: 
: 
:         ShowWindow(hwnd, nCmdShow);
:         UpdateWindow(hwnd);
: 
:         while(GetMessage(&Msg, NULL, 0, 0)) {
:                 TranslateMessage(&Msg);
:                 DispatchMessage(&Msg);
:         }
:         return Msg.wParam;
: }
: 
: LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) 
: {
: 		  TBADDBITMAP tbAddBitmap;
:             TBBUTTON tbButton[8];
: 		
: 			
: 		switch(Message) {
:                 case WM_CREATE:
:                       
: 				
: InitCommonControls();
:                
:                         ghToolBar = CreateWindowEx(
:                                 NULL,
:                                 TOOLBARCLASSNAME,
:                                 NULL,
:                                 WS_CHILD | WS_VISIBLE,
:                                 0, 0,
:                                 0, 0,
:                                 hwnd, (HMENU)IDR_TOOLBAR1,
:                                 ghInstance,
:                                 NULL);
:                         SendMessage(ghToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), (LPARAM)NULL);
: 
:                         tbAddBitmap.hInst = ghInstance;
:                         tbAddBitmap.nID   = IDR_TOOLBAR1;
:                         SendMessage(ghToolBar, TB_ADDBITMAP, 6, (LPARAM) &tbAddBitmap);
: 
:                         ZeroMemory(tbButton, sizeof(tbButton));
: 
:                         tbButton[0].iBitmap   = 0;
:                         tbButton[0].fsState   = TBSTATE_ENABLED;
:                         tbButton[0].fsStyle   = TBSTYLE_BUTTON;
:                         tbButton[0].idCommand = ID_BUTTON40001;
: 
:                         tbButton[1].iBitmap   = 1;
:                         tbButton[1].fsState   = TBSTATE_ENABLED;
:                         tbButton[1].fsStyle   = TBSTYLE_BUTTON;
:                         tbButton[1].idCommand = ID_BUTTON40002;
: 
:                         tbButton[2].fsStyle   = TBSTYLE_SEP;
: 
:                         tbButton[3].iBitmap   = 2;
:                         tbButton[3].fsState   = TBSTATE_ENABLED;
:                         tbButton[3].fsStyle   = TBSTYLE_BUTTON;
:                         tbButton[3].idCommand = ID_BUTTON40003;
: 
:                         tbButton[4].iBitmap   = 3;
:                         tbButton[4].fsState   = TBSTATE_ENABLED;
:                         tbButton[4].fsStyle   = TBSTYLE_BUTTON;
:                         tbButton[4].idCommand = ID_BUTTON40004;
: 
:                         tbButton[5].fsStyle   = TBSTYLE_SEP;
: 
:            /*             tbButton[6].iBitmap   = 4;
:                         tbButton[6].fsState   = TBSTATE_ENABLED;
:                         tbButton[6].fsStyle   = TBSTYLE_BUTTON;
:                         tbButton[6].idCommand = IDM_BUTTON4;
: 
:                         tbButton[7].iBitmap   = 5;
:                         tbButton[7].fsState   = TBSTATE_ENABLED;
:                         tbButton[7].fsStyle   = TBSTYLE_BUTTON;
:                         tbButton[7].idCommand = IDM_BUTTON5;
: */
:                         SendMessage(ghToolBar, TB_ADDBUTTONS, 8, (LPARAM) &tbButton);
:                         break;
:                 case WM_COMMAND:
:                         switch(LOWORD(wParam)) {
:                                 case ID_BUTTON40001:
:                                 case ID_BUTTON40002:
:                                 case ID_BUTTON40003:
:                                 case ID_BUTTON40004:
:                             /*    case IDM_BUTTON4:
:                                 case IDM_BUTTON5:*/
:                                         MessageBox(hwnd, "A Button was clicked.", "Toolbar Message", MB_ICONINFORMATION | MB_OK);
:                                         break;
:                         }
:                         break;
:                 case WM_SIZE:
:                         SendMessage(ghToolBar, TB_AUTOSIZE, 0, 0);
:                         break;
:                 case WM_CLOSE:
:                         DestroyWindow(hwnd);
:                         break;
:                 case WM_DESTROY:
:                         PostQuitMessage(0);
:                         break;
:                 default:
:                         return DefWindowProc(hwnd, Message, wParam, lParam);
:         }
:         return 0;
: } 
: 
: //
: // Used by rc.rc
: //
: #define IDR_TOOLBAR1                    101
: #define ID_BUTTON40001                  40001
: #define ID_BUTTON40002                  40002
: #define ID_BUTTON40003                  40003
: #define ID_BUTTON40004                  40004
: 
: // Next default values for new objects
: 
: 
: /////////////////////////////////////////////////////////////////////////////
: //
: // Toolbar
: //
: 
: IDR_TOOLBAR1 TOOLBAR DISCARDABLE  16, 15
: BEGIN
:     BUTTON      ID_BUTTON40001
:     BUTTON      ID_BUTTON40002
:     BUTTON      ID_BUTTON40003
:     BUTTON      ID_BUTTON40004
: END
: 
: 
: /////////////////////////////////////////////////////////////////////////////
: //
: // Bitmap
: //
: 
: IDR_TOOLBAR1            BITMAP  DISCARDABLE     "toolbar1.bmp"
: 
: 
: and now tell me what is the problem with this code... it generates one error i mentioned  in previous post.
: 
: thanx..
: 

Report
Re: Error in builiding.. Posted by innocent_boy on 10 Dec 2003 at 7:16 PM
hey, now i have made tool bar .. but oh there is 5 buttons as i require but those are empty there is no bitmap visible.. how can do make tool bar with bitmap..
You can view gif print of error.. here.. http://www.geocities.com/innocent4nu/toolbar.GIF

i use the following code to make and load bitmap..

case WM_CREATE:
InitCommonControls();
LoadBitmap(ghInstance,MAKEINTRESOURCE(IDR_TOOLBAR1));
ghToolBar = CreateWindowEx(
NULL,
TOOLBARCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE,
0, 0,
0, 0,
hwnd, (HMENU)IDR_TOOLBAR1,
ghInstance,
NULL);

SendMessage(ghToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)
sizeof(TBBUTTON), (LPARAM)NULL);

tbAddBitmap.hInst = ghInstance;
tbAddBitmap.nID = IDR_TOOLBAR1;

SendMessage(ghToolBar, TB_ADDBITMAP, 6, (LPARAM) &tbAddBitmap);

ZeroMemory(tbButton, sizeof(tbButton));//fills a block of
memory with zeros.

tbButton[0].iBitmap = 0;
tbButton[0].fsState = TBSTATE_ENABLED;
tbButton[0].fsStyle = TBSTYLE_BUTTON;
tbButton[0].idCommand = ID_BUTTON40006;

tbButton[1].iBitmap = 1;
tbButton[1].fsState = TBSTATE_ENABLED;
tbButton[1].fsStyle = TBSTYLE_BUTTON;
tbButton[1].idCommand = ID_BUTTON40007;

tbButton[2].fsStyle = TBSTYLE_SEP;

tbButton[3].iBitmap = 2;
tbButton[3].fsState = TBSTATE_ENABLED;
tbButton[3].fsStyle = TBSTYLE_BUTTON;
tbButton[3].idCommand = ID_BUTTON40008;

tbButton[4].iBitmap = 3;
tbButton[4].fsState = TBSTATE_ENABLED;
tbButton[4].fsStyle = TBSTYLE_BUTTON;
tbButton[4].idCommand = ID_BUTTON40010;

tbButton[5].fsStyle = TBSTYLE_SEP;

tbButton[6].iBitmap = 4;
tbButton[6].fsState = TBSTATE_ENABLED;
tbButton[6].fsStyle = TBSTYLE_BUTTON;
tbButton[6].idCommand = ID_BUTTON40011;


sendMessage(ghToolBar, TB_ADDBUTTONS, 7, (LPARAM) &tbButton);

break;
Report
Re: Error in builiding.. Posted by AsmGuru62 on 11 Dec 2003 at 7:08 AM
This message was edited by AsmGuru62 at 2003-12-11 7:10:5

: hey, now i have made tool bar .. but oh there is 5 buttons as i require but those are empty there is no bitmap visible.. how can do make tool bar with bitmap..
: You can view gif print of error.. here.. http://www.geocities.com/innocent4nu/toolbar.GIF
:
: i use the following code to make and load bitmap..
:
: case WM_CREATE:
:     InitCommonControls();
:     LoadBitmap(ghInstance,MAKEINTRESOURCE(IDR_TOOLBAR1));
You have to put the return value (HBITMAP) somewhere...
i.e. attach it to the 'ghToolBar below'...

    HBITMAP h = LoadBitmap (...);

:     ghToolBar = CreateWindowEx(
:                NULL,
:                TOOLBARCLASSNAME,
:                NULL,
:                WS_CHILD | WS_VISIBLE,
:                0, 0,
:                0, 0,
:                hwnd, (HMENU)IDR_TOOLBAR1,
:                ghInstance,
:                NULL);
: 	    
: 	      SendMessage(ghToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)   
:                             sizeof(TBBUTTON), (LPARAM)NULL);
: 
: 		tbAddBitmap.hInst = ghInstance;
:             tbAddBitmap.nID   = IDR_TOOLBAR1;
:          
: 	SendMessage(ghToolBar, TB_ADDBITMAP, 6, (LPARAM) &tbAddBitmap);
: 
: 	ZeroMemory(tbButton, sizeof(tbButton));//fills a block of  
:  memory with zeros. 
:       
: 	tbButton[0].iBitmap   = 0;
:         tbButton[0].fsState   = TBSTATE_ENABLED;
:         tbButton[0].fsStyle   = TBSTYLE_BUTTON;
:         tbButton[0].idCommand = ID_BUTTON40006;
: 
:        tbButton[1].iBitmap   = 1;
:        tbButton[1].fsState   = TBSTATE_ENABLED;
:        tbButton[1].fsStyle   = TBSTYLE_BUTTON;
:        tbButton[1].idCommand = ID_BUTTON40007;
:  
:        tbButton[2].fsStyle   = TBSTYLE_SEP;
: 
:                         tbButton[3].iBitmap   = 2;
:                         tbButton[3].fsState   = TBSTATE_ENABLED;
:                         tbButton[3].fsStyle   = TBSTYLE_BUTTON;
:                         tbButton[3].idCommand = ID_BUTTON40008;
: 
:                         tbButton[4].iBitmap   = 3;
:                         tbButton[4].fsState   = TBSTATE_ENABLED;
:                         tbButton[4].fsStyle   = TBSTYLE_BUTTON;
:                         tbButton[4].idCommand = ID_BUTTON40010;
: 
: 	tbButton[5].fsStyle   = TBSTYLE_SEP;
:                         
: 	tbButton[6].iBitmap   = 4;
:         tbButton[6].fsState   = TBSTATE_ENABLED;
:         tbButton[6].fsStyle   = TBSTYLE_BUTTON;
:         tbButton[6].idCommand = ID_BUTTON40011;
: 
:                         
:      sendMessage(ghToolBar, TB_ADDBUTTONS, 7, (LPARAM) &tbButton);
:                      		
: break;
: 






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.